annotate src/org/tmatesoft/hg/core/HgLogCommand.java @ 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)
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 13 Dec 2012 15:46:40 +0100
parents a30e74dca193
children 122e0600799f
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
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 70
diff changeset
19 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
20 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
21
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
22 import java.util.ArrayList;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
23 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
24 import java.util.Calendar;
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
25 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
26 import java.util.Collections;
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.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
28 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
29 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
30 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
31 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
32 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
33 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
34
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
35 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
36 import org.tmatesoft.hg.internal.IntVector;
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
37 import org.tmatesoft.hg.repo.HgChangelog;
154
ba2bf656f00f Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
38 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset;
80
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
39 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
40 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
41 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
42 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
43 import org.tmatesoft.hg.repo.HgParentChildMap;
74
6f1b88693d48 Complete refactoring to org.tmatesoft
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 70
diff changeset
44 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
45 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
46 import org.tmatesoft.hg.repo.HgStatusCollector;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
47 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
48 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
49 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
50 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
51 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
52
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 /**
131
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 129
diff changeset
55 * 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
56 *
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 * <pre>
131
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 129
diff changeset
58 * Usage:
70
993f6f8e1314 Test for log command
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 64
diff changeset
59 * 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
60 * </pre>
131
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 129
diff changeset
61 * 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
62 *
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
63 * @author Artem Tikhomirov
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 * @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
65 */
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
66 public class HgLogCommand extends HgAbstractCommand<HgLogCommand> implements HgChangelog.Inspector {
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 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
69 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
70 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
71 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
72 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
73 private Calendar date;
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
74 private Path file;
80
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
75 private boolean followHistory; // makes sense only when file != null
193
37f3d4a596e4 Use common low to hi-level changeset api transformer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
76 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
77 private HgParentChildMap<HgChangelog> parentHelper;
80
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
78
131
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 129
diff changeset
79 public HgLogCommand(HgRepository hgRepo) {
107
7ec89d637f50 CatCommand
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 102
diff changeset
80 repo = hgRepo;
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
81 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
82
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
83 /**
148
1a7a9a20e1f9 Exceptions, javadoc. Initial cancel and progress support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 142
diff changeset
84 * 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
85 * 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
86 * @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
87 * @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
88 * @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
89 */
131
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 129
diff changeset
90 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
91 if (user == null) {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
92 throw new IllegalArgumentException();
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
93 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
94 if (users == null) {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
95 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
96 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
97 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
98 return this;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
99 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
100
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
101 /**
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
102 * 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
103 * 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
104 * 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
105 * @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
106 * @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
107 * @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
108 */
131
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 129
diff changeset
109 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
110 if (branch == null) {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
111 throw new IllegalArgumentException();
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
112 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
113 if (branches == null) {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
114 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
115 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116 branches.add(branch);
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
117 return this;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
118 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
119
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
120 // 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
121 // multiple?
131
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 129
diff changeset
122 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
123 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
124 // 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
125 // isSet(field) - false => don't use in detection of 'same date'
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
126 throw HgRepository.notImplemented();
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
127 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
128
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
129 /**
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
130 *
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
131 * @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
132 * @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
133 */
131
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 129
diff changeset
134 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
135 limit = num;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
136 return this;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
137 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
138
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 * 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
141 * 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
142 *
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
143 * @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
144 * @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
145 * @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
146 */
131
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 129
diff changeset
147 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
148 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
149 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
150 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
151 } 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
152 startRev = rev2;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
153 endRev = rev1;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
154 } else {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
155 startRev = rev1;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
156 endRev = rev2;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
157 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
158 return this;
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
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
161 /**
253
1874d11054e5 HgLogCommand.changeset(Nodeid) to ease command configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 250
diff changeset
162 * Select specific changeset
1874d11054e5 HgLogCommand.changeset(Nodeid) to ease command configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 250
diff changeset
163 *
1874d11054e5 HgLogCommand.changeset(Nodeid) to ease command configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 250
diff changeset
164 * @param nid changeset revision
1874d11054e5 HgLogCommand.changeset(Nodeid) to ease command configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 250
diff changeset
165 * @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
166 * @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
167 */
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
168 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
169 // 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
170 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
171 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
172 return range(csetRevIndex, csetRevIndex);
457
d78cb5ca3053 Get rid of ambiguity in method name
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 456
diff changeset
173 } 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
174 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
175 }
253
1874d11054e5 HgLogCommand.changeset(Nodeid) to ease command configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 250
diff changeset
176 }
1874d11054e5 HgLogCommand.changeset(Nodeid) to ease command configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 250
diff changeset
177
1874d11054e5 HgLogCommand.changeset(Nodeid) to ease command configuration
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 250
diff changeset
178 /**
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
179 * Visit history of a given file only.
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
180 * @param file path relative to repository root. Pass <code>null</code> to reset.
80
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
181 * @param followCopyRename true to report changesets of the original file(-s), if copy/rename ever occured to the file.
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
182 */
131
aa1629f36482 Renamed .core classes to start with Hg prefix
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 129
diff changeset
183 public HgLogCommand file(Path file, boolean followCopyRename) {
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
184 // multiple? Bad idea, would need to include extra method into Handler to tell start of next file
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
185 this.file = file;
80
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
186 followHistory = followCopyRename;
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
187 return this;
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
188 }
142
37a34044e6bd More reasonable use of path normalizer and path.source
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
189
37a34044e6bd More reasonable use of path normalizer and path.source
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
190 /**
37a34044e6bd More reasonable use of path normalizer and path.source
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
191 * Handy analog of {@link #file(Path, boolean)} when clients' paths come from filesystem and need conversion to repository's
37a34044e6bd More reasonable use of path normalizer and path.source
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
192 */
37a34044e6bd More reasonable use of path normalizer and path.source
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 133
diff changeset
193 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
194 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
195 }
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
196
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
197 /**
419
7f136a3fa671 Clean javadoc to fix obvious warnings
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 418
diff changeset
198 * 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
199 *
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
200 * @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
201 * @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
202 */
396
0ae53c32ecef Straighten out exceptions thrown when file access failed - three is too much
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 383
diff changeset
203 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
204 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
205 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
206 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
207 } 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
208 // 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
209 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
210 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
211 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
212 } 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
213 // 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
214 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
215 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
216 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
217 }
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
218 return collector.getChanges();
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
219 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
220
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
221 /**
402
1fcc7f7b6d65 FIXMEs/javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
222 * 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
223 *
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
224 * @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
225 * @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
226 * @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
227 * @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
228 * @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
229 * @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
230 */
370
a2341e761609 Let callback implementations deliver errors (e,g. own exceptions) to client code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 368
diff changeset
231 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
232 if (handler == null) {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
233 throw new IllegalArgumentException();
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
234 }
193
37f3d4a596e4 Use common low to hi-level changeset api transformer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
235 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
236 throw new ConcurrentModificationException();
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
237 }
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
238 final ProgressSupport progressHelper = getProgressSupport(handler);
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
239 try {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
240 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
241 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
242 // 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
243 // 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
244 csetTransform = new ChangesetTransformer(repo, handler, pw, progressHelper, getCancelSupport(handler, true));
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
245 if (file == 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
246 progressHelper.start(endRev - startRev + 1);
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
247 repo.getChangelog().range(startRev, endRev, this);
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
248 csetTransform.checkFailure();
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
249 } else {
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
250 progressHelper.start(-1/*XXX enum const, or a dedicated method startUnspecified(). How about startAtLeast(int)?*/);
80
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
251 HgDataFile fileNode = repo.getFileNode(file);
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
252 if (!fileNode.exists()) {
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
253 throw new HgPathNotFoundException(String.format("File %s not found in the repository", file), file);
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
254 }
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
255 // FIXME startRev and endRev ARE CHANGESET REVISIONS, not that of FILE!!!
80
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
256 fileNode.history(startRev, endRev, this);
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
257 csetTransform.checkFailure();
126
b92a638764be Dispatch chnagesets even if Handler is not FileHistoryHandler
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 107
diff changeset
258 if (fileNode.isCopy()) {
80
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
259 // even if we do not follow history, report file rename
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
260 do {
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
261 if (handler instanceof HgChangesetHandler.WithCopyHistory) {
415
ee8264d80747 Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 403
diff changeset
262 HgFileRevision src = new HgFileRevision(repo, fileNode.getCopySourceRevision(), null, fileNode.getCopySourceName());
ee8264d80747 Explicit constant for regular file flags, access to flags for a given file revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 403
diff changeset
263 HgFileRevision dst = new HgFileRevision(repo, fileNode.getRevision(0), null, fileNode.getPath(), src.getPath());
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
264 ((HgChangesetHandler.WithCopyHistory) handler).copy(src, dst);
126
b92a638764be Dispatch chnagesets even if Handler is not FileHistoryHandler
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 107
diff changeset
265 }
80
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
266 if (limit > 0 && count >= limit) {
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
267 // if limit reach, follow is useless.
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
268 break;
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
269 }
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
270 if (followHistory) {
126
b92a638764be Dispatch chnagesets even if Handler is not FileHistoryHandler
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 107
diff changeset
271 fileNode = repo.getFileNode(fileNode.getCopySourceName());
80
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
272 fileNode.history(this);
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
273 csetTransform.checkFailure();
80
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
274 }
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
275 } while (followHistory && fileNode.isCopy());
4222b04f34ee Follow history of a file
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 77
diff changeset
276 }
77
c677e1593919 Moved RevlogStream implementation into .internal
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 74
diff changeset
277 }
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
278 } 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
279 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
280 } finally {
193
37f3d4a596e4 Use common low to hi-level changeset api transformer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
281 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
282 progressHelper.done();
64
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 }
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
285
370
a2341e761609 Let callback implementations deliver errors (e,g. own exceptions) to client code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 368
diff changeset
286 /**
402
1fcc7f7b6d65 FIXMEs/javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
287 * Tree-wise iteration of a file history, with handy access to parent-child relations between changesets.
1fcc7f7b6d65 FIXMEs/javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
288 *
1fcc7f7b6d65 FIXMEs/javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
289 * @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
290 * @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
291 * @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
292 * @throws CancelledException if execution of the command was cancelled
402
1fcc7f7b6d65 FIXMEs/javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
293 * @throws IllegalArgumentException if command is not satisfied with its arguments
1fcc7f7b6d65 FIXMEs/javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 396
diff changeset
294 * @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
295 */
a2341e761609 Let callback implementations deliver errors (e,g. own exceptions) to client code
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 368
diff changeset
296 public void execute(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
297 if (handler == null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
298 throw new IllegalArgumentException();
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
299 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
300 if (csetTransform != null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
301 throw new ConcurrentModificationException();
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
302 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
303 if (file == null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
304 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
305 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
306 final ProgressSupport progressHelper = getProgressSupport(handler);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
307 final CancelSupport cancelHelper = getCancelSupport(handler, true);
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
308
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
309 // builds tree of nodes according to parents in file's revlog
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
310 final TreeBuildInspector treeBuildInspector = new TreeBuildInspector(followHistory);
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
311 // we iterate separate histories of each filename, need to connect
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
312 // last node of historyA with first node of historyB (A renamed to B case)
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
313 // to make overall history smooth.
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
314 HistoryNode lastFromPrevIteration = 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
315
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
316 final int CACHE_CSET_IN_ADVANCE_THRESHOLD = 100; /* XXX is it really worth it? */
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
317 ElementImpl ei = null;
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
318
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
319 // 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
320 // i.e. if we iterate from new to old, recent filenames come first
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
321 LinkedList<Pair<HgDataFile, Nodeid>> fileRenamesQueue = buildFileRenamesQueue();
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
322 progressHelper.start(4 * fileRenamesQueue.size());
a6435c1a42d0 Test for HgChangesetTreeHandler - make sure nothing is broken prior to adding --follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
323 do {
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
324
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
325 Pair<HgDataFile, Nodeid> renameInfo = fileRenamesQueue.removeFirst();
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
326 cancelHelper.checkCancelled();
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
327 HgDataFile fileNode = renameInfo.first();
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
328 Nodeid fileLastRevToVisit = null;
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
329 if (followHistory) {
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
330 fileLastRevToVisit = renameInfo.second();
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
331 if (fileLastRevToVisit == null) {
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
332 // it's either first or last item in the queue, depending on iteration order
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
333 assert fileRenamesQueue.isEmpty() || /*awful way to find out it's first iteration*/ lastFromPrevIteration == null;
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
334 // TODO subject to dedicated method either in HgRepository (getWorkingCopyParentRevisionIndex)
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
335 // or in the HgDataFile (getWorkingCopyOriginRevision)
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
336 Nodeid wdParentChangeset = repo.getWorkingCopyParents().first();
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
337 if (!wdParentChangeset.isNull()) {
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
338 int wdParentRevIndex = repo.getChangelog().getRevisionIndex(wdParentChangeset);
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
339 fileLastRevToVisit = repo.getManifest().getFileRevision(wdParentRevIndex, fileNode.getPath());
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
340 }
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
341 // else fall-through, assume lastRevision() is ok here
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
342 }
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
343 }
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
344 int fileLastRevIndexToVisit = fileLastRevToVisit == null ? fileNode.getLastRevision() : fileNode.getRevisionIndex(fileLastRevToVisit);
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
345 final List<HistoryNode> changeHistory = treeBuildInspector.go(fileNode, fileLastRevIndexToVisit);
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
346 assert changeHistory.size() > 0;
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
347 progressHelper.worked(1);
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
348 cancelHelper.checkCancelled();
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
349 final ProgressSupport ph2;
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
350 if (ei == 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
351 // when follow is true, changeHistory.size() of the first revision might be quite short
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
352 // (e.g. bad fname recognized soon), hence ensure at least cache size at once
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
353 ei = new ElementImpl(Math.max(CACHE_CSET_IN_ADVANCE_THRESHOLD, changeHistory.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
354 }
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
355 if (changeHistory.size() < CACHE_CSET_IN_ADVANCE_THRESHOLD ) {
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
356 int[] commitRevisions = treeBuildInspector.getCommitRevisions();
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
357 assert changeHistory.size() == commitRevisions.length;
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
358 // read bunch of changesets at once and cache 'em
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
359 ei.initTransform();
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
360 repo.getChangelog().range(ei, commitRevisions);
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
361 progressHelper.worked(1);
a6435c1a42d0 Test for HgChangesetTreeHandler - make sure nothing is broken prior to adding --follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
362 ph2 = new ProgressSupport.Sub(progressHelper, 2);
a6435c1a42d0 Test for HgChangesetTreeHandler - make sure nothing is broken prior to adding --follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
363 } else {
a6435c1a42d0 Test for HgChangesetTreeHandler - make sure nothing is broken prior to adding --follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
364 ph2 = new ProgressSupport.Sub(progressHelper, 3);
a6435c1a42d0 Test for HgChangesetTreeHandler - make sure nothing is broken prior to adding --follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
365 }
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
366 ph2.start(changeHistory.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
367 if (lastFromPrevIteration != null) {
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
368 if (iterateDirection == IterateDirection.FromOldToNew) {
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
369 // forward, from old to new:
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
370 // A(0..n) -> B(0..m). First, report A(0)..A(n-1)
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
371 // then A(n).bind(B(0))
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
372 HistoryNode oldestOfTheNextChunk = changeHistory.get(0);
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
373 lastFromPrevIteration.bindChild(oldestOfTheNextChunk);
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
374 changeHistory.add(0, lastFromPrevIteration);
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
375 } else {
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
376 assert iterateDirection == IterateDirection.FromNewToOld;
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
377 // A renamed to B. A(0..n) -> B(0..m).
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
378 // First, report B(m), B(m-1)...B(1), then A(n).bind(B(0))
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
379 HistoryNode newestOfNextChunk = changeHistory.get(changeHistory.size() - 1); // A(n)
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
380 newestOfNextChunk.bindChild(lastFromPrevIteration);
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
381 changeHistory.add(lastFromPrevIteration);
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
382 }
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
383 }
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
384 if (!fileRenamesQueue.isEmpty()) {
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
385 if (iterateDirection == IterateDirection.FromOldToNew) {
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
386 // save newest, and exclude it from this iteration (postpone for 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
387 lastFromPrevIteration = changeHistory.remove(changeHistory.size()-1);
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
388 } else {
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
389 assert iterateDirection == IterateDirection.FromNewToOld;
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
390 // save oldest, and exclude it from thi iteration (postpone for 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
391 lastFromPrevIteration = changeHistory.remove(0);
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
392 }
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
393 } else {
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
394 lastFromPrevIteration = null; // just for the sake of no references to old items
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
395 }
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
396 // XXX shall sort changeHistory according to changeset numbers?
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
397 Iterator<HistoryNode> it;
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
398 if (iterateDirection == IterateDirection.FromOldToNew) {
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
399 it = changeHistory.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
400 } else {
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
401 assert iterateDirection == IterateDirection.FromNewToOld;
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
402 it = new ReverseIterator<HistoryNode>(changeHistory);
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
403 }
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
404 while(it.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
405 HistoryNode n = it.next();
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
406 handler.treeElement(ei.init(n));
a6435c1a42d0 Test for HgChangesetTreeHandler - make sure nothing is broken prior to adding --follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
407 ph2.worked(1);
a6435c1a42d0 Test for HgChangesetTreeHandler - make sure nothing is broken prior to adding --follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
408 cancelHelper.checkCancelled();
a6435c1a42d0 Test for HgChangesetTreeHandler - make sure nothing is broken prior to adding --follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
409 }
a6435c1a42d0 Test for HgChangesetTreeHandler - make sure nothing is broken prior to adding --follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
410 } while (!fileRenamesQueue.isEmpty());
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
411 progressHelper.done();
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
412 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
413
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
414 private IterateDirection iterateDirection = IterateDirection.FromOldToNew;
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
415
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
416 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
417 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
418
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
419 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
420 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
421 }
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
422
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
423 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
424 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
425 }
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
426 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
427 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
428 }
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
429 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
430 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
431 }
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
432 }
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
433
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
434 /**
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
435 * 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
436 * 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
437 *
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
438 * If {@link #followHistory} is <code>false</code>, the list contains one element only,
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
439 * 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
440 *
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
441 * For the most recent file revision is null.
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
442 *
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
443 * 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
444 * 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
445 *
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
446 * @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
447 */
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
448 private LinkedList<Pair<HgDataFile, Nodeid>> buildFileRenamesQueue() {
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
449 LinkedList<Pair<HgDataFile, Nodeid>> rv = new LinkedList<Pair<HgDataFile, Nodeid>>();
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
450 if (!followHistory) {
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
451 rv.add(new Pair<HgDataFile, Nodeid>(repo.getFileNode(file), 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
452 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
453 }
a6435c1a42d0 Test for HgChangesetTreeHandler - make sure nothing is broken prior to adding --follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
454 Path fp = file;
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
455 Nodeid copyRev = 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
456 boolean isCopy;
a6435c1a42d0 Test for HgChangesetTreeHandler - make sure nothing is broken prior to adding --follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
457 do {
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
458 HgDataFile 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
459 Pair<HgDataFile, Nodeid> p = new Pair<HgDataFile, Nodeid>(fileNode, copyRev);
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
460 if (iterateDirection == IterateDirection.FromOldToNew) {
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
461 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
462 } else {
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
463 assert iterateDirection == IterateDirection.FromNewToOld;
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
464 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
465 }
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
466 if (isCopy = fileNode.isCopy()) {
a6435c1a42d0 Test for HgChangesetTreeHandler - make sure nothing is broken prior to adding --follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
467 fp = fileNode.getCopySourceName();
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
468 copyRev = fileNode.getCopySourceRevision();
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
469 }
a6435c1a42d0 Test for HgChangesetTreeHandler - make sure nothing is broken prior to adding --follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
470 } while (isCopy);
a6435c1a42d0 Test for HgChangesetTreeHandler - make sure nothing is broken prior to adding --follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 490
diff changeset
471 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
472 }
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
473
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
474 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
475 private final boolean followAncestry;
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
476
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
477 private HistoryNode[] completeHistory;
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
478 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
479 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
480
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
481 TreeBuildInspector(boolean _followAncestry) {
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
482 followAncestry = _followAncestry;
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
483 }
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
484
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
485 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
486 commitRevisions[revisionNumber] = linkedRevision;
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
487 }
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
488
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
489 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
490 HistoryNode p1 = null, p2 = null;
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
491 if (parent1 != -1) {
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
492 p1 = completeHistory[parent1];
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
493 }
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
494 if (parent2!= -1) {
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
495 p2 = completeHistory[parent2];
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
496 }
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
497 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
498 }
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
499
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
500 /**
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
501 * 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
502 * 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
503 * 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
504 *
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
505 * @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
506 * 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
507 */
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
508 List<HistoryNode> go(HgDataFile fileNode, int lastRevisionIndex) throws HgInvalidControlFileException {
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
509 resultHistory = null;
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
510 completeHistory = new HistoryNode[lastRevisionIndex+1];
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
511 commitRevisions = new int[completeHistory.length];
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
512 fileNode.indexWalk(0, lastRevisionIndex, this);
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
513 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
514 // 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
515 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
516 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
517 // 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
518 // 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
519 return resultHistory;
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
520 }
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
521 /*
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
522 * 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
523 * 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
524 * | 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
525 * 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
526 * | 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
527 * |/
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
528 * 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
529 * |
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
530 * 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
531 *
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
532 * 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
533 *
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
534 * 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
535 */
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
536 // 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
537 // 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
538 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
539 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
540 // look for ancestors of the selected history node
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
541 queue.add(completeHistory[lastRevisionIndex]);
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
542 do {
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
543 HistoryNode withFileChange = queue.removeFirst();
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
544 if (withFileChange.children != null) {
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
545 withFileChange.children.retainAll(strippedHistoryList);
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
546 }
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
547 strippedHistoryList.addFirst(withFileChange);
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
548 if (withFileChange.parent1 != null) {
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
549 queue.addLast(withFileChange.parent1);
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
550 }
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
551 if (withFileChange.parent2 != null) {
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
552 queue.addLast(withFileChange.parent2);
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
553 }
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
554 } while (!queue.isEmpty());
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
555 completeHistory = null;
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
556 commitRevisions = null;
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
557 // 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
558 // 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
559 // 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
560 return resultHistory = strippedHistoryList;
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
561 }
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
562
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
563 /**
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
564 * 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
565 */
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
566 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
567 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
568 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
569 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
570 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
571 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
572 }
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
573 }
508
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
574 return commitRevisions;
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
575 }
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
576 };
ca5202afea90 Support follow history option when walking file history tree
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 507
diff changeset
577
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
578
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
579 //
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
580
154
ba2bf656f00f Changeset => RawChangeset
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 148
diff changeset
581 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
582 if (limit > 0 && count >= limit) {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
583 return;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
584 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
585 if (branches != null && !branches.contains(cset.branch())) {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
586 return;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
587 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
588 if (users != null) {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
589 String csetUser = cset.user().toLowerCase();
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
590 boolean found = false;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
591 for (String u : users) {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
592 if (csetUser.indexOf(u) != -1) {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
593 found = true;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
594 break;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
595 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
596 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
597 if (!found) {
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
598 return;
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
599 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
600 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
601 if (date != null) {
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
602 // TODO post-1.0 implement date support for log
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
603 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
604 count++;
193
37f3d4a596e4 Use common low to hi-level changeset api transformer
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 157
diff changeset
605 csetTransform.next(revisionNumber, nodeid, cset);
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
606 }
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
607
432
1fc0da631200 Revlog.ParentWalker helper class got promoted as TLC, renamed to HgParentChildMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 431
diff changeset
608 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
609 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
610 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
611 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
612 }
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
613 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
614 }
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
615
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
616
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
617 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
618 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
619
129
645829962785 core.Cset renamed to HgChangeset; repo.Changeset moved into HgChangelog
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 126
diff changeset
620 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
621 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
622 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
623
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
624 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
625 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
626 }
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
627 }
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
628
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
629 private static class HistoryNode {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
630 final int changeset;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
631 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
632 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
633 final HistoryNode parent2;
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
634 List<HistoryNode> children;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
635
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
636 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
637 changeset = cs;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
638 fileRevision = revision;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
639 parent1 = p1;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
640 parent2 = p2;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
641 if (p1 != null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
642 p1.addChild(this);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
643 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
644 if (p2 != null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
645 p2.addChild(this);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
646 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
647 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
648
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
649 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
650 if (children == null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
651 children = new ArrayList<HistoryNode>(2);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
652 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
653 children.add(child);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
654 }
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
655
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
656 /**
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
657 * method to merge two history chunks for renamed file so that
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
658 * this node's history continues with that of 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
659 * @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
660 */
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
661 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
662 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
663 // for the last element in history empty children are by construction:
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
664 // we don't iterate further than last element of interest in TreeBuildInspector#go
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
665 assert children == null || children.isEmpty();
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
666 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
667 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
668 }
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
669 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
670
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
671 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
672 private HistoryNode historyNode;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
673 private Pair<HgChangeset, HgChangeset> parents;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
674 private List<HgChangeset> children;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
675 private IntMap<HgChangeset> cachedChangesets;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
676 private ChangesetTransformer.Transformation transform;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
677 private Nodeid changesetRevision;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
678 private Pair<Nodeid,Nodeid> parentRevisions;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
679 private List<Nodeid> childRevisions;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
680
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
681 public ElementImpl(int total) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
682 cachedChangesets = new IntMap<HgChangeset>(total);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
683 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
684
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
685 ElementImpl init(HistoryNode n) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
686 historyNode = n;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
687 parents = null;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
688 children = null;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
689 changesetRevision = null;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
690 parentRevisions = null;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
691 childRevisions = null;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
692 return this;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
693 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
694
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
695 public Nodeid fileRevision() {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
696 return historyNode.fileRevision;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
697 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
698
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
699 public HgChangeset changeset() {
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
700 return get(historyNode.changeset)[0];
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
701 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
702
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
703 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
704 if (parents != null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
705 return parents;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
706 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
707 HistoryNode p;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
708 final int p1, p2;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
709 if ((p = historyNode.parent1) != null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
710 p1 = p.changeset;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
711 } else {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
712 p1 = -1;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
713 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
714 if ((p = historyNode.parent2) != null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
715 p2 = p.changeset;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
716 } else {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
717 p2 = -1;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
718 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
719 HgChangeset[] r = get(p1, p2);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
720 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
721 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
722
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
723 public Collection<HgChangeset> children() {
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
724 if (children != null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
725 return children;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
726 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
727 if (historyNode.children == null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
728 children = Collections.emptyList();
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
729 } else {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
730 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
731 int j = 0;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
732 for (HistoryNode hn : historyNode.children) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
733 childrentChangesetNumbers[j++] = hn.changeset;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
734 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
735 children = Arrays.asList(get(childrentChangesetNumbers));
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
736 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
737 return children;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
738 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
739
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
740 void populate(HgChangeset cs) {
403
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
741 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
742 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
743
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
744 private HgChangeset[] get(int... changelogRevisionIndex) {
403
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
745 HgChangeset[] rv = new HgChangeset[changelogRevisionIndex.length];
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
746 IntVector misses = new IntVector(changelogRevisionIndex.length, -1);
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
747 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
748 if (changelogRevisionIndex[i] == -1) {
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
749 rv[i] = null;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
750 continue;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
751 }
403
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
752 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
753 if (cached != null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
754 rv[i] = cached;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
755 } else {
403
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
756 misses.add(changelogRevisionIndex[i]);
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
757 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
758 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
759 if (misses.size() > 0) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
760 final int[] changesets2read = misses.toArray();
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
761 initTransform();
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
762 repo.getChangelog().range(this, changesets2read);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
763 for (int changeset2read : changesets2read) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
764 HgChangeset cs = cachedChangesets.get(changeset2read);
403
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
765 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
766 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
767 throw t.setRevisionIndex(changeset2read);
403
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
768 }
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
769 // 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
770 // thus need to find original index
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
771 boolean sanity = false;
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
772 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
773 if (changelogRevisionIndex[i] == cs.getRevisionIndex()) {
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
774 rv[i] = cs;
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
775 sanity = true;
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
776 break;
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
777 }
403
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
778 }
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
779 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
780 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
781 }
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
782 assert sanity;
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
783 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
784 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
785 return rv;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
786 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
787
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
788 // 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
789 void initTransform() throws HgRuntimeException {
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
790 if (transform == null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
791 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
792 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
793 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
794
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
795 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
796 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
797 populate(cs.clone());
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
798 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
799
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
800 public Nodeid changesetRevision() {
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
801 if (changesetRevision == null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
802 changesetRevision = getRevision(historyNode.changeset);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
803 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
804 return changesetRevision;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
805 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
806
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
807 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
808 if (parentRevisions == null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
809 HistoryNode p;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
810 final Nodeid p1, p2;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
811 if ((p = historyNode.parent1) != null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
812 p1 = getRevision(p.changeset);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
813 } else {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
814 p1 = Nodeid.NULL;;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
815 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
816 if ((p = historyNode.parent2) != null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
817 p2 = getRevision(p.changeset);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
818 } else {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
819 p2 = Nodeid.NULL;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
820 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
821 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
822 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
823 return parentRevisions;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
824 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
825
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
826 public Collection<Nodeid> childRevisions() {
328
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
827 if (childRevisions != null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
828 return childRevisions;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
829 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
830 if (historyNode.children == null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
831 childRevisions = Collections.emptyList();
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
832 } else {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
833 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
834 for (HistoryNode hn : historyNode.children) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
835 rv.add(getRevision(hn.changeset));
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
836 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
837 childRevisions = Collections.unmodifiableList(rv);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
838 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
839 return childRevisions;
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
840 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
841
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
842 // 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
843 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
844 // 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
845 HgChangeset cs = cachedChangesets.get(changelogRevisionNumber);
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
846 if (cs != null) {
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
847 return cs.getNodeid();
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
848 } else {
403
2747b0723867 FIXMEs: work on exceptions and javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 402
diff changeset
849 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
850 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
851 }
a674b8590362 Move file tree history to upper API level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 322
diff changeset
852 }
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
853
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
854 private enum 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
855 FromOldToNew, FromNewToOld
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
856 }
64
19e9e220bf68 Convenient commands constitute hi-level API. org.tmatesoft namespace, GPL2 statement
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
857 }