Mercurial > hg4j
annotate src/org/tmatesoft/hg/internal/FileRevisionHistoryChunk.java @ 657:6334b0267103
ParentChildMap can supply RevisionMap. Refactor ArrayHelper to keep most of sorted/reverse index magic inside
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 04 Jul 2013 20:27:45 +0200 |
parents | 6526d8adbc0f |
children | 72fc7774b87e |
rev | line source |
---|---|
596
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
2 * Copyright (c) 2013 TMate Software Ltd |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.internal; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import static org.tmatesoft.hg.core.HgIterateDirection.OldToNew; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 import static org.tmatesoft.hg.repo.HgRepository.BAD_REVISION; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
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:
diff
changeset
|
22 |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 import java.util.Arrays; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 import java.util.BitSet; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 import java.util.LinkedList; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 import org.tmatesoft.hg.core.HgIterateDirection; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 import org.tmatesoft.hg.core.Nodeid; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 import org.tmatesoft.hg.repo.HgDataFile; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 import org.tmatesoft.hg.repo.HgRepository; |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
625
diff
changeset
|
31 import org.tmatesoft.hg.repo.HgRuntimeException; |
596
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 /** |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 * Piece of file history, identified by path, limited to file revisions from range [chop..init] of changesets, |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 * can be linked to another piece. |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 * |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 * @author Artem Tikhomirov |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 * @author TMate Software Ltd. |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 */ |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 public final class FileRevisionHistoryChunk { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 private final HgDataFile df; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 // change ancestry, sequence of file revisions |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 private IntVector fileRevsToVisit; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 // parent pairs of complete file history |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 private IntVector fileParentRevs; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 // map file revision to changelog revision (sparse array, only file revisions to visit are set) |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 private int[] file2changelog; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 private int originChangelogRev = BAD_REVISION, originFileRev = BAD_REVISION; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 private int csetRangeStart = NO_REVISION, csetRangeEnd = BAD_REVISION; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 public FileRevisionHistoryChunk(HgDataFile file) { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 df = file; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 /** |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
57 * @return file at this specific chunk of history (i.e. its path may be different from the paths of other chunks) |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 */ |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 public HgDataFile getFile() { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 return df; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 /** |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 * @return changeset this file history chunk was chopped at, or {@link HgRepository#NO_REVISION} if none specified |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 */ |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 public int getStartChangeset() { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 return csetRangeStart; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
68 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
70 /** |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 * @return changeset this file history chunk ends at |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 */ |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
73 public int getEndChangeset() { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 return csetRangeEnd; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
625
diff
changeset
|
77 public void init(int changelogRevisionIndex) throws HgRuntimeException { |
596
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 csetRangeEnd = changelogRevisionIndex; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 // XXX df.indexWalk(0, fileRevIndex, ) might be more effective |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 Nodeid fileRev = df.getRepo().getManifest().getFileRevision(changelogRevisionIndex, df.getPath()); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 int fileRevIndex = df.getRevisionIndex(fileRev); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 int[] fileRevParents = new int[2]; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
83 fileParentRevs = new IntVector((fileRevIndex+1) * 2, 0); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 fileParentRevs.add(NO_REVISION, NO_REVISION); // parents of fileRevIndex == 0 |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
85 for (int i = 1; i <= fileRevIndex; i++) { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
86 df.parents(i, fileRevParents, null, null); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 fileParentRevs.add(fileRevParents[0], fileRevParents[1]); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
88 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
89 // fileRevsToVisit keep file change ancestry from new to old |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
90 fileRevsToVisit = new IntVector(fileRevIndex + 1, 0); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
91 // keep map of file revision to changelog revision |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
92 file2changelog = new int[fileRevIndex+1]; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
93 // only elements worth visit would get mapped, so there would be unfilled areas in the file2changelog, |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
94 // prevent from error (make it explicit) by bad value |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
95 Arrays.fill(file2changelog, BAD_REVISION); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 LinkedList<Integer> queue = new LinkedList<Integer>(); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 BitSet seen = new BitSet(fileRevIndex + 1); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
98 queue.add(fileRevIndex); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
99 do { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
100 int x = queue.removeFirst(); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
101 if (seen.get(x)) { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
102 continue; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
103 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
104 seen.set(x); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
105 fileRevsToVisit.add(x); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
106 file2changelog[x] = df.getChangesetRevisionIndex(x); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
107 int p1 = fileParentRevs.get(2*x); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
108 int p2 = fileParentRevs.get(2*x + 1); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
109 if (p1 != NO_REVISION) { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
110 queue.addLast(p1); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
111 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
112 if (p2 != NO_REVISION) { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
113 queue.addLast(p2); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
114 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
115 } while (!queue.isEmpty()); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
116 // make sure no child is processed before we handled all (grand-)parents of the element |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
117 fileRevsToVisit.sort(false); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
118 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
119 |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
120 public void linkTo(FileRevisionHistoryChunk target) { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
121 // assume that target.init() has been called already |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
122 if (target == null) { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
123 return; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
124 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
125 target.originFileRev = fileRevsToVisit.get(0); // files to visit are new to old |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
126 target.originChangelogRev = changeset(target.originFileRev); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
127 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
128 |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
129 /** |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
130 * Mark revision closest(ceil) to specified as the very first one (no parents) |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
131 */ |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
132 public void chopAtChangeset(int firstChangelogRevOfInterest) { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
133 csetRangeStart = firstChangelogRevOfInterest; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
134 if (firstChangelogRevOfInterest == 0) { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
135 return; // nothing to do |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
136 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
137 int i = 0, x = fileRevsToVisit.size(), fileRev = BAD_REVISION; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
138 // fileRevsToVisit is new to old, greater numbers to smaller |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
139 while (i < x && changeset(fileRev = fileRevsToVisit.get(i)) >= firstChangelogRevOfInterest) { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
140 i++; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
141 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
142 assert fileRev != BAD_REVISION; // there's at least 1 revision in fileRevsToVisit |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
143 if (i == x && changeset(fileRev) != firstChangelogRevOfInterest) { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
144 assert false : "Requested changeset shall belong to the chunk"; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
145 return; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
146 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
147 fileRevsToVisit.trimTo(i); // no need to iterate more |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
148 // pretend fileRev got no parents |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
149 fileParentRevs.set(fileRev * 2, NO_REVISION); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
150 fileParentRevs.set(fileRev, NO_REVISION); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
151 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
152 |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
153 public int[] fileRevisions(HgIterateDirection iterateOrder) { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
154 // fileRevsToVisit is { r10, r7, r6, r5, r0 }, new to old |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
155 int[] rv = fileRevsToVisit.toArray(); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
156 if (iterateOrder == OldToNew) { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
157 // reverse return value |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
158 for (int a = 0, b = rv.length-1; a < b; a++, b--) { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
159 int t = rv[b]; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
160 rv[b] = rv[a]; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
161 rv[a] = t; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
162 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
163 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
164 return rv; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
165 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
166 |
625
b4948b159ab1
Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
596
diff
changeset
|
167 /** |
b4948b159ab1
Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
596
diff
changeset
|
168 * @return number of file revisions in this chunk of its history |
b4948b159ab1
Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
596
diff
changeset
|
169 */ |
b4948b159ab1
Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
596
diff
changeset
|
170 public int revisionCount() { |
b4948b159ab1
Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
596
diff
changeset
|
171 return fileRevsToVisit.size(); |
b4948b159ab1
Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
596
diff
changeset
|
172 } |
b4948b159ab1
Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
596
diff
changeset
|
173 |
596
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
174 public int changeset(int fileRevIndex) { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
175 return file2changelog[fileRevIndex]; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
176 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
177 |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
178 public void fillFileParents(int fileRevIndex, int[] fileParents) { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
179 if (fileRevIndex == 0 && originFileRev != BAD_REVISION) { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
180 // this chunk continues another file |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
181 assert originFileRev != NO_REVISION; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
182 fileParents[0] = originFileRev; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
183 fileParents[1] = NO_REVISION; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
184 return; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
185 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
186 fileParents[0] = fileParentRevs.get(fileRevIndex * 2); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
187 fileParents[1] = fileParentRevs.get(fileRevIndex * 2 + 1); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
188 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
189 |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
190 public void fillCsetParents(int fileRevIndex, int[] csetParents) { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
191 if (fileRevIndex == 0 && originFileRev != BAD_REVISION) { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
192 assert originFileRev != NO_REVISION; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
193 csetParents[0] = originChangelogRev; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
194 csetParents[1] = NO_REVISION; // I wonder if possible to start a copy with two parents? |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
195 return; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
196 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
197 int fp1 = fileParentRevs.get(fileRevIndex * 2); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
198 int fp2 = fileParentRevs.get(fileRevIndex * 2 + 1); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
199 csetParents[0] = fp1 == NO_REVISION ? NO_REVISION : changeset(fp1); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
200 csetParents[1] = fp2 == NO_REVISION ? NO_REVISION : changeset(fp2); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
201 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
202 } |