annotate src/org/tmatesoft/hg/core/HgDiffCommand.java @ 630:72c979555cb8

HgDiffCommand. Do not use deprecated code. Javadoc
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 23 May 2013 19:44:28 +0200
parents 5f52074707b2
children 54e16ab771ec
rev   line source
629
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2013 TMate Software Ltd
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
17 package org.tmatesoft.hg.core;
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
19 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION;
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
20 import static org.tmatesoft.hg.repo.HgRepository.TIP;
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
21
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
22 import org.tmatesoft.hg.internal.BlameHelper;
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
23 import org.tmatesoft.hg.internal.CsetParamKeeper;
629
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
24 import org.tmatesoft.hg.internal.Experimental;
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import org.tmatesoft.hg.internal.FileHistory;
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 import org.tmatesoft.hg.internal.FileRevisionHistoryChunk;
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 import org.tmatesoft.hg.repo.HgDataFile;
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
28 import org.tmatesoft.hg.repo.HgRepository;
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
29 import org.tmatesoft.hg.repo.HgRuntimeException;
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 import org.tmatesoft.hg.util.CancelledException;
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 import org.tmatesoft.hg.util.Path;
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 /**
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 * 'hg diff' counterpart, with similar, diff-based, functionality
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35 *
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 * @since 1.1
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 * @author Artem Tikhomirov
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 * @author TMate Software Ltd.
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 */
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40 @Experimental(reason="#execute* methods might get renamed")
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 public class HgDiffCommand extends HgAbstractCommand<HgDiffCommand> {
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 private final HgRepository repo;
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 private HgDataFile df;
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
45 private final CsetParamKeeper clogRevIndexStart, clogRevIndexEnd;
629
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 private HgIterateDirection iterateDirection = HgIterateDirection.NewToOld;
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
47
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
48 public HgDiffCommand(HgRepository hgRepo) {
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 repo = hgRepo;
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
50 clogRevIndexStart = new CsetParamKeeper(hgRepo);
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
51 clogRevIndexEnd = new CsetParamKeeper(hgRepo);
629
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 }
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 public HgDiffCommand file(Path file) {
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55 df = repo.getFileNode(file);
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
56 return this;
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
57 }
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
59 /**
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
60 * Selects the file which history to blame, mandatory.
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
61 *
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
62 * @param file repository file
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
63 * @return <code>this</code> for convenience
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
64 */
629
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65 public HgDiffCommand file(HgDataFile file) {
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
66 df = file;
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
67 return this;
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
68 }
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
69
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
70 /**
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
71 * Select range of file's history for {@link #executeDiff(HgBlameInspector)}
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
72 * and {@link #executeAnnotate(HgBlameInspector)}.
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
73 * <p>
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
74 * {@link #executeDiff(HgBlameInspector) diff} uses these as revisions to diff against each other, while
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
75 * {@link #executeAnnotate(HgBlameInspector) annotate} walks the range.
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
76 *
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
77 * @param changelogRevIndexStart index of changelog revision, left range boundary
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
78 * @param changelogRevIndexEnd index of changelog revision, right range boundary
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
79 * @return <code>this</code> for convenience
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
80 * @throws HgBadArgumentException if failed to find any of supplied changeset
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
81 */
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
82 public HgDiffCommand range(int changelogRevIndexStart, int changelogRevIndexEnd) throws HgBadArgumentException {
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
83 clogRevIndexStart.set(changelogRevIndexStart);
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
84 clogRevIndexEnd.set(changelogRevIndexEnd);
629
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
85 return this;
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
86 }
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
87
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
88 /**
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
89 * Selects revision for {@link #executeAnnotateSingleRevision(HgBlameInspector)}, the one
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
90 * to diff against its parents.
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
91 *
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
92 * Besides, it is handy when range of interest spans up to the very beginning of the file history
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
93 * (and thus is equivalent to <code>range(0, changelogRevIndex)</code>)
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
94 *
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
95 * @param changelogRevIndex index of changelog revision
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
96 * @return <code>this</code> for convenience
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
97 * @throws HgBadArgumentException if failed to find supplied changeset
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
98 */
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
99 public HgDiffCommand changeset(int changelogRevIndex) throws HgBadArgumentException {
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
100 clogRevIndexStart.set(0);
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
101 clogRevIndexEnd.set(changelogRevIndex);
629
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
102 return this;
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
103 }
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
104
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
105 /**
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
106 * Revision differences are reported in selected order when
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
107 * annotating {@link #range(int, int) range} of changesets with
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
108 * {@link #executeAnnotate(HgBlameInspector)}.
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
109 * <p>
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
110 * This method doesn't affect {@link #executeAnnotateSingleRevision(HgBlameInspector)} and
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
111 * {@link #executeDiff(HgBlameInspector)}
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
112 *
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
113 * @param order desired iteration order
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
114 * @return <code>this</code> for convenience
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
115 */
629
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
116 public HgDiffCommand order(HgIterateDirection order) {
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
117 iterateDirection = order;
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
118 return this;
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
119 }
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
120
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
121 // FIXME progress and cancellation
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
122
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
123 /**
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
124 * Diff two revisions selected with {@link #range(int, int)} against each other.
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
125 * <p>mimics 'hg diff -r clogRevIndex1 -r clogRevIndex2'
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
126 *
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
127 * @throws HgCallbackTargetException propagated exception from the handler
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
128 * @throws CancelledException if execution of the command was cancelled
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
129 * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state
629
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
130 */
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
131 public void executeDiff(HgBlameInspector insp) throws HgCallbackTargetException, CancelledException, HgException {
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
132 checkFile();
629
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
133 try {
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
134 int fileRevIndex1 = fileRevIndex(df, clogRevIndexStart.get());
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
135 int fileRevIndex2 = fileRevIndex(df, clogRevIndexEnd.get());
629
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
136 BlameHelper bh = new BlameHelper(insp);
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
137 bh.prepare(df, clogRevIndexStart.get(), clogRevIndexEnd.get());
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
138 bh.diff(fileRevIndex1, clogRevIndexStart.get(), fileRevIndex2, clogRevIndexEnd.get());
629
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
139 } catch (HgRuntimeException ex) {
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
140 throw new HgLibraryFailureException(ex);
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
141 }
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
142 }
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
143
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
144 /**
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
145 * Walk file history {@link #range(int, int) range} and report changes (diff) for each revision
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
146 *
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
147 * @throws HgCallbackTargetException propagated exception from the handler
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
148 * @throws CancelledException if execution of the command was cancelled
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
149 * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state
629
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
150 */
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
151 public void executeAnnotate(HgBlameInspector insp) throws HgCallbackTargetException, CancelledException, HgException {
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
152 checkFile();
629
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
153 try {
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
154 if (!df.exists()) {
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
155 return;
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
156 }
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
157 BlameHelper bh = new BlameHelper(insp);
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
158 FileHistory fileHistory = bh.prepare(df, clogRevIndexStart.get(), clogRevIndexEnd.get());
629
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
159
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
160 int[] fileClogParentRevs = new int[2];
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
161 int[] fileParentRevs = new int[2];
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
162 for (FileRevisionHistoryChunk fhc : fileHistory.iterate(iterateDirection)) {
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
163 for (int fri : fhc.fileRevisions(iterateDirection)) {
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
164 int clogRevIndex = fhc.changeset(fri);
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
165 // the way we built fileHistory ensures we won't walk past [changelogRevIndexStart..changelogRevIndexEnd]
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
166 assert clogRevIndex >= clogRevIndexStart.get();
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
167 assert clogRevIndex <= clogRevIndexEnd.get();
629
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
168 fhc.fillFileParents(fri, fileParentRevs);
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
169 fhc.fillCsetParents(fri, fileClogParentRevs);
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
170 bh.annotateChange(fri, clogRevIndex, fileParentRevs, fileClogParentRevs);
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
171 }
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
172 }
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
173 } catch (HgRuntimeException ex) {
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
174 throw new HgLibraryFailureException(ex);
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
175 }
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
176 }
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
177
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
178 /**
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
179 * Annotates changes of the file against its parent(s).
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
180 * Unlike {@link #annotate(HgDataFile, int, Inspector, HgIterateDirection)}, doesn't
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
181 * walk file history, looks at the specified revision only. Handles both parents (if merge revision).
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
182 *
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
183 * @throws HgCallbackTargetException propagated exception from the handler
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
184 * @throws CancelledException if execution of the command was cancelled
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
185 * @throws HgException subclass thereof to indicate specific issue with the command arguments or repository state
629
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
186 */
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
187 public void executeAnnotateSingleRevision(HgBlameInspector insp) throws HgCallbackTargetException, CancelledException, HgException {
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
188 checkFile();
629
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
189 try {
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
190 int changelogRevisionIndex = clogRevIndexEnd.get();
629
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
191 // TODO detect if file is text/binary (e.g. looking for chars < ' ' and not \t\r\n\f
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
192 int fileRevIndex = fileRevIndex(df, changelogRevisionIndex);
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
193 int[] fileRevParents = new int[2];
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
194 df.parents(fileRevIndex, fileRevParents, null, null);
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
195 if (changelogRevisionIndex == TIP) {
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
196 changelogRevisionIndex = df.getChangesetRevisionIndex(fileRevIndex);
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
197 }
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
198 int[] fileClogParentRevs = new int[2];
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
199 fileClogParentRevs[0] = fileRevParents[0] == NO_REVISION ? NO_REVISION : df.getChangesetRevisionIndex(fileRevParents[0]);
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
200 fileClogParentRevs[1] = fileRevParents[1] == NO_REVISION ? NO_REVISION : df.getChangesetRevisionIndex(fileRevParents[1]);
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
201 BlameHelper bh = new BlameHelper(insp);
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
202 int clogIndexStart = fileClogParentRevs[0] == NO_REVISION ? (fileClogParentRevs[1] == NO_REVISION ? 0 : fileClogParentRevs[1]) : fileClogParentRevs[0];
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
203 bh.prepare(df, clogIndexStart, changelogRevisionIndex);
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
204 bh.annotateChange(fileRevIndex, changelogRevisionIndex, fileRevParents, fileClogParentRevs);
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
205 } catch (HgRuntimeException ex) {
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
206 throw new HgLibraryFailureException(ex);
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
207 }
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
208 }
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
209
630
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
210 private void checkFile() {
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
211 if (df == null) {
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
212 throw new IllegalArgumentException("File is not set");
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
213 }
72c979555cb8 HgDiffCommand. Do not use deprecated code. Javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 629
diff changeset
214 }
629
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
215
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
216 private static int fileRevIndex(HgDataFile df, int csetRevIndex) throws HgRuntimeException {
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
217 Nodeid fileRev = df.getRepo().getManifest().getFileRevision(csetRevIndex, df.getPath());
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
218 return df.getRevisionIndex(fileRev);
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
219 }
5f52074707b2 Diff/blame methods as command, their residence in HgDataFile was a mistake
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
220 }