annotate src/org/tmatesoft/hg/core/HgLogCommand.java @ 526:2f9ed6bcefa2

Initial support for Revert command with accompanying minor refactoring
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 15 Jan 2013 17:07:19 +0100
parents 2103388d4010
children f7fbf48b9383
rev   line source
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
427
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
2 s * Copyright (c) 2011-2012 TMate Software Ltd
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
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
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.core;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
518
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
19 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 70
diff changeset
20 import static org.tmatesoft.hg.repo.HgRepository.TIP;
456
909306e412e2 Refactor LogFacility and SessionContext, better API for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 432
diff changeset
21 import static org.tmatesoft.hg.util.LogFacility.Severity.Error;
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
23 import java.util.ArrayList;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
24 import java.util.Arrays;
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import java.util.Calendar;
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
26 import java.util.Collection;
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 import java.util.Collections;
511
122e0600799f Respect multiple joins/forks in a history of a single file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 510
diff changeset
28 import java.util.Comparator;
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 import java.util.ConcurrentModificationException;
510
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
30 import java.util.Iterator;
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 import java.util.LinkedList;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 import java.util.List;
510
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
33 import java.util.ListIterator;
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 import java.util.Set;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 import java.util.TreeSet;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36
520
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
37 import org.tmatesoft.hg.internal.AdapterPlug;
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
38 import org.tmatesoft.hg.internal.BatchRangeHelper;
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
39 import org.tmatesoft.hg.internal.IntMap;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
40 import org.tmatesoft.hg.internal.IntVector;
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 522
diff changeset
41 import org.tmatesoft.hg.internal.Internals;
518
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
42 import org.tmatesoft.hg.internal.Lifecycle;
520
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
43 import org.tmatesoft.hg.internal.LifecycleProxy;
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 205
diff changeset
44 import org.tmatesoft.hg.repo.HgChangelog;
154
ba2bf656f00f Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
45 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset;
80
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
46 import org.tmatesoft.hg.repo.HgDataFile;
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: 419
diff changeset
47 import org.tmatesoft.hg.repo.HgInvalidControlFileException;
457
d78cb5ca3053 Get rid of ambiguity in method name
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 456
diff changeset
48 import org.tmatesoft.hg.repo.HgInvalidRevisionException;
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: 419
diff changeset
49 import org.tmatesoft.hg.repo.HgInvalidStateException;
456
909306e412e2 Refactor LogFacility and SessionContext, better API for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 432
diff changeset
50 import org.tmatesoft.hg.repo.HgParentChildMap;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 70
diff changeset
51 import org.tmatesoft.hg.repo.HgRepository;
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: 419
diff changeset
52 import org.tmatesoft.hg.repo.HgRuntimeException;
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
53 import org.tmatesoft.hg.repo.HgStatusCollector;
514
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
54 import org.tmatesoft.hg.util.Adaptable;
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
55 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: 154
diff changeset
56 import org.tmatesoft.hg.util.CancelledException;
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
57 import org.tmatesoft.hg.util.Pair;
133
4a948ec83980 core.Path to util.Path as it's not Hg repo dependant
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 131
diff changeset
58 import org.tmatesoft.hg.util.Path;
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 205
diff changeset
59 import org.tmatesoft.hg.util.ProgressSupport;
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
60
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
61
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
62 /**
131
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 129
diff changeset
63 * Access to changelog, 'hg log' command counterpart.
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 129
diff changeset
64 *
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 * <pre>
131
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 129
diff changeset
66 * Usage:
70
993f6f8e1314 Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 64
diff changeset
67 * new LogCommand().limit(20).branch("maintenance-2.1").user("me").execute(new MyHandler());
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 * </pre>
131
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 129
diff changeset
69 * Not thread-safe (each thread has to use own {@link HgLogCommand} instance).
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
70 *
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
71 * @author Artem Tikhomirov
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
72 * @author TMate Software Ltd.
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
73 */
518
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
74 public class HgLogCommand extends HgAbstractCommand<HgLogCommand> {
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
75
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
76 private final HgRepository repo;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
77 private Set<String> users;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
78 private Set<String> branches;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
79 private int limit = 0, count = 0;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
80 private int startRev = 0, endRev = TIP;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 private Calendar date;
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
82 private Path file;
514
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
83 /*
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
84 * Whether to iterate file origins, if any.
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
85 * Makes sense only when file != null
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
86 */
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
87 private boolean followRenames;
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
88 /*
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
89 * Whether to track history of the selected file version (based on file revision
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
90 * in working dir parent), follow ancestors only.
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
91 * Note, 'hg log --follow' combines both #followHistory and #followAncestry
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
92 */
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
93 private boolean followAncestry;
522
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
94
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
95 private HgIterateDirection iterateDirection = HgIterateDirection.OldToNew;
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
96
193
37f3d4a596e4 Use common low to hi-level changeset api transformer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
97 private ChangesetTransformer csetTransform;
432
1fc0da631200 Revlog.ParentWalker helper class got promoted as TLC, renamed to HgParentChildMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
98 private HgParentChildMap<HgChangelog> parentHelper;
80
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
99
131
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 129
diff changeset
100 public HgLogCommand(HgRepository hgRepo) {
107
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
101 repo = hgRepo;
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
102 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
103
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
104 /**
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 142
diff changeset
105 * Limit search to specified user. Multiple user names may be specified. Once set, user names can't be
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 142
diff changeset
106 * cleared, use new command instance in such cases.
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
107 * @param user - full or partial name of the user, case-insensitive, non-null.
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
108 * @return <code>this</code> instance for convenience
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 142
diff changeset
109 * @throws IllegalArgumentException when argument is null
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
110 */
131
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 129
diff changeset
111 public HgLogCommand user(String user) {
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
112 if (user == null) {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
113 throw new IllegalArgumentException();
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
114 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
115 if (users == null) {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116 users = new TreeSet<String>();
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
117 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
118 users.add(user.toLowerCase());
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
119 return this;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
120 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
121
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
122 /**
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
123 * Limit search to specified branch. Multiple branch specification possible (changeset from any of these
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 142
diff changeset
124 * would be included in result). If unspecified, all branches are considered. There's no way to clean branch selection
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 142
diff changeset
125 * once set, create fresh new command instead.
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
126 * @param branch - branch name, case-sensitive, non-null.
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
127 * @return <code>this</code> instance for convenience
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 142
diff changeset
128 * @throws IllegalArgumentException when branch argument is null
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
129 */
131
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 129
diff changeset
130 public HgLogCommand branch(String branch) {
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
131 if (branch == null) {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
132 throw new IllegalArgumentException();
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
133 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
134 if (branches == null) {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
135 branches = new TreeSet<String>();
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
136 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
137 branches.add(branch);
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
138 return this;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
139 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
140
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
141 // limit search to specific date
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
142 // multiple?
131
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 129
diff changeset
143 public HgLogCommand date(Calendar date) {
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
144 this.date = date;
418
528b6780a8bd A bit of FIXME cleanup (mostly degraded to TODO post 1.0), comments and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 415
diff changeset
145 // TODO post-1.0 implement
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
146 // isSet(field) - false => don't use in detection of 'same date'
526
2f9ed6bcefa2 Initial support for Revert command with accompanying minor refactoring
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 522
diff changeset
147 throw Internals.notImplemented();
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
148 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
149
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
150 /**
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
151 *
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
152 * @param num - number of changeset to produce. Pass 0 to clear the limit.
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
153 * @return <code>this</code> instance for convenience
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
154 */
131
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 129
diff changeset
155 public HgLogCommand limit(int num) {
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
156 limit = num;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
157 return this;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
158 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
159
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
160 /**
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
161 * Limit to specified subset of Changelog, [min(rev1,rev2), max(rev1,rev2)], inclusive.
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
162 * Revision may be specified with {@link HgRepository#TIP}
427
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
163 *
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
164 * @param rev1 - local index of start changeset revision
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
165 * @param rev2 - index of end changeset revision
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
166 * @return <code>this</code> instance for convenience
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
167 */
131
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 129
diff changeset
168 public HgLogCommand range(int rev1, int rev2) {
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
169 if (rev1 != TIP && rev2 != TIP) {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
170 startRev = rev2 < rev1 ? rev2 : rev1;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
171 endRev = startRev == rev2 ? rev1 : rev2;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
172 } else if (rev1 == TIP && rev2 != TIP) {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
173 startRev = rev2;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
174 endRev = rev1;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
175 } else {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
176 startRev = rev1;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
177 endRev = rev2;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
178 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
179 return this;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
180 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
181
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
182 /**
253
1874d11054e5 HgLogCommand.changeset(Nodeid) to ease command configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 250
diff changeset
183 * Select specific changeset
1874d11054e5 HgLogCommand.changeset(Nodeid) to ease command configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 250
diff changeset
184 *
1874d11054e5 HgLogCommand.changeset(Nodeid) to ease command configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 250
diff changeset
185 * @param nid changeset revision
1874d11054e5 HgLogCommand.changeset(Nodeid) to ease command configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 250
diff changeset
186 * @return <code>this</code> for convenience
427
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
187 * @throws HgBadArgumentException if failed to find supplied changeset revision
253
1874d11054e5 HgLogCommand.changeset(Nodeid) to ease command configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 250
diff changeset
188 */
427
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
189 public HgLogCommand changeset(Nodeid nid) throws HgBadArgumentException {
253
1874d11054e5 HgLogCommand.changeset(Nodeid) to ease command configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 250
diff changeset
190 // XXX perhaps, shall support multiple (...) arguments and extend #execute to handle not only range, but also set of revisions.
427
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
191 try {
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
192 final int csetRevIndex = repo.getChangelog().getRevisionIndex(nid);
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
193 return range(csetRevIndex, csetRevIndex);
457
d78cb5ca3053 Get rid of ambiguity in method name
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 456
diff changeset
194 } catch (HgInvalidRevisionException ex) {
427
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
195 throw new HgBadArgumentException("Can't find revision", ex).setRevision(nid);
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
196 }
253
1874d11054e5 HgLogCommand.changeset(Nodeid) to ease command configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 250
diff changeset
197 }
1874d11054e5 HgLogCommand.changeset(Nodeid) to ease command configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 250
diff changeset
198
1874d11054e5 HgLogCommand.changeset(Nodeid) to ease command configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 250
diff changeset
199 /**
516
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
200 * Visit history of a given file only. Note, unlike native <code>hg log</code> command argument <code>--follow</code>, this method doesn't
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
201 * follow file ancestry, but reports complete file history (with <code>followCopyRenames == true</code>, for each
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
202 * name of the file known in sequence). To achieve output similar to that of <code>hg log --follow filePath</code>, use
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
203 * {@link #file(Path, boolean, boolean) file(filePath, true, true)} alternative.
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
204 *
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
205 * @param filePath path relative to repository root. Pass <code>null</code> to reset.
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
206 * @param followCopyRename true to report changesets of the original file(-s), if copy/rename ever occured to the file.
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
207 * @return <code>this</code> for convenience
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
208 */
516
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
209 public HgLogCommand file(Path filePath, boolean followCopyRename) {
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
210 return file(filePath, followCopyRename, false);
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
211 }
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
212
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
213 /**
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
214 * Full control over file history iteration.
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
215 *
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
216 * @param filePath path relative to repository root. Pass <code>null</code> to reset.
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
217 * @param followCopyRename true to report changesets of the original file(-s), if copy/rename ever occured to the file.
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
218 * @param followFileAncestry true to follow file history starting from revision at working copy parent. Note, only revisions
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
219 * accessible (i.e. on direct parent line) from the selected one will be reported. This is how <code>hg log --follow filePath</code>
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
220 * behaves, with the difference that this method allows separate control whether to follow renames or not.
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
221 *
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
222 * @return <code>this</code> for convenience
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
223 */
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
224 public HgLogCommand file(Path filePath, boolean followCopyRename, boolean followFileAncestry) {
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
225 file = filePath;
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
226 followRenames = followCopyRename;
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
227 followAncestry = followFileAncestry;
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
228 return this;
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
229 }
142
37a34044e6bd More reasonable use of path normalizer and path.source
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
230
37a34044e6bd More reasonable use of path normalizer and path.source
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
231 /**
516
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
232 * Handy analog to {@link #file(Path, boolean)} when clients' paths come from filesystem and need conversion to repository's
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
233 * @return <code>this</code> for convenience
142
37a34044e6bd More reasonable use of path normalizer and path.source
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
234 */
37a34044e6bd More reasonable use of path normalizer and path.source
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
235 public HgLogCommand file(String file, boolean followCopyRename) {
37a34044e6bd More reasonable use of path normalizer and path.source
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
236 return file(Path.create(repo.getToRepoPathHelper().rewrite(file)), followCopyRename);
37a34044e6bd More reasonable use of path normalizer and path.source
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
237 }
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
238
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
239 /**
516
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
240 * Handy analog to {@link #file(Path, boolean, boolean)} when clients' paths come from filesystem and need conversion to repository's
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
241 * @return <code>this</code> for convenience
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
242 */
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
243 public HgLogCommand file(String file, boolean followCopyRename, boolean followFileAncestry) {
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
244 return file(Path.create(repo.getToRepoPathHelper().rewrite(file)), followCopyRename, followFileAncestry);
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
245 }
522
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
246
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
247 /**
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
248 * Specifies order for changesets reported through #execute(...) methods.
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
249 * By default, command reports changeset in their natural repository order, older first,
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
250 * newer last (i.e. {@link HgIterateDirection#OldToNew}
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
251 *
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
252 * @param order {@link HgIterateDirection#NewToOld} to get newer revisions first
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
253 * @return <code>this</code> for convenience
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
254 */
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
255 public HgLogCommand order(HgIterateDirection order) {
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
256 iterateDirection = order;
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
257 return this;
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
258 }
516
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
259
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
260 /**
419
7f136a3fa671 Clean javadoc to fix obvious warnings
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 418
diff changeset
261 * Similar to {@link #execute(HgChangesetHandler)}, collects and return result as a list.
427
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
262 *
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
263 * @see #execute(HgChangesetHandler)
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
264 * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
265 */
396
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 383
diff changeset
266 public List<HgChangeset> execute() throws HgException {
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
267 CollectHandler collector = new CollectHandler();
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 205
diff changeset
268 try {
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 205
diff changeset
269 execute(collector);
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: 419
diff changeset
270 } catch (HgCallbackTargetException 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: 419
diff changeset
271 // see below for CanceledException
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: 419
diff changeset
272 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: 419
diff changeset
273 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: 419
diff changeset
274 throw t;
396
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 383
diff changeset
275 } catch (CancelledException ex) {
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 205
diff changeset
276 // can't happen as long as our CollectHandler doesn't throw any exception
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: 419
diff changeset
277 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: 419
diff changeset
278 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: 419
diff changeset
279 throw t;
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 205
diff changeset
280 }
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
281 return collector.getChanges();
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
282 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
283
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
284 /**
402
1fcc7f7b6d65 FIXMEs/javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
285 * Iterate over range of changesets configured in the command.
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
286 *
205
ffc5f6d59f7e HgLogCommand.Handler is used in few places, pull up to top-level class, HgChangesetHandler
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 195
diff changeset
287 * @param handler callback to process changesets.
427
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
288 * @throws HgCallbackTargetException propagated exception from the handler
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
289 * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state
380
9517df1ef7ec Comments/javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 370
diff changeset
290 * @throws CancelledException if execution of the command was cancelled
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
291 * @throws IllegalArgumentException when inspector argument is null
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
292 * @throws ConcurrentModificationException if this log command instance is already running
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
293 */
370
a2341e761609 Let callback implementations deliver errors (e,g. own exceptions) to client code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 368
diff changeset
294 public void execute(HgChangesetHandler handler) throws HgCallbackTargetException, HgException, CancelledException {
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
295 if (handler == null) {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
296 throw new IllegalArgumentException();
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
297 }
193
37f3d4a596e4 Use common low to hi-level changeset api transformer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
298 if (csetTransform != null) {
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
299 throw new ConcurrentModificationException();
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
300 }
518
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
301 final int lastCset = endRev == TIP ? repo.getChangelog().getLastRevision() : endRev;
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
302 // XXX pretty much like HgInternals.checkRevlogRange
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
303 if (lastCset < 0 || lastCset > repo.getChangelog().getLastRevision()) {
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
304 throw new HgBadArgumentException(String.format("Bad value %d for end revision", endRev), null);
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
305 }
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
306 if (startRev < 0 || startRev > lastCset) {
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
307 throw new HgBadArgumentException(String.format("Bad value %d for start revision for range [%1$d..%d]", startRev, lastCset), null);
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
308 }
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 205
diff changeset
309 final ProgressSupport progressHelper = getProgressSupport(handler);
520
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
310 final int BATCH_SIZE = 100;
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
311 try {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
312 count = 0;
432
1fc0da631200 Revlog.ParentWalker helper class got promoted as TLC, renamed to HgParentChildMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
313 HgParentChildMap<HgChangelog> pw = getParentHelper(file == null); // leave it uninitialized unless we iterate whole repo
193
37f3d4a596e4 Use common low to hi-level changeset api transformer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
314 // ChangesetTransfrom creates a blank PathPool, and #file(String, boolean) above
37f3d4a596e4 Use common low to hi-level changeset api transformer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
315 // may utilize it as well. CommandContext? How about StatusCollector there as well?
322
d68dcb3b5f49 Propagate command's CancelSupport to low-level API. CancelSupport from context got priority over one from command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 316
diff changeset
316 csetTransform = new ChangesetTransformer(repo, handler, pw, progressHelper, getCancelSupport(handler, true));
520
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
317 // FilteringInspector is responsible to check command arguments: users, branches, limit, etc.
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
318 // prior to passing cset to next Inspector, which is either (a) collector to reverse cset order, then invokes
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
319 // transformer from (b), below, with alternative cset order or (b) transformer to hi-level csets.
518
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
320 FilteringInspector filterInsp = new FilteringInspector();
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
321 filterInsp.changesets(startRev, lastCset);
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
322 if (file == null) {
520
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
323 progressHelper.start(lastCset - startRev + 1);
522
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
324 if (iterateDirection == HgIterateDirection.OldToNew) {
520
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
325 filterInsp.delegateTo(csetTransform);
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
326 repo.getChangelog().range(startRev, lastCset, filterInsp);
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
327 csetTransform.checkFailure();
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
328 } else {
522
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
329 assert iterateDirection == HgIterateDirection.NewToOld;
520
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
330 BatchRangeHelper brh = new BatchRangeHelper(startRev, lastCset, BATCH_SIZE, true);
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
331 BatchChangesetInspector batchInspector = new BatchChangesetInspector(Math.min(lastCset-startRev+1, BATCH_SIZE));
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
332 filterInsp.delegateTo(batchInspector);
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
333 while (brh.hasNext()) {
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
334 brh.next();
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
335 repo.getChangelog().range(brh.start(), brh.end(), filterInsp);
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
336 for (BatchChangesetInspector.BatchRecord br : batchInspector.iterate(true)) {
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
337 csetTransform.next(br.csetIndex, br.csetRevision, br.cset);
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
338 csetTransform.checkFailure();
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
339 }
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
340 batchInspector.reset();
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
341 }
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
342 }
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
343 } else {
520
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
344 filterInsp.delegateTo(csetTransform);
514
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
345 final HgFileRenameHandlerMixin withCopyHandler = Adaptable.Factory.getAdapter(handler, HgFileRenameHandlerMixin.class, null);
518
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
346 List<Pair<HgDataFile, Nodeid>> fileRenames = buildFileRenamesQueue();
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
347 progressHelper.start(-1/*XXX enum const, or a dedicated method startUnspecified(). How about startAtLeast(int)?*/);
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
348
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
349 for (int nameIndex = 0, fileRenamesSize = fileRenames.size(); nameIndex < fileRenamesSize; nameIndex++) {
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
350 Pair<HgDataFile, Nodeid> curRename = fileRenames.get(nameIndex);
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
351 HgDataFile fileNode = curRename.first();
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
352 if (followAncestry) {
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
353 TreeBuildInspector treeBuilder = new TreeBuildInspector(followAncestry);
520
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
354 @SuppressWarnings("unused")
518
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
355 List<HistoryNode> fileAncestry = treeBuilder.go(fileNode, curRename.second());
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
356 int[] commitRevisions = narrowChangesetRange(treeBuilder.getCommitRevisions(), startRev, lastCset);
522
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
357 if (iterateDirection == HgIterateDirection.OldToNew) {
518
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
358 repo.getChangelog().range(filterInsp, commitRevisions);
520
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
359 csetTransform.checkFailure();
518
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
360 } else {
522
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
361 assert iterateDirection == HgIterateDirection.NewToOld;
518
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
362 // visit one by one in the opposite direction
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
363 for (int i = commitRevisions.length-1; i >= 0; i--) {
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
364 int csetWithFileChange = commitRevisions[i];
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
365 repo.getChangelog().range(csetWithFileChange, csetWithFileChange, filterInsp);
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
366 }
126
b92a638764be Dispatch chnagesets even if Handler is not FileHistoryHandler
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 107
diff changeset
367 }
518
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
368 } else {
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
369 // report complete file history (XXX may narrow range with [startRev, endRev], but need to go from file rev to link rev)
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
370 int fileStartRev = 0; //fileNode.getChangesetRevisionIndex(0) >= startRev
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
371 int fileEndRev = fileNode.getLastRevision();
522
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
372 if (iterateDirection == HgIterateDirection.OldToNew) {
520
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
373 fileNode.history(fileStartRev, fileEndRev, filterInsp);
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
374 csetTransform.checkFailure();
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
375 } else {
522
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
376 assert iterateDirection == HgIterateDirection.NewToOld;
520
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
377 BatchRangeHelper brh = new BatchRangeHelper(fileStartRev, fileEndRev, BATCH_SIZE, true);
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
378 BatchChangesetInspector batchInspector = new BatchChangesetInspector(Math.min(fileEndRev-fileStartRev+1, BATCH_SIZE));
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
379 filterInsp.delegateTo(batchInspector);
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
380 while (brh.hasNext()) {
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
381 brh.next();
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
382 fileNode.history(brh.start(), brh.end(), filterInsp);
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
383 for (BatchChangesetInspector.BatchRecord br : batchInspector.iterate(true /*iterateDirection == IterateDirection.FromNewToOld*/)) {
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
384 csetTransform.next(br.csetIndex, br.csetRevision, br.cset);
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
385 csetTransform.checkFailure();
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
386 }
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
387 batchInspector.reset();
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
388 }
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
389 }
518
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
390 }
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
391 if (followRenames && withCopyHandler != null && nameIndex + 1 < fileRenamesSize) {
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
392 Pair<HgDataFile, Nodeid> nextRename = fileRenames.get(nameIndex+1);
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
393 HgFileRevision src, dst;
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
394 // A -> B
522
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
395 if (iterateDirection == HgIterateDirection.OldToNew) {
518
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
396 // curRename: A, nextRename: B
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
397 src = new HgFileRevision(fileNode, curRename.second(), null);
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
398 dst = new HgFileRevision(nextRename.first(), nextRename.first().getRevision(0), src.getPath());
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
399 } else {
522
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
400 assert iterateDirection == HgIterateDirection.NewToOld;
518
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
401 // curRename: B, nextRename: A
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
402 src = new HgFileRevision(nextRename.first(), nextRename.second(), null);
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
403 dst = new HgFileRevision(fileNode, fileNode.getRevision(0), src.getPath());
80
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
404 }
518
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
405 withCopyHandler.copy(src, dst);
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
406 }
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
407 } // for renames
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
408 } // file != null
427
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
409 } catch (HgRuntimeException ex) {
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
410 throw new HgLibraryFailureException(ex);
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
411 } finally {
193
37f3d4a596e4 Use common low to hi-level changeset api transformer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
412 csetTransform = null;
215
41a778e3fd31 Issue 5: Facilities for progress and cancellation. More specific exceptions. Exceptions from callbacks as RuntimeException
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 205
diff changeset
413 progressHelper.done();
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
414 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
415 }
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
416
520
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
417 private static class BatchChangesetInspector extends AdapterPlug implements HgChangelog.Inspector {
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
418 private static class BatchRecord {
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
419 public final int csetIndex;
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
420 public final Nodeid csetRevision;
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
421 public final RawChangeset cset;
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
422
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
423 public BatchRecord(int index, Nodeid nodeid, RawChangeset changeset) {
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
424 csetIndex = index;
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
425 csetRevision = nodeid;
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
426 cset = changeset;
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
427 }
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
428 }
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
429 private final ArrayList<BatchRecord> batch;
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
430
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
431 public BatchChangesetInspector(int batchSizeHint) {
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
432 batch = new ArrayList<BatchRecord>(batchSizeHint);
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
433 }
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
434
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
435 public BatchChangesetInspector reset() {
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
436 batch.clear();
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
437 return this;
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
438 }
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
439
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
440 public void next(int revisionIndex, Nodeid nodeid, RawChangeset cset) {
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
441 batch.add(new BatchRecord(revisionIndex, nodeid, cset.clone()));
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
442 }
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
443
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
444 public Iterable<BatchRecord> iterate(final boolean reverse) {
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
445 return new Iterable<BatchRecord>() {
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
446
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
447 public Iterator<BatchRecord> iterator() {
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
448 return reverse ? new ReverseIterator<BatchRecord>(batch) : batch.iterator();
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
449 }
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
450 };
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
451 }
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
452
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
453 // alternative would be dispatch(HgChangelog.Inspector) and dispatchReverse()
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
454 // methods, but progress and cancellation might get messy then
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
455 }
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
456
518
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
457 // public static void main(String[] args) {
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
458 // int[] r = new int[] {17, 19, 21, 23, 25, 29};
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
459 // System.out.println(Arrays.toString(narrowChangesetRange(r, 0, 45)));
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
460 // System.out.println(Arrays.toString(narrowChangesetRange(r, 0, 25)));
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
461 // System.out.println(Arrays.toString(narrowChangesetRange(r, 5, 26)));
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
462 // System.out.println(Arrays.toString(narrowChangesetRange(r, 20, 26)));
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
463 // System.out.println(Arrays.toString(narrowChangesetRange(r, 26, 28)));
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
464 // }
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
465
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
466 private static int[] narrowChangesetRange(int[] csetRange, int startCset, int endCset) {
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
467 int lastInRange = csetRange[csetRange.length-1];
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
468 assert csetRange.length < 2 || csetRange[0] < lastInRange; // sorted
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
469 assert startCset >= 0 && startCset <= endCset;
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
470 if (csetRange[0] >= startCset && lastInRange <= endCset) {
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
471 // completely fits in
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
472 return csetRange;
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
473 }
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
474 if (csetRange[0] > endCset || lastInRange < startCset) {
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
475 return new int[0]; // trivial
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
476 }
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
477 int i = 0;
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
478 while (i < csetRange.length && csetRange[i] < startCset) {
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
479 i++;
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
480 }
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
481 int j = csetRange.length - 1;
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
482 while (j > i && csetRange[j] > endCset) {
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
483 j--;
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
484 }
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
485 if (i == j) {
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
486 // no values in csetRange fit into [startCset, endCset]
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
487 return new int[0];
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
488 }
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
489 int[] rv = new int[j-i+1];
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
490 System.arraycopy(csetRange, i, rv, 0, rv.length);
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
491 return rv;
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
492 }
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
493
370
a2341e761609 Let callback implementations deliver errors (e,g. own exceptions) to client code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 368
diff changeset
494 /**
515
e6c8b9b654b2 Provide access to HgDataFile being iterated into HgChangesetTreeHandler.TreeElement to give context for renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 514
diff changeset
495 * Tree-wise iteration of a file history, with handy access to parent-child relations between changesets.
e6c8b9b654b2 Provide access to HgDataFile being iterated into HgChangesetTreeHandler.TreeElement to give context for renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 514
diff changeset
496 * When file history is being followed, handler may additionally implement {@link HgFileRenameHandlerMixin}
e6c8b9b654b2 Provide access to HgDataFile being iterated into HgChangesetTreeHandler.TreeElement to give context for renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 514
diff changeset
497 * to get notified about switching between history chunks that belong to different names.
402
1fcc7f7b6d65 FIXMEs/javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
498 *
1fcc7f7b6d65 FIXMEs/javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
499 * @param handler callback to process changesets.
515
e6c8b9b654b2 Provide access to HgDataFile being iterated into HgChangesetTreeHandler.TreeElement to give context for renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 514
diff changeset
500 * @see HgFileRenameHandlerMixin
427
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
501 * @throws HgCallbackTargetException propagated exception from the handler
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
502 * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state
380
9517df1ef7ec Comments/javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 370
diff changeset
503 * @throws CancelledException if execution of the command was cancelled
402
1fcc7f7b6d65 FIXMEs/javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
504 * @throws IllegalArgumentException if command is not satisfied with its arguments
1fcc7f7b6d65 FIXMEs/javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
505 * @throws ConcurrentModificationException if this log command instance is already running
370
a2341e761609 Let callback implementations deliver errors (e,g. own exceptions) to client code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 368
diff changeset
506 */
515
e6c8b9b654b2 Provide access to HgDataFile being iterated into HgChangesetTreeHandler.TreeElement to give context for renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 514
diff changeset
507 public void execute(final HgChangesetTreeHandler handler) throws HgCallbackTargetException, HgException, CancelledException {
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
508 if (handler == null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
509 throw new IllegalArgumentException();
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
510 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
511 if (csetTransform != null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
512 throw new ConcurrentModificationException();
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
513 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
514 if (file == null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
515 throw new IllegalArgumentException("History tree is supported for files only (at least now), please specify file");
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
516 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
517 final ProgressSupport progressHelper = getProgressSupport(handler);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
518 final CancelSupport cancelHelper = getCancelSupport(handler, true);
514
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
519 final HgFileRenameHandlerMixin renameHandler = Adaptable.Factory.getAdapter(handler, HgFileRenameHandlerMixin.class, null);
507
a6435c1a42d0 Test for HgChangesetTreeHandler - make sure nothing is broken prior to adding --follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
520
509
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
521
517
9922d1f7cb2a Update test to use new command configuration argument (used to have followAncestry == true by default)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 516
diff changeset
522 // XXX rename. dispatcher is not a proper name (most of the job done - managing history chunk interconnection)
516
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
523 final HandlerDispatcher dispatcher = new HandlerDispatcher() {
515
e6c8b9b654b2 Provide access to HgDataFile being iterated into HgChangesetTreeHandler.TreeElement to give context for renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 514
diff changeset
524
516
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
525 @Override
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
526 protected void once(HistoryNode n) throws HgCallbackTargetException, CancelledException {
515
e6c8b9b654b2 Provide access to HgDataFile being iterated into HgChangesetTreeHandler.TreeElement to give context for renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 514
diff changeset
527 handler.treeElement(ei.init(n, currentFileNode));
e6c8b9b654b2 Provide access to HgDataFile being iterated into HgChangesetTreeHandler.TreeElement to give context for renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 514
diff changeset
528 cancelHelper.checkCancelled();
e6c8b9b654b2 Provide access to HgDataFile being iterated into HgChangesetTreeHandler.TreeElement to give context for renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 514
diff changeset
529 }
e6c8b9b654b2 Provide access to HgDataFile being iterated into HgChangesetTreeHandler.TreeElement to give context for renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 514
diff changeset
530 };
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
531
510
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
532 // renamed files in the queue are placed with respect to #iterateDirection
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
533 // i.e. if we iterate from new to old, recent filenames come first
514
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
534 List<Pair<HgDataFile, Nodeid>> fileRenamesQueue = buildFileRenamesQueue();
517
9922d1f7cb2a Update test to use new command configuration argument (used to have followAncestry == true by default)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 516
diff changeset
535 // XXX perhaps, makes sense to look at selected file's revision when followAncestry is true
9922d1f7cb2a Update test to use new command configuration argument (used to have followAncestry == true by default)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 516
diff changeset
536 // to ensure file we attempt to trace is in the WC's parent. Native hg aborts if not.
507
a6435c1a42d0 Test for HgChangesetTreeHandler - make sure nothing is broken prior to adding --follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
537 progressHelper.start(4 * fileRenamesQueue.size());
514
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
538 for (int namesIndex = 0, renamesQueueSize = fileRenamesQueue.size(); namesIndex < renamesQueueSize; namesIndex++) {
510
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
539
514
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
540 final Pair<HgDataFile, Nodeid> renameInfo = fileRenamesQueue.get(namesIndex);
516
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
541 dispatcher.prepare(progressHelper, renameInfo);
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: 419
diff changeset
542 cancelHelper.checkCancelled();
516
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
543 if (namesIndex > 0) {
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
544 dispatcher.connectWithLastJunctionPoint(renameInfo, fileRenamesQueue.get(namesIndex - 1), renameHandler);
509
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
545 }
514
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
546 if (namesIndex + 1 < renamesQueueSize) {
516
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
547 // there's at least one more name we are going to look at
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
548 dispatcher.updateJunctionPoint(renameInfo, fileRenamesQueue.get(namesIndex+1));
509
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
549 } else {
516
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
550 dispatcher.clearJunctionPoint();
509
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
551 }
516
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
552 dispatcher.dispatchAllChanges();
514
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
553 } // for fileRenamesQueue;
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
554 progressHelper.done();
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
555 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
556
510
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
557 private static class ReverseIterator<E> implements Iterator<E> {
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
558 private final ListIterator<E> listIterator;
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
559
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
560 public ReverseIterator(List<E> list) {
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
561 listIterator = list.listIterator(list.size());
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
562 }
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
563
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
564 public boolean hasNext() {
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
565 return listIterator.hasPrevious();
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
566 }
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
567 public E next() {
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
568 return listIterator.previous();
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
569 }
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
570 public void remove() {
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
571 listIterator.remove();
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
572 }
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
573 }
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
574
507
a6435c1a42d0 Test for HgChangesetTreeHandler - make sure nothing is broken prior to adding --follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
575 /**
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
576 * Follows file renames and build a list of all corresponding file nodes and revisions they were
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
577 * copied/renamed/branched at (IOW, their latest revision to look at).
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
578 *
514
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
579 * If {@link #followRenames} is <code>false</code>, the list contains one element only,
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
580 * file node with the name of the file as it was specified by the user.
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
581 *
514
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
582 * For the most recent file revision depends on {@link #followAncestry}, and is file revision from working copy parent
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
583 * in it's true. <code>null</code> indicates file's TIP revision shall be used.
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
584 *
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
585 * TODO may use HgFileRevision (after some refactoring to accept HgDataFile and Nodeid) instead of Pair
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
586 * and possibly reuse this functionality
507
a6435c1a42d0 Test for HgChangesetTreeHandler - make sure nothing is broken prior to adding --follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
587 *
510
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
588 * @return list of file renames, ordered with respect to {@link #iterateDirection}
507
a6435c1a42d0 Test for HgChangesetTreeHandler - make sure nothing is broken prior to adding --follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
589 */
518
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
590 private List<Pair<HgDataFile, Nodeid>> buildFileRenamesQueue() throws HgPathNotFoundException {
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
591 LinkedList<Pair<HgDataFile, Nodeid>> rv = new LinkedList<Pair<HgDataFile, Nodeid>>();
514
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
592 Nodeid startRev = null;
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
593 HgDataFile fileNode = repo.getFileNode(file);
518
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
594 if (!fileNode.exists()) {
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
595 throw new HgPathNotFoundException(String.format("File %s not found in the repository", file), file);
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
596 }
514
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
597 if (followAncestry) {
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
598 // TODO subject to dedicated method either in HgRepository (getWorkingCopyParentRevisionIndex)
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
599 // or in the HgDataFile (getWorkingCopyOriginRevision)
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
600 Nodeid wdParentChangeset = repo.getWorkingCopyParents().first();
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
601 if (!wdParentChangeset.isNull()) {
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
602 int wdParentRevIndex = repo.getChangelog().getRevisionIndex(wdParentChangeset);
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
603 startRev = repo.getManifest().getFileRevision(wdParentRevIndex, fileNode.getPath());
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
604 }
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
605 // else fall-through, assume null (eventually, lastRevision()) is ok here
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
606 }
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
607 rv.add(new Pair<HgDataFile, Nodeid>(fileNode, startRev));
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
608 if (!followRenames) {
507
a6435c1a42d0 Test for HgChangesetTreeHandler - make sure nothing is broken prior to adding --follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
609 return rv;
a6435c1a42d0 Test for HgChangesetTreeHandler - make sure nothing is broken prior to adding --follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
610 }
514
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
611 while (fileNode.isCopy()) {
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
612 Path fp = fileNode.getCopySourceName();
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
613 Nodeid copyRev = fileNode.getCopySourceRevision();
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
614 fileNode = repo.getFileNode(fp);
510
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
615 Pair<HgDataFile, Nodeid> p = new Pair<HgDataFile, Nodeid>(fileNode, copyRev);
522
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
616 if (iterateDirection == HgIterateDirection.OldToNew) {
510
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
617 rv.addFirst(p);
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
618 } else {
522
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
619 assert iterateDirection == HgIterateDirection.NewToOld;
510
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
620 rv.addLast(p);
90093ee56c0d Full-fledged test repo to follow file history. Investigating iteration direction alternatives (from new to old in addition to existing old to new)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 509
diff changeset
621 }
514
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
622 };
507
a6435c1a42d0 Test for HgChangesetTreeHandler - make sure nothing is broken prior to adding --follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
623 return rv;
a6435c1a42d0 Test for HgChangesetTreeHandler - make sure nothing is broken prior to adding --follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
624 }
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
625
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
626 private static class TreeBuildInspector implements HgChangelog.ParentInspector, HgChangelog.RevisionInspector {
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
627 private final boolean followAncestry;
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
628
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
629 private HistoryNode[] completeHistory;
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
630 private int[] commitRevisions;
509
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
631 private List<HistoryNode> resultHistory;
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
632
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
633 TreeBuildInspector(boolean _followAncestry) {
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
634 followAncestry = _followAncestry;
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
635 }
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
636
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
637 public void next(int revisionNumber, Nodeid revision, int linkedRevision) {
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
638 commitRevisions[revisionNumber] = linkedRevision;
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
639 }
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
640
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
641 public void next(int revisionNumber, Nodeid revision, int parent1, int parent2, Nodeid nidParent1, Nodeid nidParent2) {
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
642 HistoryNode p1 = null, p2 = null;
516
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
643 // IMPORTANT: method #one(), below, doesn't expect this code expects reasonable values at parent indexes
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
644 if (parent1 != -1) {
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
645 p1 = completeHistory[parent1];
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
646 }
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
647 if (parent2!= -1) {
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
648 p2 = completeHistory[parent2];
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
649 }
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
650 completeHistory[revisionNumber] = new HistoryNode(commitRevisions[revisionNumber], revision, p1, p2);
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
651 }
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
652
516
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
653 HistoryNode one(HgDataFile fileNode, Nodeid fileRevision) throws HgInvalidControlFileException {
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
654 int fileRevIndexToVisit = fileNode.getRevisionIndex(fileRevision);
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
655 return one(fileNode, fileRevIndexToVisit);
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
656 }
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
657
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
658 HistoryNode one(HgDataFile fileNode, int fileRevIndexToVisit) throws HgInvalidControlFileException {
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
659 resultHistory = null;
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
660 if (fileRevIndexToVisit == HgRepository.TIP) {
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
661 fileRevIndexToVisit = fileNode.getLastRevision();
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
662 }
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
663 // still, allocate whole array, for #next to be able to get null parent values
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
664 completeHistory = new HistoryNode[fileRevIndexToVisit+1];
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
665 commitRevisions = new int[completeHistory.length];
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
666 fileNode.indexWalk(fileRevIndexToVisit, fileRevIndexToVisit, this);
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
667 // it's only single revision, no need to care about followAncestry
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
668 // but won't hurt to keep resultHistory != null and commitRevisions initialized just in case
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
669 HistoryNode rv = completeHistory[fileRevIndexToVisit];
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
670 commitRevisions = new int[] { commitRevisions[fileRevIndexToVisit] };
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
671 completeHistory = null; // no need to keep almost empty array in memory
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
672 resultHistory = Collections.singletonList(rv);
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
673 return rv;
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
674 }
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
675
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
676 /**
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
677 * Builds history of file changes (in natural order, from oldest to newest) up to (and including) file revision specified.
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
678 * If {@link TreeBuildInspector} follows ancestry, only elements that are on the line of ancestry of the revision at
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
679 * lastRevisionIndex would be included.
509
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
680 *
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
681 * @return list of history elements, from oldest to newest. In case {@link #followAncestry} is <code>true</code>, the list
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
682 * is modifiable (to further augment with last/first elements of renamed file histories)
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
683 */
514
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
684 List<HistoryNode> go(HgDataFile fileNode, Nodeid fileLastRevisionToVisit) throws HgInvalidControlFileException {
509
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
685 resultHistory = null;
514
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
686 int fileLastRevIndexToVisit = fileLastRevisionToVisit == null ? fileNode.getLastRevision() : fileNode.getRevisionIndex(fileLastRevisionToVisit);
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
687 completeHistory = new HistoryNode[fileLastRevIndexToVisit+1];
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
688 commitRevisions = new int[completeHistory.length];
514
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
689 fileNode.indexWalk(0, fileLastRevIndexToVisit, this);
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
690 if (!followAncestry) {
509
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
691 // in case when ancestor not followed, it's safe to return unmodifiable list
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
692 resultHistory = Arrays.asList(completeHistory);
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
693 completeHistory = null;
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
694 // keep commitRevisions initialized, no need to recalculate them
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
695 // as they correspond 1:1 to resultHistory
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
696 return resultHistory;
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
697 }
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
698 /*
509
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
699 * Changesets, newest at the top:
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
700 * o <-- cset from working dir parent (as in dirstate), file not changed (file revision recorded points to that from A)
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
701 * | x <-- revision with file changed (B')
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
702 * x / <-- revision with file changed (A)
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
703 * | x <-- revision with file changed (B)
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
704 * |/
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
705 * o <-- another changeset, where file wasn't changed
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
706 * |
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
707 * x <-- revision with file changed (C)
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
708 *
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
709 * File history: B', A, B, C
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
710 *
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
711 * When "follow", SHALL NOT report B and B', but A and C
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
712 */
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
713 // strippedHistory: only those HistoryNodes from completeHistory that are on the same
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
714 // line of descendant, in order from older to newer
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
715 LinkedList<HistoryNode> strippedHistoryList = new LinkedList<HistoryNode>();
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
716 LinkedList<HistoryNode> queue = new LinkedList<HistoryNode>();
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
717 // look for ancestors of the selected history node
514
5dcb4581c8ef Report renames when following file history tree with HgFileRenameHandlerMixin
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 511
diff changeset
718 queue.add(completeHistory[fileLastRevIndexToVisit]);
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
719 do {
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
720 HistoryNode withFileChange = queue.removeFirst();
511
122e0600799f Respect multiple joins/forks in a history of a single file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 510
diff changeset
721 if (strippedHistoryList.contains(withFileChange)) {
122e0600799f Respect multiple joins/forks in a history of a single file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 510
diff changeset
722 // fork point for the change that was later merged (and we traced
122e0600799f Respect multiple joins/forks in a history of a single file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 510
diff changeset
723 // both lines of development by now.
122e0600799f Respect multiple joins/forks in a history of a single file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 510
diff changeset
724 continue;
122e0600799f Respect multiple joins/forks in a history of a single file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 510
diff changeset
725 }
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
726 if (withFileChange.children != null) {
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
727 withFileChange.children.retainAll(strippedHistoryList);
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
728 }
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
729 strippedHistoryList.addFirst(withFileChange);
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
730 if (withFileChange.parent1 != null) {
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
731 queue.addLast(withFileChange.parent1);
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
732 }
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
733 if (withFileChange.parent2 != null) {
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
734 queue.addLast(withFileChange.parent2);
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
735 }
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
736 } while (!queue.isEmpty());
511
122e0600799f Respect multiple joins/forks in a history of a single file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 510
diff changeset
737 Collections.sort(strippedHistoryList, new Comparator<HistoryNode>() {
122e0600799f Respect multiple joins/forks in a history of a single file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 510
diff changeset
738
122e0600799f Respect multiple joins/forks in a history of a single file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 510
diff changeset
739 public int compare(HistoryNode o1, HistoryNode o2) {
122e0600799f Respect multiple joins/forks in a history of a single file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 510
diff changeset
740 return o1.changeset - o2.changeset;
122e0600799f Respect multiple joins/forks in a history of a single file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 510
diff changeset
741 }
122e0600799f Respect multiple joins/forks in a history of a single file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 510
diff changeset
742 });
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
743 completeHistory = null;
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
744 commitRevisions = null;
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
745 // collected values are no longer valid - shall
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
746 // strip off elements for missing HistoryNodes, but it's easier just to re-create the array
509
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
747 // from resultHistory later, once (and if) needed
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
748 return resultHistory = strippedHistoryList;
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
749 }
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
750
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
751 /**
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
752 * handy access to all HistoryNode[i].changeset values
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
753 */
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
754 int[] getCommitRevisions() {
509
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
755 if (commitRevisions == null) {
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
756 commitRevisions = new int[resultHistory.size()];
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
757 int i = 0;
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
758 for (HistoryNode n : resultHistory) {
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
759 commitRevisions[i++] = n.changeset;
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
760 }
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
761 }
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
762 return commitRevisions;
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
763 }
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
764 };
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
765
516
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
766 private abstract class HandlerDispatcher {
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
767 private final int CACHE_CSET_IN_ADVANCE_THRESHOLD = 100; /* XXX is it really worth it? */
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
768 // builds tree of nodes according to parents in file's revlog
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
769 private final TreeBuildInspector treeBuildInspector = new TreeBuildInspector(followAncestry);
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
770 private List<HistoryNode> changeHistory;
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
771 protected ElementImpl ei = null;
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
772 private ProgressSupport progress;
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
773 protected HgDataFile currentFileNode;
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
774 // node where current file history chunk intersects with same file under other name history
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
775 // either mock of B(0) or A(k), depending on iteration order
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
776 private HistoryNode junctionNode;
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
777
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
778 // parentProgress shall be initialized with 4 XXX refactor all this stuff with parentProgress
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
779 public void prepare(ProgressSupport parentProgress, Pair<HgDataFile, Nodeid> renameInfo) {
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
780 // if we don't followAncestry, take complete history
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
781 // XXX treeBuildInspector knows followAncestry, perhaps the logic
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
782 // whether to take specific revision or the last one shall be there?
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
783 changeHistory = treeBuildInspector.go(renameInfo.first(), followAncestry ? renameInfo.second() : null);
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
784 assert changeHistory.size() > 0;
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
785 parentProgress.worked(1);
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
786 int historyNodeCount = changeHistory.size();
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
787 if (ei == null) {
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
788 // when follow is true, changeHistory.size() of the first revision might be quite short
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
789 // (e.g. bad fname recognized soon), hence ensure at least cache size at once
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
790 ei = new ElementImpl(Math.max(CACHE_CSET_IN_ADVANCE_THRESHOLD, historyNodeCount));
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
791 }
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
792 if (historyNodeCount < CACHE_CSET_IN_ADVANCE_THRESHOLD ) {
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
793 int[] commitRevisions = treeBuildInspector.getCommitRevisions();
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
794 assert commitRevisions.length == changeHistory.size();
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
795 // read bunch of changesets at once and cache 'em
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
796 ei.initTransform();
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
797 repo.getChangelog().range(ei, commitRevisions);
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
798 parentProgress.worked(1);
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
799 progress = new ProgressSupport.Sub(parentProgress, 2);
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
800 } else {
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
801 progress = new ProgressSupport.Sub(parentProgress, 3);
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
802 }
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
803 progress.start(historyNodeCount);
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
804 // switch to present chunk's file node
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
805 switchTo(renameInfo.first());
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
806 }
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
807
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
808 public void updateJunctionPoint(Pair<HgDataFile, Nodeid> curRename, Pair<HgDataFile, Nodeid> nextRename) {
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
809 // A (old) renamed to B(new). A(0..k..n) -> B(0..m). If followAncestry, k == n
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
810 // curRename.second() points to A(k)
522
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
811 if (iterateDirection == HgIterateDirection.OldToNew) {
516
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
812 // looking at A chunk (curRename), nextRename points to B
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
813 HistoryNode junctionSrc = findJunctionPointInCurrentChunk(curRename.second()); // A(k)
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
814 HistoryNode junctionDestMock = treeBuildInspector.one(nextRename.first(), 0); // B(0)
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
815 // junstionDestMock is mock object, once we iterate next rename, there'd be different HistoryNode
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
816 // for B's first revision. This means we read it twice, but this seems to be reasonable
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
817 // price for simplicity of the code (and opportunity to follow renames while not following ancestry)
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
818 junctionSrc.bindChild(junctionDestMock);
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
819 // Save mock A(k) 1) not to keep whole A history in memory 2) Don't need it's parent and children once get to B
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
820 // moreover, children of original A(k) (junctionSrc) would list mock B(0) which is undesired once we iterate over real B
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
821 junctionNode = new HistoryNode(junctionSrc.changeset, junctionSrc.fileRevision, null, null);
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
822 } else {
522
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
823 assert iterateDirection == HgIterateDirection.NewToOld;
516
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
824 // looking at B chunk (curRename), nextRename points at A
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
825 HistoryNode junctionDest = changeHistory.get(0); // B(0)
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
826 // prepare mock A(k)
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
827 HistoryNode junctionSrcMock = treeBuildInspector.one(nextRename.first(), nextRename.second()); // A(k)
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
828 // B(0) to list A(k) as its parent
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
829 // NOTE, A(k) would be different when we reach A chunk on the next iteration,
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
830 // but we do not care as long as TreeElement needs only parent/child changesets
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
831 // and not other TreeElements; so that it's enough to have mock parent node (just
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
832 // for the sake of parent cset revisions). We have to, indeed, update real A(k),
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
833 // once we get to iteration over A, with B(0) (junctionDest) as one more child.
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
834 junctionSrcMock.bindChild(junctionDest);
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
835 // Save mock B(0), for reasons see above for opposite direction
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
836 junctionNode = new HistoryNode(junctionDest.changeset, junctionDest.fileRevision, null, null);
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
837 }
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
838 }
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
839
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
840 public void clearJunctionPoint() {
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
841 junctionNode = null;
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
842 }
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
843
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
844 public void connectWithLastJunctionPoint(Pair<HgDataFile, Nodeid> curRename, Pair<HgDataFile, Nodeid> prevRename, HgFileRenameHandlerMixin renameHandler) throws HgCallbackTargetException {
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
845 assert junctionNode != null;
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
846 // A renamed to B. A(0..k..n) -> B(0..m). If followAncestry: k == n
522
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
847 if (iterateDirection == HgIterateDirection.OldToNew) {
516
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
848 // forward, from old to new:
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
849 // changeHistory points to B
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
850 // Already reported: A(0)..A(n), A(k) is in junctionNode
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
851 // Shall connect histories: A(k).bind(B(0))
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
852 HistoryNode junctionDest = changeHistory.get(0); // B(0)
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
853 // junctionNode is A(k)
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
854 junctionNode.bindChild(junctionDest);
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
855 if (renameHandler != null) { // shall report renames
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
856 HgFileRevision copiedFrom = new HgFileRevision(prevRename.first(), junctionNode.fileRevision, null); // "A", A(k)
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
857 HgFileRevision copiedTo = new HgFileRevision(curRename.first(), junctionDest.fileRevision, copiedFrom.getPath()); // "B", B(0)
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
858 renameHandler.copy(copiedFrom, copiedTo);
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
859 }
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
860 } else {
522
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
861 assert iterateDirection == HgIterateDirection.NewToOld;
516
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
862 // changeHistory points to A
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
863 // Already reported B(m), B(m-1)...B(0), B(0) is in junctionNode
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
864 // Shall connect histories A(k).bind(B(0))
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
865 // if followAncestry: A(k) is latest in changeHistory (k == n)
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
866 HistoryNode junctionSrc = findJunctionPointInCurrentChunk(curRename.second()); // A(k)
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
867 junctionSrc.bindChild(junctionNode);
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
868 if (renameHandler != null) {
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
869 HgFileRevision copiedFrom = new HgFileRevision(curRename.first(), junctionSrc.fileRevision, null); // "A", A(k)
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
870 HgFileRevision copiedTo = new HgFileRevision(prevRename.first(), junctionNode.fileRevision, copiedFrom.getPath()); // "B", B(0)
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
871 renameHandler.copy(copiedFrom, copiedTo);
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
872 }
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
873 }
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
874 }
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
875
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
876 private HistoryNode findJunctionPointInCurrentChunk(Nodeid fileRevision) {
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
877 if (followAncestry) {
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
878 // use the fact we don't go past junction point when followAncestry == true
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
879 HistoryNode rv = changeHistory.get(changeHistory.size() - 1);
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
880 assert rv.fileRevision.equals(fileRevision);
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
881 return rv;
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
882 }
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
883 for (HistoryNode n : changeHistory) {
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
884 if (n.fileRevision.equals(fileRevision)) {
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
885 return n;
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
886 }
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
887 }
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
888 int csetStart = changeHistory.get(0).changeset;
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
889 int csetEnd = changeHistory.get(changeHistory.size() - 1).changeset;
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
890 throw new HgInvalidStateException(String.format("For change history (cset[%d..%d]) could not find node for file change %s", csetStart, csetEnd, fileRevision.shortNotation()));
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
891 }
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
892
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
893 protected abstract void once(HistoryNode n) throws HgCallbackTargetException, CancelledException;
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
894
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
895 public void dispatchAllChanges() throws HgCallbackTargetException, CancelledException {
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
896 // XXX shall sort changeHistory according to changeset numbers?
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
897 Iterator<HistoryNode> it;
522
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
898 if (iterateDirection == HgIterateDirection.OldToNew) {
516
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
899 it = changeHistory.listIterator();
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
900 } else {
522
2103388d4010 Expose option to report changesets in reversed order
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 520
diff changeset
901 assert iterateDirection == HgIterateDirection.NewToOld;
516
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
902 it = new ReverseIterator<HistoryNode>(changeHistory);
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
903 }
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
904 while(it.hasNext()) {
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
905 HistoryNode n = it.next();
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
906 once(n);
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
907 progress.worked(1);
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
908 }
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
909 changeHistory = null;
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
910 }
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
911
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
912 public void switchTo(HgDataFile df) {
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
913 // from now on, use df in TreeElement
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
914 currentFileNode = df;
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
915 }
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
916 }
0ae5768081aa Allow walking file rename history independently from file ancestry (native hg log --follow does both at once)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 515
diff changeset
917
507
a6435c1a42d0 Test for HgChangesetTreeHandler - make sure nothing is broken prior to adding --follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
918
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
919 //
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
920
520
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
921 private class FilteringInspector extends AdapterPlug implements HgChangelog.Inspector, Adaptable {
518
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
922
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
923 private int firstCset = BAD_REVISION, lastCset = BAD_REVISION;
520
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
924 private HgChangelog.Inspector delegate;
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
925 // we use lifecycle to stop when limit is reached.
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
926 // delegate, however, may use lifecycle, too, so give it a chance
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
927 private LifecycleProxy lifecycleProxy;
518
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
928
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
929 // limit to changesets in this range only
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
930 public void changesets(int start, int end) {
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
931 firstCset = start;
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
932 lastCset = end;
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
933 }
520
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
934
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
935 public void delegateTo(HgChangelog.Inspector inspector) {
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
936 delegate = inspector;
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
937 // let delegate control life cycle, too
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
938 if (lifecycleProxy == null) {
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
939 super.attachAdapter(Lifecycle.class, lifecycleProxy = new LifecycleProxy(inspector));
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
940 } else {
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
941 lifecycleProxy.init(inspector);
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
942 }
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
943 }
518
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
944
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
945 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
946 if (limit > 0 && count >= limit) {
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
947 return;
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
948 }
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
949 // XXX may benefit from optional interface with #isInterested(int csetRev) - to avoid
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
950 // RawChangeset instantiation
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
951 if (firstCset != BAD_REVISION && revisionNumber < firstCset) {
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
952 return;
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
953 }
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
954 if (lastCset != BAD_REVISION && revisionNumber > lastCset) {
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
955 return;
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
956 }
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
957 if (branches != null && !branches.contains(cset.branch())) {
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
958 return;
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
959 }
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
960 if (users != null) {
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
961 String csetUser = cset.user().toLowerCase();
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
962 boolean found = false;
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
963 for (String u : users) {
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
964 if (csetUser.indexOf(u) != -1) {
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
965 found = true;
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
966 break;
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
967 }
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
968 }
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
969 if (!found) {
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
970 return;
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
971 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
972 }
518
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
973 if (date != null) {
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
974 // TODO post-1.0 implement date support for log
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
975 }
520
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
976 delegate.next(revisionNumber, nodeid, cset);
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
977 count++;
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
978 if (limit > 0 && count >= limit) {
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
979 lifecycleProxy.stop();
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
980 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
981 }
520
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
982 }
518
0d5e1ea7955e Tests for HgLogCommand#execute(HgChangesetHandler) with various combination of follow renames and ancestry
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 517
diff changeset
983
432
1fc0da631200 Revlog.ParentWalker helper class got promoted as TLC, renamed to HgParentChildMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
984 private HgParentChildMap<HgChangelog> getParentHelper(boolean create) throws HgInvalidControlFileException {
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
985 if (parentHelper == null && create) {
432
1fc0da631200 Revlog.ParentWalker helper class got promoted as TLC, renamed to HgParentChildMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
986 parentHelper = new HgParentChildMap<HgChangelog>(repo.getChangelog());
195
c9b305df0b89 Optimization: use ParentWalker to get changeset's parents, if possible. Do not keep duplicating nodeids and strings in manifest revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 193
diff changeset
987 parentHelper.init();
c9b305df0b89 Optimization: use ParentWalker to get changeset's parents, if possible. Do not keep duplicating nodeids and strings in manifest revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 193
diff changeset
988 }
c9b305df0b89 Optimization: use ParentWalker to get changeset's parents, if possible. Do not keep duplicating nodeids and strings in manifest revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 193
diff changeset
989 return parentHelper;
c9b305df0b89 Optimization: use ParentWalker to get changeset's parents, if possible. Do not keep duplicating nodeids and strings in manifest revisions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 193
diff changeset
990 }
520
1ee452f31187 Experimental support for inverse direction history walking. Refactored/streamlined cancellation in HgLogCommand and down the stack
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 518
diff changeset
991
205
ffc5f6d59f7e HgLogCommand.Handler is used in few places, pull up to top-level class, HgChangesetHandler
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 195
diff changeset
992 public static class CollectHandler implements HgChangesetHandler {
129
645829962785 core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 126
diff changeset
993 private final List<HgChangeset> result = new LinkedList<HgChangeset>();
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
994
129
645829962785 core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 126
diff changeset
995 public List<HgChangeset> getChanges() {
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
996 return Collections.unmodifiableList(result);
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
997 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
998
427
31a89587eb04 FIXMEs: consistent names, throws for commands and their handlers. Use of checked exceptions in hi-level api
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 424
diff changeset
999 public void cset(HgChangeset changeset) {
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1000 result.add(changeset.clone());
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1001 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1002 }
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1003
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1004 private static class HistoryNode {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1005 final int changeset;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1006 final Nodeid fileRevision;
509
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
1007 HistoryNode parent1; // there's special case when we can alter it, see #bindChild()
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
1008 final HistoryNode parent2;
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1009 List<HistoryNode> children;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1010
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1011 HistoryNode(int cs, Nodeid revision, HistoryNode p1, HistoryNode p2) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1012 changeset = cs;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1013 fileRevision = revision;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1014 parent1 = p1;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1015 parent2 = p2;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1016 if (p1 != null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1017 p1.addChild(this);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1018 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1019 if (p2 != null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1020 p2.addChild(this);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1021 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1022 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1023
509
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
1024 private void addChild(HistoryNode child) {
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1025 if (children == null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1026 children = new ArrayList<HistoryNode>(2);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1027 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1028 children.add(child);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1029 }
509
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
1030
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
1031 /**
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
1032 * method to merge two history chunks for renamed file so that
517
9922d1f7cb2a Update test to use new command configuration argument (used to have followAncestry == true by default)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 516
diff changeset
1033 * this node's history continues (or forks, if we don't followAncestry)
9922d1f7cb2a Update test to use new command configuration argument (used to have followAncestry == true by default)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 516
diff changeset
1034 * with that of child
509
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
1035 * @param child
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
1036 */
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
1037 public void bindChild(HistoryNode child) {
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
1038 assert child.parent1 == null && child.parent2 == null;
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
1039 child.parent1 = this;
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
1040 addChild(child);
a30e74dca193 Establish parent-child between first and last elements of history chunks for two renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 508
diff changeset
1041 }
511
122e0600799f Respect multiple joins/forks in a history of a single file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 510
diff changeset
1042
122e0600799f Respect multiple joins/forks in a history of a single file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 510
diff changeset
1043 public String toString() {
122e0600799f Respect multiple joins/forks in a history of a single file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 510
diff changeset
1044 return String.format("<cset:%d, parents: %s, %s>", changeset, parent1 == null ? "-" : String.valueOf(parent1.changeset), parent2 == null ? "-" : String.valueOf(parent2.changeset));
122e0600799f Respect multiple joins/forks in a history of a single file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 510
diff changeset
1045 }
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1046 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1047
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1048 private class ElementImpl implements HgChangesetTreeHandler.TreeElement, HgChangelog.Inspector {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1049 private HistoryNode historyNode;
515
e6c8b9b654b2 Provide access to HgDataFile being iterated into HgChangesetTreeHandler.TreeElement to give context for renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 514
diff changeset
1050 private HgDataFile fileNode;
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1051 private Pair<HgChangeset, HgChangeset> parents;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1052 private List<HgChangeset> children;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1053 private IntMap<HgChangeset> cachedChangesets;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1054 private ChangesetTransformer.Transformation transform;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1055 private Nodeid changesetRevision;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1056 private Pair<Nodeid,Nodeid> parentRevisions;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1057 private List<Nodeid> childRevisions;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1058
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1059 public ElementImpl(int total) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1060 cachedChangesets = new IntMap<HgChangeset>(total);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1061 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1062
515
e6c8b9b654b2 Provide access to HgDataFile being iterated into HgChangesetTreeHandler.TreeElement to give context for renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 514
diff changeset
1063 ElementImpl init(HistoryNode n, HgDataFile df) {
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1064 historyNode = n;
515
e6c8b9b654b2 Provide access to HgDataFile being iterated into HgChangesetTreeHandler.TreeElement to give context for renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 514
diff changeset
1065 fileNode = df;
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1066 parents = null;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1067 children = null;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1068 changesetRevision = null;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1069 parentRevisions = null;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1070 childRevisions = null;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1071 return this;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1072 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1073
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1074 public Nodeid fileRevision() {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1075 return historyNode.fileRevision;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1076 }
515
e6c8b9b654b2 Provide access to HgDataFile being iterated into HgChangesetTreeHandler.TreeElement to give context for renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 514
diff changeset
1077
e6c8b9b654b2 Provide access to HgDataFile being iterated into HgChangesetTreeHandler.TreeElement to give context for renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 514
diff changeset
1078 public HgDataFile file() {
e6c8b9b654b2 Provide access to HgDataFile being iterated into HgChangesetTreeHandler.TreeElement to give context for renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 514
diff changeset
1079 return fileNode;
e6c8b9b654b2 Provide access to HgDataFile being iterated into HgChangesetTreeHandler.TreeElement to give context for renamed files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 514
diff changeset
1080 }
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1081
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: 419
diff changeset
1082 public HgChangeset changeset() {
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1083 return get(historyNode.changeset)[0];
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1084 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1085
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: 419
diff changeset
1086 public Pair<HgChangeset, HgChangeset> parents() {
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1087 if (parents != null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1088 return parents;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1089 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1090 HistoryNode p;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1091 final int p1, p2;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1092 if ((p = historyNode.parent1) != null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1093 p1 = p.changeset;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1094 } else {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1095 p1 = -1;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1096 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1097 if ((p = historyNode.parent2) != null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1098 p2 = p.changeset;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1099 } else {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1100 p2 = -1;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1101 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1102 HgChangeset[] r = get(p1, p2);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1103 return parents = new Pair<HgChangeset, HgChangeset>(r[0], r[1]);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1104 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1105
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: 419
diff changeset
1106 public Collection<HgChangeset> children() {
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1107 if (children != null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1108 return children;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1109 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1110 if (historyNode.children == null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1111 children = Collections.emptyList();
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1112 } else {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1113 int[] childrentChangesetNumbers = new int[historyNode.children.size()];
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1114 int j = 0;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1115 for (HistoryNode hn : historyNode.children) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1116 childrentChangesetNumbers[j++] = hn.changeset;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1117 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1118 children = Arrays.asList(get(childrentChangesetNumbers));
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1119 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1120 return children;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1121 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1122
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1123 void populate(HgChangeset cs) {
403
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
1124 cachedChangesets.put(cs.getRevisionIndex(), cs);
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1125 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1126
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: 419
diff changeset
1127 private HgChangeset[] get(int... changelogRevisionIndex) {
403
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
1128 HgChangeset[] rv = new HgChangeset[changelogRevisionIndex.length];
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
1129 IntVector misses = new IntVector(changelogRevisionIndex.length, -1);
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
1130 for (int i = 0; i < changelogRevisionIndex.length; i++) {
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
1131 if (changelogRevisionIndex[i] == -1) {
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1132 rv[i] = null;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1133 continue;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1134 }
403
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
1135 HgChangeset cached = cachedChangesets.get(changelogRevisionIndex[i]);
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1136 if (cached != null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1137 rv[i] = cached;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1138 } else {
403
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
1139 misses.add(changelogRevisionIndex[i]);
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1140 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1141 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1142 if (misses.size() > 0) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1143 final int[] changesets2read = misses.toArray();
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1144 initTransform();
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1145 repo.getChangelog().range(this, changesets2read);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1146 for (int changeset2read : changesets2read) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1147 HgChangeset cs = cachedChangesets.get(changeset2read);
403
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
1148 if (cs == null) {
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: 419
diff changeset
1149 HgInvalidStateException t = new HgInvalidStateException(String.format("Can't get changeset for revision %d", changeset2read));
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: 419
diff changeset
1150 throw t.setRevisionIndex(changeset2read);
403
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
1151 }
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
1152 // HgChangelog.range may reorder changesets according to their order in the changelog
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
1153 // thus need to find original index
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
1154 boolean sanity = false;
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
1155 for (int i = 0; i < changelogRevisionIndex.length; i++) {
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
1156 if (changelogRevisionIndex[i] == cs.getRevisionIndex()) {
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
1157 rv[i] = cs;
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
1158 sanity = true;
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
1159 break;
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1160 }
403
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
1161 }
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
1162 if (!sanity) {
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: 457
diff changeset
1163 repo.getSessionContext().getLog().dump(getClass(), Error, "Index of revision %d:%s doesn't match any of requested", cs.getRevisionIndex(), cs.getNodeid().shortNotation());
403
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
1164 }
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
1165 assert sanity;
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1166 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1167 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1168 return rv;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1169 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1170
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1171 // init only when needed
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: 419
diff changeset
1172 void initTransform() throws HgRuntimeException {
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1173 if (transform == null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1174 transform = new ChangesetTransformer.Transformation(new HgStatusCollector(repo)/*XXX try to reuse from context?*/, getParentHelper(false));
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1175 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1176 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1177
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1178 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1179 HgChangeset cs = transform.handle(revisionNumber, nodeid, cset);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1180 populate(cs.clone());
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1181 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1182
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: 419
diff changeset
1183 public Nodeid changesetRevision() {
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1184 if (changesetRevision == null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1185 changesetRevision = getRevision(historyNode.changeset);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1186 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1187 return changesetRevision;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1188 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1189
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: 419
diff changeset
1190 public Pair<Nodeid, Nodeid> parentRevisions() {
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1191 if (parentRevisions == null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1192 HistoryNode p;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1193 final Nodeid p1, p2;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1194 if ((p = historyNode.parent1) != null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1195 p1 = getRevision(p.changeset);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1196 } else {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1197 p1 = Nodeid.NULL;;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1198 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1199 if ((p = historyNode.parent2) != null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1200 p2 = getRevision(p.changeset);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1201 } else {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1202 p2 = Nodeid.NULL;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1203 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1204 parentRevisions = new Pair<Nodeid, Nodeid>(p1, p2);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1205 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1206 return parentRevisions;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1207 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1208
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: 419
diff changeset
1209 public Collection<Nodeid> childRevisions() {
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1210 if (childRevisions != null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1211 return childRevisions;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1212 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1213 if (historyNode.children == null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1214 childRevisions = Collections.emptyList();
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1215 } else {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1216 ArrayList<Nodeid> rv = new ArrayList<Nodeid>(historyNode.children.size());
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1217 for (HistoryNode hn : historyNode.children) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1218 rv.add(getRevision(hn.changeset));
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1219 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1220 childRevisions = Collections.unmodifiableList(rv);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1221 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1222 return childRevisions;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1223 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1224
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1225 // reading nodeid involves reading index only, guess, can afford not to optimize multiple reads
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: 419
diff changeset
1226 private Nodeid getRevision(int changelogRevisionNumber) {
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: 419
diff changeset
1227 // TODO post-1.0 pipe through pool
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1228 HgChangeset cs = cachedChangesets.get(changelogRevisionNumber);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1229 if (cs != null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1230 return cs.getNodeid();
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1231 } else {
403
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
1232 return repo.getChangelog().getRevision(changelogRevisionNumber);
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1233 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1234 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
1235 }
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1236 }