annotate src/org/tmatesoft/hg/repo/HgWorkingCopyStatusCollector.java @ 613:f41dd9a3b8af v1.1m4

Remove few Experimental annotations as the API they've marked graduates
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 10 May 2013 17:31:27 +0200
parents e1b29756f901
children 6526d8adbc0f
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 /*
537
5a455624be4f Update javadoc for HgManifest.Inspector and fix erroneous internal API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 506
diff changeset
2 * Copyright (c) 2011-2013 TMate Software Ltd
74
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.*;
456
909306e412e2 Refactor LogFacility and SessionContext, better API for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
22 import static org.tmatesoft.hg.util.LogFacility.Severity.*;
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
23
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.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
25 import java.io.IOException;
117
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
26 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
27 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
28 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
29 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
30 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
31 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
32 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
33
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
34 import org.tmatesoft.hg.core.Nodeid;
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 423
diff changeset
35 import org.tmatesoft.hg.core.SessionContext;
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;
117
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
37 import org.tmatesoft.hg.internal.FilterByteChannel;
413
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
38 import org.tmatesoft.hg.internal.Internals;
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;
431
12f668401613 FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 429
diff changeset
40 import org.tmatesoft.hg.internal.PathPool;
229
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
41 import org.tmatesoft.hg.internal.PathScope;
355
f2c11fe7f3e9 Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
42 import org.tmatesoft.hg.internal.Preview;
356
91d75e1bac9f Consistent approach to deal with adaptable objects. Give adaptable precedence over instanceof to allow conditional response when classes do implement desired interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 355
diff changeset
43 import org.tmatesoft.hg.util.Adaptable;
117
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
44 import org.tmatesoft.hg.util.ByteChannel;
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
45 import org.tmatesoft.hg.util.CancelSupport;
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
46 import org.tmatesoft.hg.util.CancelledException;
431
12f668401613 FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 429
diff changeset
47 import org.tmatesoft.hg.util.Convertor;
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
48 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
49 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
50 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
51 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
52 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
53 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
54
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 /**
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
56 *
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
57 * @author Artem Tikhomirov
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
58 * @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
59 */
94
af1f3b78b918 *StatusCollector renamed to Hg*StatusCollector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 93
diff changeset
60 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
61
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
62 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
63 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
64 private HgDirstate dirstate;
94
af1f3b78b918 *StatusCollector renamed to Hg*StatusCollector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 93
diff changeset
65 private HgStatusCollector baseRevisionCollector;
431
12f668401613 FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 429
diff changeset
66 private Convertor<Path> 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
67 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
68
362
4937e35b805b Report dirstate access error with Exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 360
diff changeset
69 /**
4937e35b805b Report dirstate access error with Exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 360
diff changeset
70 * Collector that iterates over complete working copy
4937e35b805b Report dirstate access error with Exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 360
diff changeset
71 */
94
af1f3b78b918 *StatusCollector renamed to Hg*StatusCollector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 93
diff changeset
72 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
73 this(hgRepo, new HgInternals(hgRepo).createWorkingDirWalker(null));
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
74 }
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
75
362
4937e35b805b Report dirstate access error with Exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 360
diff changeset
76 /**
4937e35b805b Report dirstate access error with Exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 360
diff changeset
77 * Collector may analyze and report status for any arbitrary sub-tree of the working copy.
4937e35b805b Report dirstate access error with Exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 360
diff changeset
78 * File iterator shall return names of the files relative to the repository root.
4937e35b805b Report dirstate access error with Exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 360
diff changeset
79 *
4937e35b805b Report dirstate access error with Exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 360
diff changeset
80 * @param hgRepo status target repository
4937e35b805b Report dirstate access error with Exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 360
diff changeset
81 * @param workingCopyWalker iterator over files in the working copy
4937e35b805b Report dirstate access error with Exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 360
diff changeset
82 */
4937e35b805b Report dirstate access error with Exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 360
diff changeset
83 public HgWorkingCopyStatusCollector(HgRepository hgRepo, FileIterator workingCopyWalker) {
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
84 repo = hgRepo;
362
4937e35b805b Report dirstate access error with Exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 360
diff changeset
85 repoWalker = workingCopyWalker;
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
86 }
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
87
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
88 /**
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
89 * 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
90 * @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
91 */
94
af1f3b78b918 *StatusCollector renamed to Hg*StatusCollector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 93
diff changeset
92 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
93 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
94 }
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
95
431
12f668401613 FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 429
diff changeset
96 /*package-local*/ Convertor<Path> getPathPool() {
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
97 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
98 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
99 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
100 } 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
101 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
102 }
d55d4eedfc57 Switch to Path instead of String in filenames returned by various status operations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
103 }
d55d4eedfc57 Switch to Path instead of String in filenames returned by various status operations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
104 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
105 }
d55d4eedfc57 Switch to Path instead of String in filenames returned by various status operations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
106
431
12f668401613 FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 429
diff changeset
107 public void setPathPool(Convertor<Path> pathConvertor) {
12f668401613 FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 429
diff changeset
108 pathPool = pathConvertor;
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
109 }
d55d4eedfc57 Switch to Path instead of String in filenames returned by various status operations
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 91
diff changeset
110
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
111 /**
8faad08c709b Expose dirstate to allow pre-configuration of FileIterators for status collection in particular
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 287
diff changeset
112 * 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
113 * @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
114 */
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 337
diff changeset
115 public HgDirstate getDirstate() throws HgInvalidControlFileException {
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
116 if (dirstate == null) {
431
12f668401613 FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 429
diff changeset
117 Convertor<Path> pp = getPathPool();
12f668401613 FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 429
diff changeset
118 Path.Source ps;
12f668401613 FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 429
diff changeset
119 if (pp instanceof Path.Source) {
12f668401613 FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 429
diff changeset
120 ps = (Path.Source) pp;
12f668401613 FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 429
diff changeset
121 } else {
12f668401613 FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 429
diff changeset
122 ps = new Path.SimpleSource(new PathRewrite.Empty(), pp);
12f668401613 FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 429
diff changeset
123 }
12f668401613 FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 429
diff changeset
124 dirstate = repo.loadDirstate(ps);
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
125 }
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
126 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
127 }
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
128
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 337
diff changeset
129 private HgDirstate getDirstateImpl() {
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 337
diff changeset
130 return dirstate;
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 337
diff changeset
131 }
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 337
diff changeset
132
366
189dc6dc1c3e Use exceptions to expose errors reading mercurial data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 362
diff changeset
133 private ManifestRevision getManifest(int changelogLocalRev) throws HgInvalidControlFileException {
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
134 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
135 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
136 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
137 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
138 } 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
139 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
140 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
141 }
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 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
143 }
354
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 350
diff changeset
144
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 350
diff changeset
145 private void initDirstateParentManifest() throws HgInvalidControlFileException {
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 350
diff changeset
146 Nodeid dirstateParent = getDirstateImpl().parents().first();
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 350
diff changeset
147 if (dirstateParent.isNull()) {
405
866fc3b597a0 Add an explicit constant instead of -1 to indicate 'no revision' case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 397
diff changeset
148 dirstateParentManifest = baseRevisionCollector != null ? baseRevisionCollector.raw(NO_REVISION) : HgStatusCollector.createEmptyManifestRevision();
354
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 350
diff changeset
149 } else {
367
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
150 int changeloRevIndex = repo.getChangelog().getRevisionIndex(dirstateParent);
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
151 dirstateParentManifest = getManifest(changeloRevIndex);
354
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 350
diff changeset
152 }
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 350
diff changeset
153 }
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 350
diff changeset
154
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 350
diff changeset
155 // WC not necessarily points to TIP, but may be result of update to any previous revision.
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 350
diff changeset
156 // In such case, we need to compare local files not to their TIP content, but to specific version at the time of selected revision
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
157 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
158 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
159 }
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
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
161 /**
429
cd658b24a620 FIXMEs: javadoc, proper use of constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 425
diff changeset
162 * Walk working copy, analyze status for each file found and missing.
cd658b24a620 FIXMEs: javadoc, proper use of constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 425
diff changeset
163 * May be invoked few times.
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
164 *
506
27398bbfd543 Experiment to add a facility to check working files for actual changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 496
diff changeset
165 * <p>There's no dedicated constant for working copy parent, at least now.
429
cd658b24a620 FIXMEs: javadoc, proper use of constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 425
diff changeset
166 * Use {@link HgRepository#WORKING_COPY} to indicate comparison
cd658b24a620 FIXMEs: javadoc, proper use of constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 425
diff changeset
167 * shall be run against working copy parent. Although a bit confusing, single case doesn't
cd658b24a620 FIXMEs: javadoc, proper use of constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 425
diff changeset
168 * justify a dedicated constant.
cd658b24a620 FIXMEs: javadoc, proper use of constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 425
diff changeset
169 *
cd658b24a620 FIXMEs: javadoc, proper use of constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 425
diff changeset
170 * @param baseRevision revision index to check against, or {@link HgRepository#WORKING_COPY}. Note, {@link HgRepository#TIP} is not supported.
cd658b24a620 FIXMEs: javadoc, proper use of constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 425
diff changeset
171 * @param inspector callback to receive status information
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
172 * @throws IOException to propagate IO errors from {@link FileIterator}
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
173 * @throws CancelledException if operation execution was cancelled
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
174 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em>
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
175 */
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
176 public void walk(int baseRevision, HgStatusInspector inspector) throws IOException, CancelledException, HgRuntimeException {
367
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
177 if (HgInternals.wrongRevisionIndex(baseRevision) || baseRevision == BAD_REVISION) {
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 423
diff changeset
178 throw new HgInvalidRevisionException(baseRevision);
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
179 }
362
4937e35b805b Report dirstate access error with Exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 360
diff changeset
180 if (getDirstateImpl() == null) {
4937e35b805b Report dirstate access error with Exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 360
diff changeset
181 getDirstate();
4937e35b805b Report dirstate access error with Exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 360
diff changeset
182 }
4937e35b805b Report dirstate access error with Exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 360
diff changeset
183 if (getDirstateParentManifest() == null) {
4937e35b805b Report dirstate access error with Exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 360
diff changeset
184 initDirstateParentManifest();
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 337
diff changeset
185 }
429
cd658b24a620 FIXMEs: javadoc, proper use of constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 425
diff changeset
186 // XXX NOTE, use of TIP for working copy parent is questionable, at least. Instead, TIP shall mean latest cset or not allowed at all
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
187 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
188 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
189 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
190 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
191 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
192 }
94
af1f3b78b918 *StatusCollector renamed to Hg*StatusCollector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 93
diff changeset
193 if (inspector instanceof HgStatusCollector.Record) {
af1f3b78b918 *StatusCollector renamed to Hg*StatusCollector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 93
diff changeset
194 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
195 // 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
196 // 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
197 // 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
198 // 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
199 // is done mostly not to leave stale initialization in the Record)
537
5a455624be4f Update javadoc for HgManifest.Inspector and fix erroneous internal API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 506
diff changeset
200 int rev1,rev2 = getDirstateParentManifest().changesetRevisionIndex();
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
201 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
202 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
203 } 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
204 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
205 }
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
206 ((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
207 }
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
208 final CancelSupport cs = CancelSupport.Factory.get(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
209 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
210 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
211 TreeSet<Path> processed = new TreeSet<Path>(); // names of files we handled as they known to Dirstate (not FileIterator)
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 337
diff changeset
212 final HgDirstate ds = getDirstateImpl();
293
9774f47d904d Issue 13: Status reports filenames with case other than in dirstate incorrectly
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 290
diff changeset
213 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
214 while (repoWalker.hasNext()) {
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
215 cs.checkCancelled();
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
216 repoWalker.next();
431
12f668401613 FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 429
diff changeset
217 final Path fname = getPathPool().mangle(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
218 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
219 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
220 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
221 // 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
222 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
223 // 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
224 processed.add(knownInDirstate);
294
32890bab7209 Issue 13: Report filenames as they are known in repository rather than from file system
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 293
diff changeset
225 if (ds.checkRemoved(knownInDirstate) == null) {
32890bab7209 Issue 13: Report filenames as they are known in repository rather than from file system
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 293
diff changeset
226 inspector.missing(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
227 } else {
294
32890bab7209 Issue 13: Report filenames as they are known in repository rather than from file system
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 293
diff changeset
228 inspector.removed(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
229 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
230 // 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
231 if (collect != null) {
294
32890bab7209 Issue 13: Report filenames as they are known in repository rather than from file system
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 293
diff changeset
232 baseRevFiles.remove(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
233 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
234 } 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
235 // 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
236 // 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
237 // 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
238 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
239 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
240 } 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
241 // 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
242 // 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
243 // 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
244 // 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
245 // 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
246 // 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
247 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
248 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
249 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
250 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
251 }
293
9774f47d904d Issue 13: Status reports filenames with case other than in dirstate incorrectly
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 290
diff changeset
252 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
253 // 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
254 // 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
255 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
256 if (collect != null) { // need to check against base revision, not FS file
294
32890bab7209 Issue 13: Report filenames as they are known in repository rather than from file system
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 293
diff changeset
257 checkLocalStatusAgainstBaseRevision(baseRevFiles, collect, baseRevision, knownInDirstate, 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
258 } else {
294
32890bab7209 Issue 13: Report filenames as they are known in repository rather than from file system
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 293
diff changeset
259 checkLocalStatusAgainstFile(knownInDirstate, 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
260 }
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
261 } 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
262 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
263 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
264 } 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
265 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
266 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
267 // 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
268 // 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
269 // 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
270 }
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
271 }
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
272 if (collect != null) {
473
5c09a9f2e073 Issue 34: incorrect status for a file copy in wc against base rev
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 471
diff changeset
273 // perhaps, this code shall go after processing leftovers of knownEntries, below
5c09a9f2e073 Issue 34: incorrect status for a file copy in wc against base rev
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 471
diff changeset
274 // as it's sort of last resort - what to do with otherwise unprocessed base revision files
285
6dbbc53fc46d Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 284
diff changeset
275 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
276 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
277 inspector.removed(fromBase);
473
5c09a9f2e073 Issue 34: incorrect status for a file copy in wc against base rev
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 471
diff changeset
278 processed.add(fromBase);
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
279 cs.checkCancelled();
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
280 }
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
281 }
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
282 }
293
9774f47d904d Issue 13: Status reports filenames with case other than in dirstate incorrectly
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 290
diff changeset
283 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
284 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
285 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
286 // 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
287 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
288 }
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
289 cs.checkCancelled();
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
290 // 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
291 if (ds.checkRemoved(m) == null) {
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
292 // 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
293 inspector.missing(m);
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
294 } else {
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 68
diff changeset
295 // 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
296 // 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
297 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
298 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
299 }
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
300 }
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 }
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 }
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
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
304 /**
429
cd658b24a620 FIXMEs: javadoc, proper use of constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 425
diff changeset
305 * A {@link #walk(int, HgStatusInspector)} that records all the status information in the {@link HgStatusCollector.Record} object.
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
306 *
429
cd658b24a620 FIXMEs: javadoc, proper use of constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 425
diff changeset
307 * @see #walk(int, HgStatusInspector)
cd658b24a620 FIXMEs: javadoc, proper use of constants
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 425
diff changeset
308 * @param baseRevision revision index to check against, or {@link HgRepository#WORKING_COPY}. Note, {@link HgRepository#TIP} is not supported.
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
309 * @return information object that describes change between the revisions
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
310 * @throws IOException to propagate IO errors from {@link FileIterator}
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
311 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em>
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
312 */
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
313 public HgStatusCollector.Record status(int baseRevision) throws IOException, HgRuntimeException {
94
af1f3b78b918 *StatusCollector renamed to Hg*StatusCollector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 93
diff changeset
314 HgStatusCollector.Record rv = new HgStatusCollector.Record();
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
315 try {
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
316 walk(baseRevision, rv);
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
317 } catch (CancelledException ex) {
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
318 // can't happen as long our Record class doesn't implement CancelSupport
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
319 HgInvalidStateException t = new HgInvalidStateException("Internal error");
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
320 t.initCause(ex);
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
321 throw t;
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
322 }
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 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
324 }
506
27398bbfd543 Experiment to add a facility to check working files for actual changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 496
diff changeset
325
27398bbfd543 Experiment to add a facility to check working files for actual changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 496
diff changeset
326 /**
27398bbfd543 Experiment to add a facility to check working files for actual changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 496
diff changeset
327 * Compares file state from working directory against parent recorded in dirstate.
27398bbfd543 Experiment to add a facility to check working files for actual changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 496
diff changeset
328 * Might be handy for merged files, always reported as 'modified' or files deemed modified
27398bbfd543 Experiment to add a facility to check working files for actual changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 496
diff changeset
329 * based on their flags change.
27398bbfd543 Experiment to add a facility to check working files for actual changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 496
diff changeset
330 *
27398bbfd543 Experiment to add a facility to check working files for actual changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 496
diff changeset
331 * @param fname repository-relative path to the file in question
27398bbfd543 Experiment to add a facility to check working files for actual changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 496
diff changeset
332 * @param fileInfo file content mediator
27398bbfd543 Experiment to add a facility to check working files for actual changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 496
diff changeset
333 * @return <code>true</code> when content in working dir differs from that of manifest-recorded revision
27398bbfd543 Experiment to add a facility to check working files for actual changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 496
diff changeset
334 */
27398bbfd543 Experiment to add a facility to check working files for actual changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 496
diff changeset
335 public boolean hasTangibleChanges(Path fname, FileInfo fileInfo) throws HgRuntimeException {
27398bbfd543 Experiment to add a facility to check working files for actual changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 496
diff changeset
336 // see #checkLocalStatusAgainstFile() below for the origin of changed file check
27398bbfd543 Experiment to add a facility to check working files for actual changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 496
diff changeset
337 HgDataFile df = repo.getFileNode(fname);
27398bbfd543 Experiment to add a facility to check working files for actual changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 496
diff changeset
338 if (!df.exists()) {
27398bbfd543 Experiment to add a facility to check working files for actual changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 496
diff changeset
339 throw new HgInvalidFileException("File not found", null).setFileName(fname);
27398bbfd543 Experiment to add a facility to check working files for actual changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 496
diff changeset
340 }
27398bbfd543 Experiment to add a facility to check working files for actual changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 496
diff changeset
341 Nodeid rev = getDirstateParentManifest().nodeid(fname);
27398bbfd543 Experiment to add a facility to check working files for actual changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 496
diff changeset
342 return rev == null || !areTheSame(fileInfo, df, rev);
27398bbfd543 Experiment to add a facility to check working files for actual changes
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 496
diff changeset
343 }
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
344
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
345 //********************************************
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
346
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
347
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
348 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
349 HgDirstate.Record r;
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 337
diff changeset
350 if ((r = getDirstateImpl().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
351 // 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
352 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
353 if (timestampEqual && sizeEqual) {
413
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
354 // if flags change (chmod -x), timestamp does not change
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
355 if (checkFlagsEqual(f, r.mode())) {
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
356 inspector.clean(fname);
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
357 } else {
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
358 inspector.modified(fname); // flags are not the same
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
359 }
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
360 } 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
361 inspector.modified(fname);
496
c1c8f6859d3f Recognize 'merged from parent' metastate in dirstate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 493
diff changeset
362 } else if (r.size() == -2) {
c1c8f6859d3f Recognize 'merged from parent' metastate in dirstate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 493
diff changeset
363 // DirState wiki calls this np2 metastate:
c1c8f6859d3f Recognize 'merged from parent' metastate in dirstate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 493
diff changeset
364 // 'np2': merged from other parent (status == 'n', size == -2)
c1c8f6859d3f Recognize 'merged from parent' metastate in dirstate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 493
diff changeset
365 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
366 } else {
413
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
367 // size is the same or unknown, and, perhaps, different timestamp
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
368 // check actual content to avoid false modified files
397
5e95b0da26f2 Issue 24: IAE, Underflow in FilterDataAccess. Issue 26:UnsupportedOperationException when patching empty base revision. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 367
diff changeset
369 try {
413
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
370 if (!checkFlagsEqual(f, r.mode())) {
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
371 // flags modified, no need to do expensive content check
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
372 inspector.modified(fname);
397
5e95b0da26f2 Issue 24: IAE, Underflow in FilterDataAccess. Issue 26:UnsupportedOperationException when patching empty base revision. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 367
diff changeset
373 } else {
413
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
374 HgDataFile df = repo.getFileNode(fname);
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
375 if (!df.exists()) {
608
e1b29756f901 Clean, organize and resolve some TODOs and FIXMEs: minor refactorings and comments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 537
diff changeset
376 Internals implRepo = repo.getImplHelper();
493
ba36f66c32b4 Refactor to keep knowledge about repository control files and their location in respect to .hg/ in a single place (facilitate future adoption of shared repositories)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
377 String msg = String.format("File %s known as normal in dirstate (%d, %d), doesn't exist at %s", fname, r.modificationTime(), r.size(), implRepo.getStoragePath(df));
413
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
378 throw new HgInvalidFileException(msg, null).setFileName(fname);
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
379 }
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
380 Nodeid rev = getDirstateParentManifest().nodeid(fname);
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
381 // rev might be null here if fname comes to dirstate as a result of a merge operation
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
382 // where one of the parents (first parent) had no fname file, but second parent had.
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
383 // E.g. fork revision 3, revision 4 gets .hgtags, few modifications and merge(3,12)
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
384 // see Issue 14 for details
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
385 if (rev == null || !areTheSame(f, df, rev)) {
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
386 inspector.modified(df.getPath());
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
387 } else {
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
388 inspector.clean(df.getPath());
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
389 }
397
5e95b0da26f2 Issue 24: IAE, Underflow in FilterDataAccess. Issue 26:UnsupportedOperationException when patching empty base revision. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 367
diff changeset
390 }
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 423
diff changeset
391 } catch (HgRuntimeException ex) {
490
b3c16d1aede0 Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 473
diff changeset
392 repo.getSessionContext().getLog().dump(getClass(), Warn, ex, null);
397
5e95b0da26f2 Issue 24: IAE, Underflow in FilterDataAccess. Issue 26:UnsupportedOperationException when patching empty base revision. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 367
diff changeset
393 inspector.invalid(fname, ex);
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
394 }
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
395 }
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 337
diff changeset
396 } else if ((r = getDirstateImpl().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
397 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
398 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
399 } 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
400 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
401 }
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 337
diff changeset
402 } else if ((r = getDirstateImpl().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
403 inspector.removed(fname);
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 337
diff changeset
404 } else if ((r = getDirstateImpl().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
405 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
406 }
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
407 }
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
408
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
409 // 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
410 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
411 // 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
412 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
413 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
414 HgDirstate.Record r;
471
7bcfbc255f48 Merge changes from smartgit3 branch into 1.1 stream
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 456
diff changeset
415 final HgDirstate ds = getDirstateImpl();
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
416 if (nid1 == null) {
471
7bcfbc255f48 Merge changes from smartgit3 branch into 1.1 stream
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 456
diff changeset
417 // not known at the time of baseRevision:
7bcfbc255f48 Merge changes from smartgit3 branch into 1.1 stream
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 456
diff changeset
418 // normal, added, merged: either added or copied since base revision.
7bcfbc255f48 Merge changes from smartgit3 branch into 1.1 stream
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 456
diff changeset
419 // removed: nothing to report,
7bcfbc255f48 Merge changes from smartgit3 branch into 1.1 stream
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 456
diff changeset
420 if (ds.checkNormal(fname) != null || ds.checkMerged(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
421 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
422 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
423 if (origin != null) {
431
12f668401613 FIXMEs: awkward API refactored, what need to be internal got hidden; public aspects got captured in slim interfaces
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 429
diff changeset
424 inspector.copied(getPathPool().mangle(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
425 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
426 }
471
7bcfbc255f48 Merge changes from smartgit3 branch into 1.1 stream
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 456
diff changeset
427 // fall-through, report as added
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 423
diff changeset
428 } catch (HgInvalidFileException ex) {
360
150500515714 Report non-critical errors during status operation to handler/inspector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 356
diff changeset
429 // report failure and continue status collection
150500515714 Report non-critical errors during status operation to handler/inspector
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 356
diff changeset
430 inspector.invalid(fname, ex);
90
a95c700408a9 Correctly report copy/rename events for rev..working copy case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 89
diff changeset
431 }
471
7bcfbc255f48 Merge changes from smartgit3 branch into 1.1 stream
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 456
diff changeset
432 } else if ((r = ds.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
433 if (r.copySource() != null && baseRevNames.contains(r.copySource())) {
473
5c09a9f2e073 Issue 34: incorrect status for a file copy in wc against base rev
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 471
diff changeset
434 // shall not remove rename source from baseRevNames, as the source
5c09a9f2e073 Issue 34: incorrect status for a file copy in wc against base rev
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 471
diff changeset
435 // likely needs to be reported as Removed as well
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
436 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
437 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
438 }
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
439 // fall-through, report as added
471
7bcfbc255f48 Merge changes from smartgit3 branch into 1.1 stream
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 456
diff changeset
440 } else if (ds.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
441 // 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
442 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
443 }
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
444 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
445 } 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
446 // 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
447 Nodeid nidFromDirstate = getDirstateParentManifest().nodeid(fname);
471
7bcfbc255f48 Merge changes from smartgit3 branch into 1.1 stream
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 456
diff changeset
448 if ((r = ds.checkNormal(fname)) != null && nid1.equals(nidFromDirstate)) {
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
449 // 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
450 // 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
451 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
452 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
453 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
454 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
455 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
456 } 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
457 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
458 handled = true;
413
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
459 } else if (!checkFlagsEqual(f, flags)) {
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
460 // 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
461 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
462 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
463 }
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
464 if (handled) {
285
6dbbc53fc46d Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 284
diff changeset
465 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
466 return;
35125450c804 Erroneous and slow status for working copies based on non-tip revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 275
diff changeset
467 }
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
468 // 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
469 // 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
470 // 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
471 }
471
7bcfbc255f48 Merge changes from smartgit3 branch into 1.1 stream
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 456
diff changeset
472 if (r != null || (r = ds.checkMerged(fname)) != null || (r = ds.checkAdded(fname)) != null) {
397
5e95b0da26f2 Issue 24: IAE, Underflow in FilterDataAccess. Issue 26:UnsupportedOperationException when patching empty base revision. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 367
diff changeset
473 try {
5e95b0da26f2 Issue 24: IAE, Underflow in FilterDataAccess. Issue 26:UnsupportedOperationException when patching empty base revision. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 367
diff changeset
474 // check actual content to see actual changes
5e95b0da26f2 Issue 24: IAE, Underflow in FilterDataAccess. Issue 26:UnsupportedOperationException when patching empty base revision. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 367
diff changeset
475 // when added - seems to be the case of a file added once again, hence need to check if content is different
5e95b0da26f2 Issue 24: IAE, Underflow in FilterDataAccess. Issue 26:UnsupportedOperationException when patching empty base revision. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 367
diff changeset
476 // either clean or modified
5e95b0da26f2 Issue 24: IAE, Underflow in FilterDataAccess. Issue 26:UnsupportedOperationException when patching empty base revision. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 367
diff changeset
477 HgDataFile fileNode = repo.getFileNode(fname);
5e95b0da26f2 Issue 24: IAE, Underflow in FilterDataAccess. Issue 26:UnsupportedOperationException when patching empty base revision. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 367
diff changeset
478 if (areTheSame(f, fileNode, nid1)) {
5e95b0da26f2 Issue 24: IAE, Underflow in FilterDataAccess. Issue 26:UnsupportedOperationException when patching empty base revision. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 367
diff changeset
479 inspector.clean(fname);
5e95b0da26f2 Issue 24: IAE, Underflow in FilterDataAccess. Issue 26:UnsupportedOperationException when patching empty base revision. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 367
diff changeset
480 } else {
5e95b0da26f2 Issue 24: IAE, Underflow in FilterDataAccess. Issue 26:UnsupportedOperationException when patching empty base revision. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 367
diff changeset
481 inspector.modified(fname);
5e95b0da26f2 Issue 24: IAE, Underflow in FilterDataAccess. Issue 26:UnsupportedOperationException when patching empty base revision. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 367
diff changeset
482 }
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 423
diff changeset
483 } catch (HgRuntimeException ex) {
490
b3c16d1aede0 Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 473
diff changeset
484 repo.getSessionContext().getLog().dump(getClass(), Warn, ex, null);
397
5e95b0da26f2 Issue 24: IAE, Underflow in FilterDataAccess. Issue 26:UnsupportedOperationException when patching empty base revision. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 367
diff changeset
485 inspector.invalid(fname, ex);
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
486 }
285
6dbbc53fc46d Use Path instead of plain String for manifest file names
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 284
diff changeset
487 baseRevNames.remove(fname); // consumed, processed, handled.
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 337
diff changeset
488 } else if (getDirstateImpl().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
489 // 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
490 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
491 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
492 }
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
493 // 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
494 }
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
495
608
e1b29756f901 Clean, organize and resolve some TODOs and FIXMEs: minor refactorings and comments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 537
diff changeset
496 // TODO [post-1.1] 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
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
497 // 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
498 // 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
499 // 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
500 // 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
501 // 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
502 }
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
503
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 423
diff changeset
504 private boolean areTheSame(FileInfo f, HgDataFile dataFile, Nodeid revision) throws HgInvalidFileException {
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
505 // 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
506 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
507 try {
367
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
508 int fileRevisionIndex = dataFile.getRevisionIndex(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
509 // 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
510 // WC doesn't have it anyway
367
2fadf8695f8a Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 366
diff changeset
511 dataFile.content(fileRevisionIndex, bac);
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
512 } 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
513 // 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
514 }
397
5e95b0da26f2 Issue 24: IAE, Underflow in FilterDataAccess. Issue 26:UnsupportedOperationException when patching empty base revision. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 367
diff changeset
515 return areTheSame(f, bac.toArray(), dataFile.getPath());
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
516 }
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
517
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
518 private boolean areTheSame(FileInfo f, final byte[] data, Path p) throws HgInvalidFileException {
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
519 ReadableByteChannel is = null;
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
520 class Check implements ByteChannel {
490
b3c16d1aede0 Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 473
diff changeset
521 final boolean debug = repo.getSessionContext().getLog().isDebug();
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
522 boolean sameSoFar = true;
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
523 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
524
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
525 public int write(ByteBuffer buffer) {
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
526 for (int i = buffer.remaining(); i > 0; i--, x++) {
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
527 if (x >= data.length /*file has been appended*/ || data[x] != buffer.get()) {
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
528 if (debug) {
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
529 byte[] xx = new byte[15];
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
530 if (buffer.position() > 5) {
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
531 buffer.position(buffer.position() - 5);
117
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
532 }
334
15e1961719f2 Investigate sporadic BufferUnderflowException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 323
diff changeset
533 buffer.get(xx, 0, min(xx.length, i-1 /*-1 for the one potentially read at buffer.get in if() */));
15e1961719f2 Investigate sporadic BufferUnderflowException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 323
diff changeset
534 String exp;
15e1961719f2 Investigate sporadic BufferUnderflowException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 323
diff changeset
535 if (x < data.length) {
15e1961719f2 Investigate sporadic BufferUnderflowException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 323
diff changeset
536 exp = new String(data, max(0, x - 4), min(data.length - x, 20));
15e1961719f2 Investigate sporadic BufferUnderflowException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 323
diff changeset
537 } else {
15e1961719f2 Investigate sporadic BufferUnderflowException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 323
diff changeset
538 int offset = max(0, x - 4);
15e1961719f2 Investigate sporadic BufferUnderflowException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 323
diff changeset
539 exp = new String(data, offset, min(data.length - offset, 20));
15e1961719f2 Investigate sporadic BufferUnderflowException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 323
diff changeset
540 }
490
b3c16d1aede0 Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 473
diff changeset
541 repo.getSessionContext().getLog().dump(getClass(), Debug, "expected >>%s<< but got >>%s<<", exp, new String(xx));
117
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
542 }
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
543 sameSoFar = false;
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
544 break;
219
d63583b47bfa ArrayIndexOutOfBoundsException when file appended. Erroneous 'areTheSame' when trailing were deleted.
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 218
diff changeset
545 }
117
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
546 }
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
547 buffer.position(buffer.limit()); // mark as read
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
548 return buffer.limit();
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
549 }
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
550
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
551 public boolean sameSoFar() {
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
552 return sameSoFar;
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
553 }
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
554 public boolean ultimatelyTheSame() {
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
555 return sameSoFar && x == data.length;
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
556 }
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
557 };
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
558 Check check = new Check();
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
559 try {
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
560 is = f.newInputChannel();
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
561 ByteBuffer fb = ByteBuffer.allocate(min(1 + data.length * 2 /*to fit couple of lines appended; never zero*/, 8192));
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
562 FilterByteChannel filters = new FilterByteChannel(check, repo.getFiltersFromWorkingDirToRepo(p));
356
91d75e1bac9f Consistent approach to deal with adaptable objects. Give adaptable precedence over instanceof to allow conditional response when classes do implement desired interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 355
diff changeset
563 Preview preview = Adaptable.Factory.getAdapter(filters, Preview.class, null);
355
f2c11fe7f3e9 Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
564 if (preview != null) {
f2c11fe7f3e9 Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
565 while (is.read(fb) != -1) {
f2c11fe7f3e9 Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
566 fb.flip();
f2c11fe7f3e9 Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
567 preview.preview(fb);
f2c11fe7f3e9 Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
568 fb.clear();
f2c11fe7f3e9 Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
569 }
f2c11fe7f3e9 Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
570 // reset channel to read once again
f2c11fe7f3e9 Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
571 try {
f2c11fe7f3e9 Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
572 is.close();
f2c11fe7f3e9 Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
573 } catch (IOException ex) {
490
b3c16d1aede0 Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 473
diff changeset
574 repo.getSessionContext().getLog().dump(getClass(), Info, ex, null);
355
f2c11fe7f3e9 Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
575 }
f2c11fe7f3e9 Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
576 is = f.newInputChannel();
f2c11fe7f3e9 Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
577 fb.clear();
f2c11fe7f3e9 Newline filter shall respect whole stream when deciding whether to process line terminators, hence added stream preview functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 354
diff changeset
578 }
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
579 while (is.read(fb) != -1 && check.sameSoFar()) {
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
580 fb.flip();
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
581 filters.write(fb);
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
582 fb.compact();
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
583 }
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
584 return check.ultimatelyTheSame();
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
585 } catch (CancelledException ex) {
490
b3c16d1aede0 Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 473
diff changeset
586 repo.getSessionContext().getLog().dump(getClass(), Warn, ex, "Unexpected cancellation");
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
587 return check.ultimatelyTheSame();
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
588 } catch (IOException ex) {
397
5e95b0da26f2 Issue 24: IAE, Underflow in FilterDataAccess. Issue 26:UnsupportedOperationException when patching empty base revision. Tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 367
diff changeset
589 throw new HgInvalidFileException("File comparison failed", ex).setFileName(p);
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
590 } finally {
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
591 if (is != null) {
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
592 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
593 is.close();
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 294
diff changeset
594 } catch (IOException ex) {
490
b3c16d1aede0 Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 473
diff changeset
595 repo.getSessionContext().getLog().dump(getClass(), Info, ex, null);
117
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
596 }
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
597 }
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
598 }
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
599 }
6c0be854d149 Enable filters for status operation (ToRepo case)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
600
413
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
601 /**
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
602 * @return <code>true</code> if flags are the same
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
603 */
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
604 private boolean checkFlagsEqual(FileInfo f, HgManifest.Flags originalManifestFlags) {
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
605 boolean same = true;
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
606 if (repoWalker.supportsLinkFlag()) {
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
607 if (originalManifestFlags == HgManifest.Flags.Link) {
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
608 return f.isSymlink();
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
609 }
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
610 // original flag is not link, hence flags are the same if file is not link, too.
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
611 same = !f.isSymlink();
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
612 } // otherwise treat flags the same
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
613 if (repoWalker.supportsExecFlag()) {
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
614 if (originalManifestFlags == HgManifest.Flags.Exec) {
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
615 return f.isExecutable();
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
616 }
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
617 // original flag has no executable attribute, hence file shall not be executable, too
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
618 same = same || !f.isExecutable();
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
619 }
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
620 return same;
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
621 }
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
622
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
623 private boolean checkFlagsEqual(FileInfo f, int dirstateFileMode) {
608
e1b29756f901 Clean, organize and resolve some TODOs and FIXMEs: minor refactorings and comments
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 537
diff changeset
624 return checkFlagsEqual(f, HgManifest.Flags.parse(dirstateFileMode));
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
625 }
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
626
229
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
627 /**
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
628 * 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
629 * 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
630 *
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
631 * @param hgRepo repository
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
632 * @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
633 *
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
634 * @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
635 */
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
636 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
637 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
638 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
639 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
640 if (p.isDirectory()) {
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
641 d.add(p);
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
642 } else {
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
643 f.add(p);
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
644 }
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
645 }
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
646 // 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
647 if (d.isEmpty()) {
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
648 final Path[] files = f.toArray(new Path[f.size()]);
490
b3c16d1aede0 Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 473
diff changeset
649 FileIterator fi = new FileListIterator(hgRepo.getSessionContext(), 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
650 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
651 }
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
652 //
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
653
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
654 //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
655 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
656 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
657 }
229
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
658
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
659 /**
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
660 * 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
661 * 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
662 * (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
663 * 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
664 *
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
665 * @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
666 */
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
667 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
668 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
669 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
670 // 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
671 // 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
672 // 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
673 // 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
674 // 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
675 // method above/
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
676 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
677 }
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
678
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
679 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
680 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
681 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
682 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
683 private RegularFileInfo nextFile;
413
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
684 private final boolean execCap, linkCap;
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 423
diff changeset
685 private final SessionContext sessionContext;
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
686
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 423
diff changeset
687 public FileListIterator(SessionContext ctx, File startDir, Path... files) {
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 423
diff changeset
688 sessionContext = ctx;
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
689 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
690 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
691 reset();
413
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
692 execCap = Internals.checkSupportsExecutables(startDir);
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
693 linkCap = Internals.checkSupportsSymlinks(startDir);
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
694 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
695
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
696 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
697 index = -1;
425
48f993aa2f41 FIXMEs: exceptions, javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 423
diff changeset
698 nextFile = new RegularFileInfo(sessionContext, execCap, linkCap);
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
699 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
700
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
701 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
702 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
703 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
704
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
705 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
706 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
707 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
708 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
709 }
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
710 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
711 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
712
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
713 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
714 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
715 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
716
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
717 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
718 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
719 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
720
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
721 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
722 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
723 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
724 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
725 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
726 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
727 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
728 }
413
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
729
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
730 public boolean supportsExecFlag() {
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
731 return execCap;
413
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
732 }
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
733
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
734 public boolean supportsLinkFlag() {
423
9c9c442b5f2e Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
735 return linkCap;
413
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
736 }
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
737 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
738
229
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
739 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
740 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
741 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
742 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
743
229
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
744 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
745 assert fileWalker != null;
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
746 assert filterMatcher != null;
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
747 filter = filterMatcher;
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
748 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
749 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
750
350
33eaed1ad130 Allow FileIterator report any errors from the underlaying file system up to the client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
751 public void reset() throws IOException {
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
752 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
753 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
754
350
33eaed1ad130 Allow FileIterator report any errors from the underlaying file system up to the client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
755 public boolean hasNext() throws IOException {
229
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
756 while (walker.hasNext()) {
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
757 walker.next();
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
758 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
759 didNext = true;
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
760 return true;
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
761 }
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
762 }
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
763 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
764 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
765
350
33eaed1ad130 Allow FileIterator report any errors from the underlaying file system up to the client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
766 public void next() throws IOException {
229
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
767 if (didNext) {
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
768 didNext = false;
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
769 } else {
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
770 if (!hasNext()) {
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
771 throw new NoSuchElementException();
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
772 }
1ec6b327a6ac Scope for status reworked: explicit files or a general matcher
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 226
diff changeset
773 }
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
774 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
775
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
776 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
777 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
778 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
779
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
780 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
781 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
782 }
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
783
26ad7827a62d Support status query for a single file or a subdirectory of a repository
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 219
diff changeset
784 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
785 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
786 }
413
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
787
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
788 public boolean supportsExecFlag() {
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
789 return walker.supportsExecFlag();
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
790 }
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
791
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
792 public boolean supportsLinkFlag() {
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
793 return walker.supportsLinkFlag();
7f27122011c3 Support and respect for symbolic links and executable flag, with /bin/ls backed implementation to discover these
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 405
diff changeset
794 }
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
795 }
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
796 }