annotate src/org/tmatesoft/hg/repo/HgWorkingCopyStatusCollector.java @ 293:9774f47d904d

Issue 13: Status reports filenames with case other than in dirstate incorrectly
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 14 Sep 2011 04:11:37 +0200
parents 8faad08c709b
children 32890bab7209
rev   line source
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
2 * Copyright (c) 2011 TMate Software Ltd
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
3 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
4 * This program is free software; you can redistribute it and/or modify
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
5 * it under the terms of the GNU General Public License as published by
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
6 * the Free Software Foundation; version 2 of the License.
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
7 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
8 * This program is distributed in the hope that it will be useful,
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
11 * GNU General Public License for more details.
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
12 *
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
13 * For information on how to redistribute this software under
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
14 * the terms of a license other than GNU General Public License
102
a3a2e5deb320 Updated contact address to support@hg4j.com
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 94
diff changeset
15 * contact TMate Software at support@hg4j.com
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
17 package org.tmatesoft.hg.repo;
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
120
b19f0ac5ee62 Check against working copy shall expect non-persistent modifications done by filters and not report such files as modified
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 117
diff changeset
19 import static java.lang.Math.max;
117
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
20 import static java.lang.Math.min;
218
047b1dec7a04 Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 195
diff changeset
21 import static org.tmatesoft.hg.repo.HgRepository.*;
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
23 import java.io.File;
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import java.io.IOException;
117
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
25 import java.nio.ByteBuffer;
287
ed6b74a58c66 Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
26 import java.nio.channels.ReadableByteChannel;
229
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
27 import java.util.ArrayList;
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 import java.util.Collections;
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
29 import java.util.NoSuchElementException;
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 import java.util.Set;
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 import java.util.TreeSet;
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
33 import org.tmatesoft.hg.core.HgDataStreamException;
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
34 import org.tmatesoft.hg.core.HgException;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
35 import org.tmatesoft.hg.core.Nodeid;
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
36 import org.tmatesoft.hg.internal.ByteArrayChannel;
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
37 import org.tmatesoft.hg.internal.Experimental;
117
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
38 import org.tmatesoft.hg.internal.FilterByteChannel;
248
3fbfce107f94 Issue 8: Means to find out information about given file at specific changeset. Inner ManifestRevisionInspector got promoted to ManifestRevision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 246
diff changeset
39 import org.tmatesoft.hg.internal.ManifestRevision;
229
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
40 import org.tmatesoft.hg.internal.PathScope;
117
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
41 import org.tmatesoft.hg.util.ByteChannel;
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
42 import org.tmatesoft.hg.util.CancelledException;
287
ed6b74a58c66 Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
43 import org.tmatesoft.hg.util.FileInfo;
141
8248aae33f7d Adopt FileIterator moving towards WCStatusCollector parameterizing. Improved path handling, move 'em around
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
44 import org.tmatesoft.hg.util.FileIterator;
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
45 import org.tmatesoft.hg.util.FileWalker;
133
4a948ec83980 core.Path to util.Path as it's not Hg repo dependant
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 120
diff changeset
46 import org.tmatesoft.hg.util.Path;
93
d55d4eedfc57 Switch to Path instead of String in filenames returned by various status operations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
47 import org.tmatesoft.hg.util.PathPool;
d55d4eedfc57 Switch to Path instead of String in filenames returned by various status operations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
48 import org.tmatesoft.hg.util.PathRewrite;
287
ed6b74a58c66 Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
49 import org.tmatesoft.hg.util.RegularFileInfo;
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
50
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 /**
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 *
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
53 * @author Artem Tikhomirov
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
54 * @author TMate Software Ltd.
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 */
94
af1f3b78b918 *StatusCollector renamed to Hg*StatusCollector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 93
diff changeset
56 public class HgWorkingCopyStatusCollector {
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 private final HgRepository repo;
141
8248aae33f7d Adopt FileIterator moving towards WCStatusCollector parameterizing. Improved path handling, move 'em around
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
59 private final FileIterator repoWalker;
59
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 58
diff changeset
60 private HgDirstate dirstate;
94
af1f3b78b918 *StatusCollector renamed to Hg*StatusCollector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 93
diff changeset
61 private HgStatusCollector baseRevisionCollector;
93
d55d4eedfc57 Switch to Path instead of String in filenames returned by various status operations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
62 private PathPool pathPool;
282
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
63 private ManifestRevision dirstateParentManifest;
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64
94
af1f3b78b918 *StatusCollector renamed to Hg*StatusCollector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 93
diff changeset
65 public HgWorkingCopyStatusCollector(HgRepository hgRepo) {
229
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
66 this(hgRepo, new HgInternals(hgRepo).createWorkingDirWalker(null));
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
67 }
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
68
229
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
69 // FIXME document cons
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
70 public HgWorkingCopyStatusCollector(HgRepository hgRepo, FileIterator hgRepoWalker) {
218
047b1dec7a04 Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 195
diff changeset
71 repo = hgRepo;
047b1dec7a04 Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 195
diff changeset
72 repoWalker = hgRepoWalker;
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 }
59
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 58
diff changeset
74
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 58
diff changeset
75 /**
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 58
diff changeset
76 * Optionally, supply a collector instance that may cache (or have already cached) base revision
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 58
diff changeset
77 * @param sc may be null
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 58
diff changeset
78 */
94
af1f3b78b918 *StatusCollector renamed to Hg*StatusCollector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 93
diff changeset
79 public void setBaseRevisionCollector(HgStatusCollector sc) {
59
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 58
diff changeset
80 baseRevisionCollector = sc;
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 58
diff changeset
81 }
93
d55d4eedfc57 Switch to Path instead of String in filenames returned by various status operations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
82
d55d4eedfc57 Switch to Path instead of String in filenames returned by various status operations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
83 /*package-local*/ PathPool getPathPool() {
d55d4eedfc57 Switch to Path instead of String in filenames returned by various status operations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
84 if (pathPool == null) {
d55d4eedfc57 Switch to Path instead of String in filenames returned by various status operations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
85 if (baseRevisionCollector == null) {
d55d4eedfc57 Switch to Path instead of String in filenames returned by various status operations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
86 pathPool = new PathPool(new PathRewrite.Empty());
d55d4eedfc57 Switch to Path instead of String in filenames returned by various status operations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
87 } else {
d55d4eedfc57 Switch to Path instead of String in filenames returned by various status operations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
88 return baseRevisionCollector.getPathPool();
d55d4eedfc57 Switch to Path instead of String in filenames returned by various status operations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
89 }
d55d4eedfc57 Switch to Path instead of String in filenames returned by various status operations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
90 }
d55d4eedfc57 Switch to Path instead of String in filenames returned by various status operations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
91 return pathPool;
d55d4eedfc57 Switch to Path instead of String in filenames returned by various status operations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
92 }
d55d4eedfc57 Switch to Path instead of String in filenames returned by various status operations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
93
d55d4eedfc57 Switch to Path instead of String in filenames returned by various status operations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
94 public void setPathPool(PathPool pathPool) {
d55d4eedfc57 Switch to Path instead of String in filenames returned by various status operations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
95 this.pathPool = pathPool;
d55d4eedfc57 Switch to Path instead of String in filenames returned by various status operations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
96 }
d55d4eedfc57 Switch to Path instead of String in filenames returned by various status operations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
97
290
8faad08c709b Expose dirstate to allow pre-configuration of FileIterators for status collection in particular
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 287
diff changeset
98 /**
8faad08c709b Expose dirstate to allow pre-configuration of FileIterators for status collection in particular
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 287
diff changeset
99 * Access to directory state information this collector uses.
8faad08c709b Expose dirstate to allow pre-configuration of FileIterators for status collection in particular
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 287
diff changeset
100 * @return directory state holder, never <code>null</code>
8faad08c709b Expose dirstate to allow pre-configuration of FileIterators for status collection in particular
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 287
diff changeset
101 */
8faad08c709b Expose dirstate to allow pre-configuration of FileIterators for status collection in particular
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 287
diff changeset
102 public HgDirstate getDirstate() {
59
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 58
diff changeset
103 if (dirstate == null) {
284
7232b94f2ae3 HgDirstate shall operate with Path instead of String for file names. Use of Pair instead of array of unspecified length for parents.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 282
diff changeset
104 dirstate = repo.loadDirstate(getPathPool());
59
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 58
diff changeset
105 }
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 58
diff changeset
106 return dirstate;
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 58
diff changeset
107 }
275
6d1804fe0ed7 Issue 10: Report file content length with respect of metadata. Respect dirstate parents for WC's status. Exceptions to keep useful attributes of the location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 248
diff changeset
108
282
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
109 private ManifestRevision getManifest(int changelogLocalRev) {
284
7232b94f2ae3 HgDirstate shall operate with Path instead of String for file names. Use of Pair instead of array of unspecified length for parents.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 282
diff changeset
110 assert changelogLocalRev >= 0;
282
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
111 ManifestRevision mr;
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
112 if (baseRevisionCollector != null) {
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
113 mr = baseRevisionCollector.raw(changelogLocalRev);
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
114 } else {
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
115 mr = new ManifestRevision(null, null);
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
116 repo.getManifest().walk(changelogLocalRev, changelogLocalRev, mr);
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
117 }
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
118 return mr;
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
119 }
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
120
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
121 private ManifestRevision getDirstateParentManifest() {
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
122 // WC not necessarily points to TIP, but may be result of update to any previous revision.
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
123 // In such case, we need to compare local files not to their TIP content, but to specific version at the time of selected revision
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
124 if (dirstateParentManifest == null) {
284
7232b94f2ae3 HgDirstate shall operate with Path instead of String for file names. Use of Pair instead of array of unspecified length for parents.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 282
diff changeset
125 Nodeid dirstateParent = getDirstate().parents().first();
7232b94f2ae3 HgDirstate shall operate with Path instead of String for file names. Use of Pair instead of array of unspecified length for parents.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 282
diff changeset
126 if (dirstateParent.isNull()) {
7232b94f2ae3 HgDirstate shall operate with Path instead of String for file names. Use of Pair instead of array of unspecified length for parents.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 282
diff changeset
127 dirstateParentManifest = baseRevisionCollector != null ? baseRevisionCollector.raw(-1) : HgStatusCollector.createEmptyManifestRevision();
7232b94f2ae3 HgDirstate shall operate with Path instead of String for file names. Use of Pair instead of array of unspecified length for parents.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 282
diff changeset
128 } else {
7232b94f2ae3 HgDirstate shall operate with Path instead of String for file names. Use of Pair instead of array of unspecified length for parents.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 282
diff changeset
129 int changelogLocalRev = repo.getChangelog().getLocalRevision(dirstateParent);
7232b94f2ae3 HgDirstate shall operate with Path instead of String for file names. Use of Pair instead of array of unspecified length for parents.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 282
diff changeset
130 dirstateParentManifest = getManifest(changelogLocalRev);
7232b94f2ae3 HgDirstate shall operate with Path instead of String for file names. Use of Pair instead of array of unspecified length for parents.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 282
diff changeset
131 }
282
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
132 }
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
133 return dirstateParentManifest;
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
134 }
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
135
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
136 // may be invoked few times, TIP or WORKING_COPY indicate comparison shall be run against working copy parent
275
6d1804fe0ed7 Issue 10: Report file content length with respect of metadata. Respect dirstate parents for WC's status. Exceptions to keep useful attributes of the location
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 248
diff changeset
137 // NOTE, use of TIP constant requires certain care. TIP here doesn't mean latest cset, but actual working copy parent.
93
d55d4eedfc57 Switch to Path instead of String in filenames returned by various status operations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
138 public void walk(int baseRevision, HgStatusInspector inspector) {
282
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
139 if (HgInternals.wrongLocalRevision(baseRevision) || baseRevision == BAD_REVISION) {
218
047b1dec7a04 Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 195
diff changeset
140 throw new IllegalArgumentException(String.valueOf(baseRevision));
047b1dec7a04 Issue 7: Correctly handle manifest and changelog with different number of (or non-matching) revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 195
diff changeset
141 }
282
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
142 ManifestRevision collect = null; // non null indicates we compare against base revision
285
6dbbc53fc46d Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 284
diff changeset
143 Set<Path> baseRevFiles = Collections.emptySet(); // files from base revision not affected by status calculation
282
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
144 if (baseRevision != TIP && baseRevision != WORKING_COPY) {
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
145 collect = getManifest(baseRevision);
285
6dbbc53fc46d Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 284
diff changeset
146 baseRevFiles = new TreeSet<Path>(collect.files());
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
147 }
94
af1f3b78b918 *StatusCollector renamed to Hg*StatusCollector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 93
diff changeset
148 if (inspector instanceof HgStatusCollector.Record) {
af1f3b78b918 *StatusCollector renamed to Hg*StatusCollector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 93
diff changeset
149 HgStatusCollector sc = baseRevisionCollector == null ? new HgStatusCollector(repo) : baseRevisionCollector;
282
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
150 // nodeidAfterChange(dirstate's parent) doesn't make too much sense,
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
151 // because the change might be actually in working copy. Nevertheless,
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
152 // as long as no nodeids can be provided for WC, seems reasonable to report
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
153 // latest known nodeid change (although at the moment this is not used and
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
154 // is done mostly not to leave stale initialization in the Record)
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
155 int rev1,rev2 = getDirstateParentManifest().changesetLocalRev();
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
156 if (baseRevision == TIP || baseRevision == WORKING_COPY) {
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
157 rev1 = rev2 - 1; // just use revision prior to dirstate's parent
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
158 } else {
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
159 rev1 = baseRevision;
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
160 }
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
161 ((HgStatusCollector.Record) inspector).init(rev1, rev2, sc);
68
0e499fed9b3d StatusCommand with tests. Extra constants to indicate common revision cases
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 63
diff changeset
162 }
282
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
163 final HgIgnore hgIgnore = repo.getIgnore();
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
164 repoWalker.reset();
293
9774f47d904d Issue 13: Status reports filenames with case other than in dirstate incorrectly
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 290
diff changeset
165 TreeSet<Path> processed = new TreeSet<Path>(); // names of files we handled as they known to Dirstate (not FileIterator)
9774f47d904d Issue 13: Status reports filenames with case other than in dirstate incorrectly
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 290
diff changeset
166 final HgDirstate ds = getDirstate();
9774f47d904d Issue 13: Status reports filenames with case other than in dirstate incorrectly
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 290
diff changeset
167 TreeSet<Path> knownEntries = ds.all(); // here just to get dirstate initialized
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
168 while (repoWalker.hasNext()) {
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
169 repoWalker.next();
284
7232b94f2ae3 HgDirstate shall operate with Path instead of String for file names. Use of Pair instead of array of unspecified length for parents.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 282
diff changeset
170 final Path fname = getPathPool().path(repoWalker.name());
287
ed6b74a58c66 Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
171 FileInfo f = repoWalker.file();
293
9774f47d904d Issue 13: Status reports filenames with case other than in dirstate incorrectly
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 290
diff changeset
172 Path knownInDirstate;
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
173 if (!f.exists()) {
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
174 // file coming from iterator doesn't exist.
293
9774f47d904d Issue 13: Status reports filenames with case other than in dirstate incorrectly
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 290
diff changeset
175 if ((knownInDirstate = ds.known(fname)) != null) {
9774f47d904d Issue 13: Status reports filenames with case other than in dirstate incorrectly
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 290
diff changeset
176 // found in dirstate
9774f47d904d Issue 13: Status reports filenames with case other than in dirstate incorrectly
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 290
diff changeset
177 processed.add(knownInDirstate);
9774f47d904d Issue 13: Status reports filenames with case other than in dirstate incorrectly
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 290
diff changeset
178 if (ds.checkRemoved(fname) == null) {
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
179 inspector.missing(fname);
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
180 } else {
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
181 inspector.removed(fname);
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
182 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
183 // do not report it as removed later
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
184 if (collect != null) {
285
6dbbc53fc46d Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 284
diff changeset
185 baseRevFiles.remove(fname);
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
186 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
187 } else {
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
188 // chances are it was known in baseRevision. We may rely
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
189 // that later iteration over baseRevFiles leftovers would yield correct Removed,
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
190 // but it doesn't hurt to be explicit (provided we know fname *is* inScope of the FileIterator
285
6dbbc53fc46d Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 284
diff changeset
191 if (collect != null && baseRevFiles.remove(fname)) {
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
192 inspector.removed(fname);
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
193 } else {
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
194 // not sure I shall report such files (i.e. arbitrary name coming from FileIterator)
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
195 // as unknown. Command-line HG aborts "system can't find the file specified"
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
196 // in similar case (against wc), or just gives nothing if --change <rev> is specified.
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
197 // however, as it's unlikely to get unexisting files from FileIterator, and
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
198 // its better to see erroneous file status rather than not to see any (which is too easy
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
199 // to overlook), I think unknown() is reasonable approach here
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
200 inspector.unknown(fname);
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
201 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
202 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
203 continue;
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
204 }
293
9774f47d904d Issue 13: Status reports filenames with case other than in dirstate incorrectly
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 290
diff changeset
205 if ((knownInDirstate = ds.known(fname)) != null) {
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
206 // tracked file.
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
207 // modified, added, removed, clean
293
9774f47d904d Issue 13: Status reports filenames with case other than in dirstate incorrectly
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 290
diff changeset
208 processed.add(knownInDirstate);
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
209 if (collect != null) { // need to check against base revision, not FS file
90
a95c700408a9 Correctly report copy/rename events for rev..working copy case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 89
diff changeset
210 checkLocalStatusAgainstBaseRevision(baseRevFiles, collect, baseRevision, fname, f, inspector);
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
211 } else {
59
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 58
diff changeset
212 checkLocalStatusAgainstFile(fname, f, inspector);
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
213 }
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
214 } else {
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
215 if (hgIgnore.isIgnored(fname)) { // hgignore shall be consulted only for non-tracked files
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
216 inspector.ignored(fname);
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
217 } else {
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
218 inspector.unknown(fname);
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
219 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
220 // the file is not tracked. Even if it's known at baseRevision, we don't need to remove it
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
221 // from baseRevFiles, it might need to be reported as removed as well (cmdline client does
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
222 // yield two statuses for the same file)
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
223 }
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
224 }
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
225 if (collect != null) {
285
6dbbc53fc46d Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 284
diff changeset
226 for (Path fromBase : baseRevFiles) {
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
227 if (repoWalker.inScope(fromBase)) {
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
228 inspector.removed(fromBase);
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
229 }
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
230 }
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
231 }
293
9774f47d904d Issue 13: Status reports filenames with case other than in dirstate incorrectly
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 290
diff changeset
232 knownEntries.removeAll(processed);
284
7232b94f2ae3 HgDirstate shall operate with Path instead of String for file names. Use of Pair instead of array of unspecified length for parents.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 282
diff changeset
233 for (Path m : knownEntries) {
7232b94f2ae3 HgDirstate shall operate with Path instead of String for file names. Use of Pair instead of array of unspecified length for parents.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 282
diff changeset
234 if (!repoWalker.inScope(m)) {
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
235 // do not report as missing/removed those FileIterator doesn't care about.
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
236 continue;
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
237 }
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
238 // missing known file from a working dir
293
9774f47d904d Issue 13: Status reports filenames with case other than in dirstate incorrectly
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 290
diff changeset
239 if (ds.checkRemoved(m) == null) {
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
240 // not removed from the repository = 'deleted'
284
7232b94f2ae3 HgDirstate shall operate with Path instead of String for file names. Use of Pair instead of array of unspecified length for parents.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 282
diff changeset
241 inspector.missing(m);
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
242 } else {
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
243 // removed from the repo
76
658fa6b3a371 Fixed a defect when a file added and removed past some revision was reported as R for status against that rev
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
244 // if we check against non-tip revision, do not report files that were added past that revision and now removed.
285
6dbbc53fc46d Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 284
diff changeset
245 if (collect == null || baseRevFiles.contains(m)) {
284
7232b94f2ae3 HgDirstate shall operate with Path instead of String for file names. Use of Pair instead of array of unspecified length for parents.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 282
diff changeset
246 inspector.removed(m);
76
658fa6b3a371 Fixed a defect when a file added and removed past some revision was reported as R for status against that rev
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
247 }
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
248 }
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
249 }
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
250 }
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
251
94
af1f3b78b918 *StatusCollector renamed to Hg*StatusCollector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 93
diff changeset
252 public HgStatusCollector.Record status(int baseRevision) {
af1f3b78b918 *StatusCollector renamed to Hg*StatusCollector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 93
diff changeset
253 HgStatusCollector.Record rv = new HgStatusCollector.Record();
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
254 walk(baseRevision, rv);
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
255 return rv;
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
256 }
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
257
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
258 //********************************************
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
259
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
260
287
ed6b74a58c66 Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
261 private void checkLocalStatusAgainstFile(Path fname, FileInfo f, HgStatusInspector inspector) {
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
262 HgDirstate.Record r;
59
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 58
diff changeset
263 if ((r = getDirstate().checkNormal(fname)) != null) {
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
264 // either clean or modified
290
8faad08c709b Expose dirstate to allow pre-configuration of FileIterators for status collection in particular
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 287
diff changeset
265 final boolean timestampEqual = f.lastModified() == r.modificationTime(), sizeEqual = r.size() == f.length();
280
35125450c804 Erroneous and slow status for working copies based on non-tip revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
266 if (timestampEqual && sizeEqual) {
35125450c804 Erroneous and slow status for working copies based on non-tip revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
267 inspector.clean(fname);
290
8faad08c709b Expose dirstate to allow pre-configuration of FileIterators for status collection in particular
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 287
diff changeset
268 } else if (!sizeEqual && r.size() >= 0) {
280
35125450c804 Erroneous and slow status for working copies based on non-tip revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
269 inspector.modified(fname);
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
270 } else {
280
35125450c804 Erroneous and slow status for working copies based on non-tip revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
271 // size is the same or unknown, and, perhaps, different timestamp
120
b19f0ac5ee62 Check against working copy shall expect non-persistent modifications done by filters and not report such files as modified
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 117
diff changeset
272 // check actual content to avoid false modified files
b19f0ac5ee62 Check against working copy shall expect non-persistent modifications done by filters and not report such files as modified
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 117
diff changeset
273 HgDataFile df = repo.getFileNode(fname);
285
6dbbc53fc46d Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 284
diff changeset
274 Nodeid rev = getDirstateParentManifest().nodeid(fname);
282
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
275 if (!areTheSame(f, df, rev)) {
120
b19f0ac5ee62 Check against working copy shall expect non-persistent modifications done by filters and not report such files as modified
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 117
diff changeset
276 inspector.modified(df.getPath());
180
42fe9a94b9d0 Report files as clean when no difference but timestamp found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
277 } else {
42fe9a94b9d0 Report files as clean when no difference but timestamp found
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
278 inspector.clean(df.getPath());
120
b19f0ac5ee62 Check against working copy shall expect non-persistent modifications done by filters and not report such files as modified
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 117
diff changeset
279 }
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
280 }
59
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 58
diff changeset
281 } else if ((r = getDirstate().checkAdded(fname)) != null) {
290
8faad08c709b Expose dirstate to allow pre-configuration of FileIterators for status collection in particular
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 287
diff changeset
282 if (r.copySource() == null) {
280
35125450c804 Erroneous and slow status for working copies based on non-tip revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
283 inspector.added(fname);
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
284 } else {
290
8faad08c709b Expose dirstate to allow pre-configuration of FileIterators for status collection in particular
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 287
diff changeset
285 inspector.copied(r.copySource(), fname);
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
286 }
59
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 58
diff changeset
287 } else if ((r = getDirstate().checkRemoved(fname)) != null) {
280
35125450c804 Erroneous and slow status for working copies based on non-tip revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
288 inspector.removed(fname);
59
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 58
diff changeset
289 } else if ((r = getDirstate().checkMerged(fname)) != null) {
280
35125450c804 Erroneous and slow status for working copies based on non-tip revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
290 inspector.modified(fname);
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
291 }
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
292 }
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
293
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
294 // XXX refactor checkLocalStatus methods in more OO way
287
ed6b74a58c66 Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
295 private void checkLocalStatusAgainstBaseRevision(Set<Path> baseRevNames, ManifestRevision collect, int baseRevision, Path fname, FileInfo f, HgStatusInspector inspector) {
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
296 // fname is in the dirstate, either Normal, Added, Removed or Merged
285
6dbbc53fc46d Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 284
diff changeset
297 Nodeid nid1 = collect.nodeid(fname);
6dbbc53fc46d Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 284
diff changeset
298 HgManifest.Flags flags = collect.flags(fname);
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
299 HgDirstate.Record r;
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
300 if (nid1 == null) {
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
301 // normal: added?
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
302 // added: not known at the time of baseRevision, shall report
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
303 // merged: was not known, report as added?
90
a95c700408a9 Correctly report copy/rename events for rev..working copy case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 89
diff changeset
304 if ((r = getDirstate().checkNormal(fname)) != null) {
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
305 try {
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
306 Path origin = HgStatusCollector.getOriginIfCopy(repo, fname, baseRevNames, baseRevision);
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
307 if (origin != null) {
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
308 inspector.copied(getPathPool().path(origin), fname);
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
309 return;
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
310 }
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
311 } catch (HgDataStreamException ex) {
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
312 ex.printStackTrace();
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
313 // FIXME report to a mediator, continue status collection
90
a95c700408a9 Correctly report copy/rename events for rev..working copy case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 89
diff changeset
314 }
a95c700408a9 Correctly report copy/rename events for rev..working copy case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 89
diff changeset
315 } else if ((r = getDirstate().checkAdded(fname)) != null) {
290
8faad08c709b Expose dirstate to allow pre-configuration of FileIterators for status collection in particular
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 287
diff changeset
316 if (r.copySource() != null && baseRevNames.contains(r.copySource())) {
8faad08c709b Expose dirstate to allow pre-configuration of FileIterators for status collection in particular
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 287
diff changeset
317 baseRevNames.remove(r.copySource()); // XXX surely I shall not report rename source as Removed?
8faad08c709b Expose dirstate to allow pre-configuration of FileIterators for status collection in particular
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 287
diff changeset
318 inspector.copied(r.copySource(), fname);
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
319 return;
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
320 }
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
321 // fall-through, report as added
59
b771e94a4f7c Introduce Internals to keep LocalHgRepo casts and alike in a single place. WCSC optionally to reuse SC data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 58
diff changeset
322 } else if (getDirstate().checkRemoved(fname) != null) {
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
323 // removed: removed file was not known at the time of baseRevision, and we should not report it as removed
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
324 return;
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
325 }
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
326 inspector.added(fname);
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
327 } else {
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
328 // was known; check whether clean or modified
285
6dbbc53fc46d Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 284
diff changeset
329 Nodeid nidFromDirstate = getDirstateParentManifest().nodeid(fname);
282
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
330 if ((r = getDirstate().checkNormal(fname)) != null && nid1.equals(nidFromDirstate)) {
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
331 // regular file, was the same up to WC initialization. Check if was modified since, and, if not, report right away
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
332 // same code as in #checkLocalStatusAgainstFile
290
8faad08c709b Expose dirstate to allow pre-configuration of FileIterators for status collection in particular
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 287
diff changeset
333 final boolean timestampEqual = f.lastModified() == r.modificationTime(), sizeEqual = r.size() == f.length();
282
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
334 boolean handled = false;
280
35125450c804 Erroneous and slow status for working copies based on non-tip revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
335 if (timestampEqual && sizeEqual) {
35125450c804 Erroneous and slow status for working copies based on non-tip revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
336 inspector.clean(fname);
282
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
337 handled = true;
290
8faad08c709b Expose dirstate to allow pre-configuration of FileIterators for status collection in particular
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 287
diff changeset
338 } else if (!sizeEqual && r.size() >= 0) {
280
35125450c804 Erroneous and slow status for working copies based on non-tip revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
339 inspector.modified(fname);
282
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
340 handled = true;
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
341 } else if (!todoCheckFlagsEqual(f, flags)) {
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
342 // seems like flags have changed, no reason to check content further
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
343 inspector.modified(fname);
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
344 handled = true;
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
345 }
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
346 if (handled) {
285
6dbbc53fc46d Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 284
diff changeset
347 baseRevNames.remove(fname); // consumed, processed, handled.
280
35125450c804 Erroneous and slow status for working copies based on non-tip revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
348 return;
35125450c804 Erroneous and slow status for working copies based on non-tip revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
349 }
282
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
350 // otherwise, shall check actual content (size not the same, or unknown (-1 or -2), or timestamp is different,
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
351 // or nodeid in dirstate is different, but local change might have brought it back to baseRevision state)
280
35125450c804 Erroneous and slow status for working copies based on non-tip revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
352 // FALL THROUGH
35125450c804 Erroneous and slow status for working copies based on non-tip revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
353 }
282
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
354 if (r != null || (r = getDirstate().checkMerged(fname)) != null || (r = getDirstate().checkAdded(fname)) != null) {
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
355 // check actual content to see actual changes
280
35125450c804 Erroneous and slow status for working copies based on non-tip revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
356 // when added - seems to be the case of a file added once again, hence need to check if content is different
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
357 // either clean or modified
282
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
358 HgDataFile fileNode = repo.getFileNode(fname);
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
359 if (areTheSame(f, fileNode, nid1)) {
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
360 inspector.clean(fname);
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
361 } else {
282
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
362 inspector.modified(fname);
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
363 }
285
6dbbc53fc46d Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 284
diff changeset
364 baseRevNames.remove(fname); // consumed, processed, handled.
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
365 } else if (getDirstate().checkRemoved(fname) != null) {
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
366 // was known, and now marked as removed, report it right away, do not rely on baseRevNames processing later
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
367 inspector.removed(fname);
285
6dbbc53fc46d Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 284
diff changeset
368 baseRevNames.remove(fname); // consumed, processed, handled.
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
369 }
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
370 // only those left in baseRevNames after processing are reported as removed
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
371 }
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
372
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
373 // TODO think over if content comparison may be done more effectively by e.g. calculating nodeid for a local file and comparing it with nodeid from manifest
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
374 // we don't need to tell exact difference, hash should be enough to detect difference, and it doesn't involve reading historical file content, and it's relatively
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
375 // cheap to calc hash on a file (no need to keep it completely in memory). OTOH, if I'm right that the next approach is used for nodeids:
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
376 // changeset nodeid + hash(actual content) => entry (Nodeid) in the next Manifest
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
377 // then it's sufficient to check parents from dirstate, and if they do not match parents from file's baseRevision (non matching parents means different nodeids).
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
378 // The question is whether original Hg treats this case (same content, different parents and hence nodeids) as 'modified' or 'clean'
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
379 }
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
380
287
ed6b74a58c66 Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
381 private boolean areTheSame(FileInfo f, HgDataFile dataFile, Nodeid revision) {
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
382 // XXX consider adding HgDataDile.compare(File/byte[]/whatever) operation to optimize comparison
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
383 ByteArrayChannel bac = new ByteArrayChannel();
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
384 boolean ioFailed = false;
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
385 try {
282
e51dd9a14b6f Yet another WC status fix, where dirstate parent and base revision are treated right (dirstate parent other than tip and explicit baseRevision are not the same)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 280
diff changeset
386 int localRevision = dataFile.getLocalRevision(revision);
157
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
387 // need content with metadata striped off - although theoretically chances are metadata may be different,
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
388 // WC doesn't have it anyway
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
389 dataFile.content(localRevision, bac);
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
390 } catch (CancelledException ex) {
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
391 // silently ignore - can't happen, ByteArrayChannel is not cancellable
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
392 } catch (HgException ex) {
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
393 ioFailed = true;
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
394 }
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
395 return !ioFailed && areTheSame(f, bac.toArray(), dataFile.getPath());
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
396 }
d5268ca7715b Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
397
287
ed6b74a58c66 Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
398 private boolean areTheSame(FileInfo f, final byte[] data, Path p) {
ed6b74a58c66 Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
399 ReadableByteChannel is = null;
117
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
400 try {
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
401 try {
287
ed6b74a58c66 Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
402 is = f.newInputChannel();
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
403 ByteBuffer fb = ByteBuffer.allocate(min(1 + data.length * 2 /*to fit couple of lines appended; never zero*/, 8192));
219
d63583b47bfa ArrayIndexOutOfBoundsException when file appended. Erroneous 'areTheSame' when trailing were deleted.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
404 class Check implements ByteChannel {
d63583b47bfa ArrayIndexOutOfBoundsException when file appended. Erroneous 'areTheSame' when trailing were deleted.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
405 final boolean debug = false; // XXX may want to add global variable to allow clients to turn
d63583b47bfa ArrayIndexOutOfBoundsException when file appended. Erroneous 'areTheSame' when trailing were deleted.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
406 boolean sameSoFar = true;
117
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
407 int x = 0;
219
d63583b47bfa ArrayIndexOutOfBoundsException when file appended. Erroneous 'areTheSame' when trailing were deleted.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
408
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 142
diff changeset
409 public int write(ByteBuffer buffer) {
117
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
410 for (int i = buffer.remaining(); i > 0; i--, x++) {
219
d63583b47bfa ArrayIndexOutOfBoundsException when file appended. Erroneous 'areTheSame' when trailing were deleted.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
411 if (x >= data.length /*file has been appended*/ || data[x] != buffer.get()) {
120
b19f0ac5ee62 Check against working copy shall expect non-persistent modifications done by filters and not report such files as modified
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 117
diff changeset
412 if (debug) {
b19f0ac5ee62 Check against working copy shall expect non-persistent modifications done by filters and not report such files as modified
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 117
diff changeset
413 byte[] xx = new byte[15];
b19f0ac5ee62 Check against working copy shall expect non-persistent modifications done by filters and not report such files as modified
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 117
diff changeset
414 if (buffer.position() > 5) {
b19f0ac5ee62 Check against working copy shall expect non-persistent modifications done by filters and not report such files as modified
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 117
diff changeset
415 buffer.position(buffer.position() - 5);
b19f0ac5ee62 Check against working copy shall expect non-persistent modifications done by filters and not report such files as modified
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 117
diff changeset
416 }
b19f0ac5ee62 Check against working copy shall expect non-persistent modifications done by filters and not report such files as modified
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 117
diff changeset
417 buffer.get(xx);
b19f0ac5ee62 Check against working copy shall expect non-persistent modifications done by filters and not report such files as modified
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 117
diff changeset
418 System.out.print("expected >>" + new String(data, max(0, x - 4), 20) + "<< but got >>");
b19f0ac5ee62 Check against working copy shall expect non-persistent modifications done by filters and not report such files as modified
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 117
diff changeset
419 System.out.println(new String(xx) + "<<");
b19f0ac5ee62 Check against working copy shall expect non-persistent modifications done by filters and not report such files as modified
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 117
diff changeset
420 }
219
d63583b47bfa ArrayIndexOutOfBoundsException when file appended. Erroneous 'areTheSame' when trailing were deleted.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
421 sameSoFar = false;
117
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
422 break;
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
423 }
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
424 }
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
425 buffer.position(buffer.limit()); // mark as read
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
426 return buffer.limit();
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
427 }
219
d63583b47bfa ArrayIndexOutOfBoundsException when file appended. Erroneous 'areTheSame' when trailing were deleted.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
428
d63583b47bfa ArrayIndexOutOfBoundsException when file appended. Erroneous 'areTheSame' when trailing were deleted.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
429 public boolean sameSoFar() {
d63583b47bfa ArrayIndexOutOfBoundsException when file appended. Erroneous 'areTheSame' when trailing were deleted.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
430 return sameSoFar;
d63583b47bfa ArrayIndexOutOfBoundsException when file appended. Erroneous 'areTheSame' when trailing were deleted.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
431 }
d63583b47bfa ArrayIndexOutOfBoundsException when file appended. Erroneous 'areTheSame' when trailing were deleted.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
432 public boolean ultimatelyTheSame() {
d63583b47bfa ArrayIndexOutOfBoundsException when file appended. Erroneous 'areTheSame' when trailing were deleted.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
433 return sameSoFar && x == data.length;
d63583b47bfa ArrayIndexOutOfBoundsException when file appended. Erroneous 'areTheSame' when trailing were deleted.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
434 }
117
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
435 };
219
d63583b47bfa ArrayIndexOutOfBoundsException when file appended. Erroneous 'areTheSame' when trailing were deleted.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
436 Check check = new Check();
117
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
437 FilterByteChannel filters = new FilterByteChannel(check, repo.getFiltersFromWorkingDirToRepo(p));
287
ed6b74a58c66 Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
438 while (is.read(fb) != -1 && check.sameSoFar()) {
117
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
439 fb.flip();
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
440 filters.write(fb);
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
441 fb.compact();
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
442 }
219
d63583b47bfa ArrayIndexOutOfBoundsException when file appended. Erroneous 'areTheSame' when trailing were deleted.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
443 return check.ultimatelyTheSame();
117
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
444 } catch (IOException ex) {
287
ed6b74a58c66 Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
445 ex.printStackTrace(); // log warn
ed6b74a58c66 Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
446 } finally {
ed6b74a58c66 Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
447 if (is != null) {
ed6b74a58c66 Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
448 is.close();
117
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
449 }
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
450 }
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
451 } catch (/*TODO typed*/Exception ex) {
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
452 ex.printStackTrace();
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
453 }
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
454 return false;
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
455 }
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
456
287
ed6b74a58c66 Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
457 private static boolean todoCheckFlagsEqual(FileInfo f, HgManifest.Flags originalManifestFlags) {
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
458 // FIXME implement
280
35125450c804 Erroneous and slow status for working copies based on non-tip revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
459 return true;
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
460 }
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
461
229
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
462 /**
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
463 * Configure status collector to consider only subset of a working copy tree. Tries to be as effective as possible, and to
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
464 * traverse only relevant part of working copy on the filesystem.
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
465 *
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
466 * @param hgRepo repository
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
467 * @param paths repository-relative files and/or directories. Directories are processed recursively.
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
468 *
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
469 * @return new instance of {@link HgWorkingCopyStatusCollector}, ready to {@link #walk(int, HgStatusInspector) walk} associated working copy
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
470 */
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
471 @Experimental(reason="Provisional API")
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
472 public static HgWorkingCopyStatusCollector create(HgRepository hgRepo, Path... paths) {
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
473 ArrayList<Path> f = new ArrayList<Path>(5);
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
474 ArrayList<Path> d = new ArrayList<Path>(5);
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
475 for (Path p : paths) {
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
476 if (p.isDirectory()) {
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
477 d.add(p);
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
478 } else {
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
479 f.add(p);
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
480 }
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
481 }
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
482 // final Path[] dirs = f.toArray(new Path[d.size()]);
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
483 if (d.isEmpty()) {
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
484 final Path[] files = f.toArray(new Path[f.size()]);
237
6e1373b54e9b Allow access to working copy content through HgDataFile. Give access to repository's working dir
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 229
diff changeset
485 FileIterator fi = new FileListIterator(hgRepo.getWorkingDir(), files);
229
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
486 return new HgWorkingCopyStatusCollector(hgRepo, fi);
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
487 }
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
488 //
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
489
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
490 //FileIterator fi = file.isDirectory() ? new DirFileIterator(hgRepo, file) : new FileListIterator(, file);
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
491 FileIterator fi = new HgInternals(hgRepo).createWorkingDirWalker(new PathScope(true, paths));
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
492 return new HgWorkingCopyStatusCollector(hgRepo, fi);
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
493 }
229
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
494
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
495 /**
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
496 * Configure collector object to calculate status for matching files only.
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
497 * This method may be less effective than explicit list of files as it iterates over whole repository
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
498 * (thus supplied matcher doesn't need to care if directories to files in question are also in scope,
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
499 * see {@link FileWalker#FileWalker(File, Path.Source, Path.Matcher)})
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
500 *
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
501 * @return new instance of {@link HgWorkingCopyStatusCollector}, ready to {@link #walk(int, HgStatusInspector) walk} associated working copy
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
502 */
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
503 @Experimental(reason="Provisional API. May add boolean strict argument for those who write smart matchers that can be used in FileWalker")
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
504 public static HgWorkingCopyStatusCollector create(HgRepository hgRepo, Path.Matcher scope) {
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
505 FileIterator w = new HgInternals(hgRepo).createWorkingDirWalker(null);
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
506 FileIterator wf = (scope == null || scope instanceof Path.Matcher.Any) ? w : new FileIteratorFilter(w, scope);
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
507 // the reason I need to iterate over full repo and apply filter is that I have no idea whatsoever about
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
508 // patterns in the scope. I.e. if scope lists a file (PathGlobMatcher("a/b/c.txt")), FileWalker won't get deep
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
509 // to the file unless matcher would also explicitly include "a/", "a/b/" in scope. Since I can't rely
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
510 // users would write robust matchers, and I don't see a decent way to enforce that (i.e. factory to produce
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
511 // correct matcher from Path is much like what PathScope does, and can be accessed directly with #create(repo, Path...)
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
512 // method above/
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
513 return new HgWorkingCopyStatusCollector(hgRepo, wf);
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
514 }
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
515
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
516 private static class FileListIterator implements FileIterator {
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
517 private final File dir;
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
518 private final Path[] paths;
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
519 private int index;
287
ed6b74a58c66 Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
520 private RegularFileInfo nextFile;
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
521
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
522 public FileListIterator(File startDir, Path... files) {
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
523 dir = startDir;
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
524 paths = files;
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
525 reset();
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
526 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
527
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
528 public void reset() {
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
529 index = -1;
287
ed6b74a58c66 Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
530 nextFile = new RegularFileInfo();
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
531 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
532
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
533 public boolean hasNext() {
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
534 return paths.length > 0 && index < paths.length-1;
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
535 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
536
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
537 public void next() {
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
538 index++;
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
539 if (index == paths.length) {
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
540 throw new NoSuchElementException();
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
541 }
287
ed6b74a58c66 Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
542 nextFile.init(new File(dir, paths[index].toString()));
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
543 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
544
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
545 public Path name() {
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
546 return paths[index];
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
547 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
548
287
ed6b74a58c66 Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
549 public FileInfo file() {
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
550 return nextFile;
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
551 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
552
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
553 public boolean inScope(Path file) {
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
554 for (int i = 0; i < paths.length; i++) {
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
555 if (paths[i].equals(file)) {
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
556 return true;
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
557 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
558 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
559 return false;
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
560 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
561 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
562
229
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
563 private static class FileIteratorFilter implements FileIterator {
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
564 private final Path.Matcher filter;
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
565 private final FileIterator walker;
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
566 private boolean didNext = false;
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
567
229
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
568 public FileIteratorFilter(FileIterator fileWalker, Path.Matcher filterMatcher) {
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
569 assert fileWalker != null;
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
570 assert filterMatcher != null;
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
571 filter = filterMatcher;
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
572 walker = fileWalker;
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
573 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
574
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
575 public void reset() {
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
576 walker.reset();
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
577 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
578
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
579 public boolean hasNext() {
229
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
580 while (walker.hasNext()) {
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
581 walker.next();
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
582 if (filter.accept(walker.name())) {
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
583 didNext = true;
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
584 return true;
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
585 }
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
586 }
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
587 return false;
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
588 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
589
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
590 public void next() {
229
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
591 if (didNext) {
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
592 didNext = false;
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
593 } else {
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
594 if (!hasNext()) {
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
595 throw new NoSuchElementException();
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
596 }
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
597 }
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
598 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
599
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
600 public Path name() {
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
601 return walker.name();
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
602 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
603
287
ed6b74a58c66 Use FileInfo abstraction with necessary subset of File functionality instead of File to facilitate other effective file system iterators
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 285
diff changeset
604 public FileInfo file() {
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
605 return walker.file();
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
606 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
607
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
608 public boolean inScope(Path file) {
229
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
609 return filter.accept(file);
226
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
610 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
611 }
58
4cfc47bc14cc Status against local working dir extracted into distinct class. Iterating over local files extracted for ease of os-dependant patching
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
612 }