Mercurial > jhg
comparison src/org/tmatesoft/hg/repo/HgStatusCollector.java @ 455:281cfb60e2ef smartgit3
Added option to turn detection of copied files off during status operation
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 18 Jun 2012 20:26:59 +0200 |
parents | 2fadf8695f8a |
children | 7bcfbc255f48 |
comparison
equal
deleted
inserted
replaced
451:39fe00407937 | 455:281cfb60e2ef |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2011 TMate Software Ltd | 2 * Copyright (c) 2011-2012 TMate Software Ltd |
3 * | 3 * |
4 * This program is free software; you can redistribute it and/or modify | 4 * This program is free software; you can redistribute it and/or modify |
5 * it under the terms of the GNU General Public License as published by | 5 * it under the terms of the GNU General Public License as published by |
6 * the Free Software Foundation; version 2 of the License. | 6 * the Free Software Foundation; version 2 of the License. |
7 * | 7 * |
58 private PathPool pathPool; | 58 private PathPool pathPool; |
59 private final Pool<Nodeid> cacheNodes; | 59 private final Pool<Nodeid> cacheNodes; |
60 private final Pool<Path> cacheFilenames; | 60 private final Pool<Path> cacheFilenames; |
61 private final ManifestRevision emptyFakeState; | 61 private final ManifestRevision emptyFakeState; |
62 private Path.Matcher scope = new Path.Matcher.Any(); | 62 private Path.Matcher scope = new Path.Matcher.Any(); |
63 // @see #detectCopies() | |
64 private boolean detectCopies = true; | |
63 | 65 |
64 | 66 |
65 public HgStatusCollector(HgRepository hgRepo) { | 67 public HgStatusCollector(HgRepository hgRepo) { |
66 this.repo = hgRepo; | 68 this.repo = hgRepo; |
67 cache = new IntMap<ManifestRevision>(cacheMaxSize); | 69 cache = new IntMap<ManifestRevision>(cacheMaxSize); |
182 */ | 184 */ |
183 public void setScope(Path.Matcher scopeMatcher) { | 185 public void setScope(Path.Matcher scopeMatcher) { |
184 // do not assign null, ever | 186 // do not assign null, ever |
185 scope = scopeMatcher == null ? new Path.Matcher.Any() : scopeMatcher; | 187 scope = scopeMatcher == null ? new Path.Matcher.Any() : scopeMatcher; |
186 } | 188 } |
189 | |
190 /** | |
191 * Select whether Collector shall tell "added-new" from "added-by-copy/rename" files. | |
192 * This is analogous to '-C' switch of 'hg status' command. | |
193 * | |
194 * <p>With copy detection turned off, files continue be reported as plain 'added' files. | |
195 * | |
196 * <p>By default, copy detection is <em>on</em>, as it's reasonably cheap. However, | |
197 * in certain scenarios it may be reasonable to turn it off, for example when it's a merge | |
198 * of two very different branches and there are a lot of files added/moved. | |
199 * | |
200 * Another legitimate reason to set detection to off if you're lazy to | |
201 * implement {@link HgStatusInspector#copied(Path, Path)} ;) | |
202 * | |
203 * @param detect <code>true</code> if copies detection is desirable | |
204 */ | |
205 public void detectCopies(boolean detect) { | |
206 // cpython, revision:72161, p1:72159, p2:72160 | |
207 // p2 comes from another branch with 321 file added (looks like copied/moved, however, the isCopy | |
208 // record present only for couple of them). With 2,5 ms per isCopy() operation, almost a second | |
209 // is spent detecting origins (according to Marc, of little use in this scenario, as it's second parent | |
210 // in the merge) - in fact, most of the time of the status operation | |
211 detectCopies = detect; | |
212 } | |
187 | 213 |
188 // hg status --change <rev> | 214 // hg status --change <rev> |
189 public void change(int rev, HgStatusInspector inspector) throws /*FIXME HInvalidRevisionException,*/ HgInvalidControlFileException { | 215 public void change(int rev, HgStatusInspector inspector) throws /*FIXME HInvalidRevisionException,*/ HgInvalidControlFileException { |
190 int[] parents = new int[2]; | 216 int[] parents = new int[2]; |
191 repo.getChangelog().parents(rev, parents, null, null); | 217 repo.getChangelog().parents(rev, parents, null, null); |
262 inspector.modified(r2fname); | 288 inspector.modified(r2fname); |
263 } | 289 } |
264 } else { | 290 } else { |
265 try { | 291 try { |
266 Path copyTarget = r2fname; | 292 Path copyTarget = r2fname; |
267 Path copyOrigin = getOriginIfCopy(repo, copyTarget, r1Files, rev1); | 293 Path copyOrigin = detectCopies ? getOriginIfCopy(repo, copyTarget, r1Files, rev1) : null; |
268 if (copyOrigin != null) { | 294 if (copyOrigin != null) { |
269 inspector.copied(getPathPool().path(copyOrigin) /*pipe through pool, just in case*/, copyTarget); | 295 inspector.copied(getPathPool().path(copyOrigin) /*pipe through pool, just in case*/, copyTarget); |
270 } else { | 296 } else { |
271 inspector.added(copyTarget); | 297 inspector.added(copyTarget); |
272 } | 298 } |