annotate src/org/tmatesoft/hg/repo/HgBlameFacility.java @ 597:c895b5556937

Wrap manifest revision map completion into single file access
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 03 May 2013 14:10:40 +0200
parents 43cfa08ff3fd
children
rev   line source
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2013 TMate Software Ltd
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
3 *
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
6 * the Free Software Foundation; version 2 of the License.
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
7 *
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
8 * This program is distributed in the hope that it will be useful,
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
11 * GNU General Public License for more details.
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
12 *
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
13 * For information on how to redistribute this software under
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
14 * the terms of a license other than GNU General Public License
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
15 * contact TMate Software at support@hg4j.com
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
16 */
556
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
17 package org.tmatesoft.hg.repo;
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
18
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
19 import static org.tmatesoft.hg.core.HgIterateDirection.OldToNew;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
20 import static org.tmatesoft.hg.repo.HgInternals.wrongRevisionIndex;
596
43cfa08ff3fd HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 573
diff changeset
21 import static org.tmatesoft.hg.repo.HgRepository.NO_REVISION;
43cfa08ff3fd HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 573
diff changeset
22 import static org.tmatesoft.hg.repo.HgRepository.TIP;
552
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
23
562
6fbca6506bb5 Allow HgBlameFacility.Inspector (former BlockInspector) to throw an exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
24 import org.tmatesoft.hg.core.HgCallbackTargetException;
552
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
25 import org.tmatesoft.hg.core.HgIterateDirection;
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 import org.tmatesoft.hg.core.Nodeid;
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
27 import org.tmatesoft.hg.internal.BlameHelper;
556
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
28 import org.tmatesoft.hg.internal.Callback;
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
29 import org.tmatesoft.hg.internal.Experimental;
596
43cfa08ff3fd HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 573
diff changeset
30 import org.tmatesoft.hg.internal.FileHistory;
43cfa08ff3fd HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 573
diff changeset
31 import org.tmatesoft.hg.internal.FileRevisionHistoryChunk;
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
32 import org.tmatesoft.hg.util.Adaptable;
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
34 /**
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
35 * Facility with diff/annotate functionality.
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 *
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
37 * @author Artem Tikhomirov
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 * @author TMate Software Ltd.
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 */
556
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
40 @Experimental(reason="Unstable API")
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
41 public final class HgBlameFacility {
568
8ed4f4f4f0a6 Blame facility refactored, get ready for follow/no-follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 562
diff changeset
42 private final HgDataFile df;
8ed4f4f4f0a6 Blame facility refactored, get ready for follow/no-follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 562
diff changeset
43
8ed4f4f4f0a6 Blame facility refactored, get ready for follow/no-follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 562
diff changeset
44 public HgBlameFacility(HgDataFile file) {
8ed4f4f4f0a6 Blame facility refactored, get ready for follow/no-follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 562
diff changeset
45 if (file == null) {
8ed4f4f4f0a6 Blame facility refactored, get ready for follow/no-follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 562
diff changeset
46 throw new IllegalArgumentException();
8ed4f4f4f0a6 Blame facility refactored, get ready for follow/no-follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 562
diff changeset
47 }
8ed4f4f4f0a6 Blame facility refactored, get ready for follow/no-follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 562
diff changeset
48 df = file;
8ed4f4f4f0a6 Blame facility refactored, get ready for follow/no-follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 562
diff changeset
49 }
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
50
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
51 /**
552
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
52 * mimic 'hg diff -r clogRevIndex1 -r clogRevIndex2'
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
53 */
568
8ed4f4f4f0a6 Blame facility refactored, get ready for follow/no-follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 562
diff changeset
54 public void diff(int clogRevIndex1, int clogRevIndex2, Inspector insp) throws HgCallbackTargetException {
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
55 // FIXME clogRevIndex1 and clogRevIndex2 may point to different files, need to decide whether to throw an exception
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
56 // or to attempt to look up correct file node (tricky)
552
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
57 int fileRevIndex1 = fileRevIndex(df, clogRevIndex1);
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
58 int fileRevIndex2 = fileRevIndex(df, clogRevIndex2);
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
59 BlameHelper bh = new BlameHelper(insp, 5);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
60 bh.useFileUpTo(df, clogRevIndex2);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
61 bh.diff(fileRevIndex1, clogRevIndex1, fileRevIndex2, clogRevIndex2);
552
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
62 }
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
63
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
64 /**
568
8ed4f4f4f0a6 Blame facility refactored, get ready for follow/no-follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 562
diff changeset
65 * Walk file history up/down to revision at given changeset and report changes for each revision
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
66 */
568
8ed4f4f4f0a6 Blame facility refactored, get ready for follow/no-follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 562
diff changeset
67 public void annotate(int changelogRevisionIndex, Inspector insp, HgIterateDirection iterateOrder) throws HgCallbackTargetException {
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
68 annotate(0, changelogRevisionIndex, insp, iterateOrder);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
69 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
70
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
71 /**
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
72 * Walk file history range and report changes for each revision
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
73 */
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
74 public void annotate(int changelogRevIndexStart, int changelogRevIndexEnd, Inspector insp, HgIterateDirection iterateOrder) throws HgCallbackTargetException {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
75 if (wrongRevisionIndex(changelogRevIndexStart) || wrongRevisionIndex(changelogRevIndexEnd)) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
76 throw new IllegalArgumentException();
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
77 }
573
e49f9d9513fa Partial blame when start/end revisions are in the middle of a single filename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 570
diff changeset
78 // Note, changelogRevIndexEnd may be TIP, while the code below doesn't tolerate constants
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
79 //
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
80 int lastRevision = df.getRepo().getChangelog().getLastRevision();
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
81 if (changelogRevIndexEnd == TIP) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
82 changelogRevIndexEnd = lastRevision;
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
83 }
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
84 HgInternals.checkRevlogRange(changelogRevIndexStart, changelogRevIndexEnd, lastRevision);
552
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
85 if (!df.exists()) {
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
86 return;
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
87 }
596
43cfa08ff3fd HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 573
diff changeset
88 FileHistory fileHistory = new FileHistory(df, changelogRevIndexStart, changelogRevIndexEnd);
43cfa08ff3fd HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 573
diff changeset
89 fileHistory.build();
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
90 BlameHelper bh = new BlameHelper(insp, 10);
596
43cfa08ff3fd HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 573
diff changeset
91 for (FileRevisionHistoryChunk fhc : fileHistory.iterate(OldToNew)) {
43cfa08ff3fd HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 573
diff changeset
92 // iteration order is not important here
43cfa08ff3fd HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 573
diff changeset
93 bh.useFileUpTo(fhc.getFile(), fhc.getEndChangeset());
43cfa08ff3fd HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 573
diff changeset
94 }
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
95 int[] fileClogParentRevs = new int[2];
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
96 int[] fileParentRevs = new int[2];
596
43cfa08ff3fd HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 573
diff changeset
97 for (FileRevisionHistoryChunk fhc : fileHistory.iterate(iterateOrder)) {
43cfa08ff3fd HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 573
diff changeset
98 for (int fri : fhc.fileRevisions(iterateOrder)) {
43cfa08ff3fd HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 573
diff changeset
99 int clogRevIndex = fhc.changeset(fri);
43cfa08ff3fd HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 573
diff changeset
100 // the way we built fileHistory ensures we won't walk past [changelogRevIndexStart..changelogRevIndexEnd]
43cfa08ff3fd HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 573
diff changeset
101 assert clogRevIndex >= changelogRevIndexStart;
43cfa08ff3fd HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 573
diff changeset
102 assert clogRevIndex <= changelogRevIndexEnd;
43cfa08ff3fd HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 573
diff changeset
103 fhc.fillFileParents(fri, fileParentRevs);
43cfa08ff3fd HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 573
diff changeset
104 fhc.fillCsetParents(fri, fileClogParentRevs);
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
105 bh.annotateChange(fri, clogRevIndex, fileParentRevs, fileClogParentRevs);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
106 }
552
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
107 }
549
83afa680555d Annotate merge revision (combined diff against two parents without looking further)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 548
diff changeset
108 }
548
ab21ac7dd833 Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 546
diff changeset
109
ab21ac7dd833 Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 546
diff changeset
110 /**
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
111 * Annotates changes of the file against its parent(s).
562
6fbca6506bb5 Allow HgBlameFacility.Inspector (former BlockInspector) to throw an exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
112 * Unlike {@link #annotate(HgDataFile, int, Inspector, HgIterateDirection)}, doesn't
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
113 * walk file history, looks at the specified revision only. Handles both parents (if merge revision).
548
ab21ac7dd833 Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 546
diff changeset
114 */
568
8ed4f4f4f0a6 Blame facility refactored, get ready for follow/no-follow support
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 562
diff changeset
115 public void annotateSingleRevision(int changelogRevisionIndex, Inspector insp) throws HgCallbackTargetException {
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
116 // TODO detect if file is text/binary (e.g. looking for chars < ' ' and not \t\r\n\f
552
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
117 int fileRevIndex = fileRevIndex(df, changelogRevisionIndex);
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
118 int[] fileRevParents = new int[2];
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
119 df.parents(fileRevIndex, fileRevParents, null, null);
552
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
120 if (changelogRevisionIndex == TIP) {
45751456b471 Annotate file changes through few revisions, walking either direction (old to new and vice versa)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 551
diff changeset
121 changelogRevisionIndex = df.getChangesetRevisionIndex(fileRevIndex);
548
ab21ac7dd833 Line-by-line annotation API and support code in place
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 546
diff changeset
122 }
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
123 BlameHelper bh = new BlameHelper(insp, 5);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
124 bh.useFileUpTo(df, changelogRevisionIndex);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
125 int[] fileClogParentRevs = new int[2];
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
126 fileClogParentRevs[0] = fileRevParents[0] == NO_REVISION ? NO_REVISION : df.getChangesetRevisionIndex(fileRevParents[0]);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
127 fileClogParentRevs[1] = fileRevParents[1] == NO_REVISION ? NO_REVISION : df.getChangesetRevisionIndex(fileRevParents[1]);
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
128 bh.annotateChange(fileRevIndex, changelogRevisionIndex, fileRevParents, fileClogParentRevs);
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
129 }
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
130
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
131 /**
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
132 * Client's sink for revision differences.
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
133 *
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
134 * When implemented, clients shall not expect new {@link Block blocks} instances in each call.
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
135 *
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
136 * In case more information about annotated revision is needed, inspector instances may supply
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
137 * {@link RevisionDescriptor.Recipient} through {@link Adaptable}.
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
138 */
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
139 @Callback
562
6fbca6506bb5 Allow HgBlameFacility.Inspector (former BlockInspector) to throw an exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
140 public interface Inspector {
6fbca6506bb5 Allow HgBlameFacility.Inspector (former BlockInspector) to throw an exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
141 void same(EqualBlock block) throws HgCallbackTargetException;
6fbca6506bb5 Allow HgBlameFacility.Inspector (former BlockInspector) to throw an exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
142 void added(AddBlock block) throws HgCallbackTargetException;
6fbca6506bb5 Allow HgBlameFacility.Inspector (former BlockInspector) to throw an exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
143 void changed(ChangeBlock block) throws HgCallbackTargetException;
6fbca6506bb5 Allow HgBlameFacility.Inspector (former BlockInspector) to throw an exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
144 void deleted(DeleteBlock block) throws HgCallbackTargetException;
6fbca6506bb5 Allow HgBlameFacility.Inspector (former BlockInspector) to throw an exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
145 }
6fbca6506bb5 Allow HgBlameFacility.Inspector (former BlockInspector) to throw an exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
146
6fbca6506bb5 Allow HgBlameFacility.Inspector (former BlockInspector) to throw an exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
147 /**
554
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
148 * Represents content of a block, either as a sequence of bytes or a
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
149 * sequence of smaller blocks (lines), if appropriate (according to usage context).
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
150 *
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
151 * This approach allows line-by-line access to content data along with complete byte sequence for the whole block, i.e.
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
152 * <pre>
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
153 * BlockData bd = addBlock.addedLines()
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
154 * // bd describes data from the addition completely.
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
155 * // elements of the BlockData are lines
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
156 * bd.elementCount() == addBlock.totalAddedLines();
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
157 * // one cat obtain complete addition with
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
158 * byte[] everythingAdded = bd.asArray();
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
159 * // or iterate line by line
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
160 * for (int i = 0; i < bd.elementCount(); i++) {
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
161 * byte[] lineContent = bd.elementAt(i);
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
162 * String line = new String(lineContent, fileEncodingCharset);
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
163 * }
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
164 * where bd.elementAt(0) is the line at index addBlock.firstAddedLine()
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
165 * </pre>
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
166 *
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
167 * LineData or ChunkData?
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
168 */
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
169 public interface BlockData {
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
170 BlockData elementAt(int index);
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
171 int elementCount();
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
172 byte[] asArray();
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
173 }
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
174
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
175 /**
562
6fbca6506bb5 Allow HgBlameFacility.Inspector (former BlockInspector) to throw an exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
176 * {@link Inspector} may optionally request extra information about revisions
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
177 * being inspected, denoting itself as a {@link RevisionDescriptor.Recipient}. This class
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
178 * provides complete information about file revision under annotation now.
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
179 */
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
180 public interface RevisionDescriptor {
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
181 /**
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
182 * @return complete source of the diff origin, never <code>null</code>
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
183 */
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
184 BlockData origin();
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
185 /**
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
186 * @return complete source of the diff target, never <code>null</code>
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
187 */
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
188 BlockData target();
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
189 /**
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
190 * @return changeset revision index of original file, or {@link HgRepository#NO_REVISION} if it's the very first revision
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
191 */
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
192 int originChangesetIndex();
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
193 /**
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
194 * @return changeset revision index of the target file
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
195 */
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
196 int targetChangesetIndex();
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
197 /**
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
198 * @return <code>true</code> if this revision is merge
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
199 */
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
200 boolean isMerge();
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
201 /**
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
202 * @return changeset revision index of the second, merged parent
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
203 */
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
204 int mergeChangesetIndex();
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
205 /**
556
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
206 * @return revision index of the change in target file's revlog
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
207 */
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
208 int fileRevisionIndex();
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
209
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
210 /**
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
211 * @return file object under blame (target file)
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
212 */
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
213 HgDataFile file();
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
214
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
215 /**
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
216 * Implement to indicate interest in {@link RevisionDescriptor}.
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
217 *
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
218 * Note, instance of {@link RevisionDescriptor} is the same for
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
219 * {@link #start(RevisionDescriptor)} and {@link #done(RevisionDescriptor)}
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
220 * methods, and not necessarily a new one (i.e. <code>==</code>) for the next
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
221 * revision announced.
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
222 */
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
223 @Callback
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
224 public interface Recipient {
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
225 /**
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
226 * Comes prior to any change {@link Block blocks}
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
227 */
562
6fbca6506bb5 Allow HgBlameFacility.Inspector (former BlockInspector) to throw an exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
228 void start(RevisionDescriptor revisionDescription) throws HgCallbackTargetException;
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
229 /**
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
230 * Comes after all change {@link Block blocks} were dispatched
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
231 */
562
6fbca6506bb5 Allow HgBlameFacility.Inspector (former BlockInspector) to throw an exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 561
diff changeset
232 void done(RevisionDescriptor revisionDescription) throws HgCallbackTargetException;
555
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
233 }
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
234 }
e623aa2ca526 Annotate: RevisionDescriptor provides extra knowledge about inspected/annotated revision
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 554
diff changeset
235
556
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
236 /**
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
237 * Each change block comes from a single origin, blocks that are result of a merge
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
238 * have {@link #originChangesetIndex()} equal to {@link RevisionDescriptor#mergeChangesetIndex()}.
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
239 */
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
240 public interface Block {
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
241 int originChangesetIndex();
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
242 int targetChangesetIndex();
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
243 }
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
244
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
245 public interface EqualBlock extends Block {
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
246 int originStart();
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
247 int targetStart();
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
248 int length();
554
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
249 BlockData content();
545
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
250 }
15b406c7cd9d First round of annotate file is functional
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 544
diff changeset
251
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
252 public interface AddBlock extends Block {
556
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
253 /**
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
254 * @return line index in the origin where this block is inserted
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
255 */
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
256 int insertedAt();
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
257 /**
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
258 * @return line index of the first added line in the target revision
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
259 */
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
260 int firstAddedLine();
556
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
261 /**
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
262 * @return number of added lines in this block
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
263 */
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
264 int totalAddedLines();
556
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
265 /**
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
266 * @return content of added lines
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
267 */
554
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
268 BlockData addedLines();
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
269 }
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
270 public interface DeleteBlock extends Block {
556
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
271 /**
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
272 * @return line index in the target revision were this deleted block would be
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
273 */
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
274 int removedAt();
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
275 /**
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
276 * @return line index of the first removed line in the original revision
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
277 */
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
278 int firstRemovedLine();
556
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
279 /**
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
280 * @return number of deleted lines in this block
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
281 */
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
282 int totalRemovedLines();
556
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
283 /**
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
284 * @return content of deleted lines
e55f17a7a195 AnnotateFacility renamed to HgBlameFacility and exposed, API shapes out and got some javadoc
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 555
diff changeset
285 */
554
a5fd757d1b5d Access to content of annotated files through BlockData interface
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 553
diff changeset
286 BlockData removedLines();
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
287 }
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
288 public interface ChangeBlock extends AddBlock, DeleteBlock {
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
289 }
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
290
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
291
569
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
292 private static int fileRevIndex(HgDataFile df, int csetRevIndex) {
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
293 Nodeid fileRev = df.getRepo().getManifest().getFileRevision(csetRevIndex, df.getPath());
c4fd1037bc6f Support for copy/rename follow/no-follow for annotate
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 568
diff changeset
294 return df.getRevisionIndex(fileRev);
542
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
295 }
a71a05ec11bc Towards annotate/blame support: general outline of the functionality
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
296 }