Mercurial > hg4j
annotate src/org/tmatesoft/hg/internal/FileRevisionHistoryChunk.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 | b4948b159ab1 |
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; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 |
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 * 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
|
34 * 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
|
35 * |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 * @author Artem Tikhomirov |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 * @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
|
38 */ |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 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
|
40 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
|
41 // 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
|
42 private IntVector fileRevsToVisit; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 // 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
|
44 private IntVector fileParentRevs; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 // 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
|
46 private int[] file2changelog; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 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
|
48 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
|
49 |
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 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
|
52 df = file; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 } |
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 * @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
|
57 */ |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 public HgDataFile getFile() { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 return df; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 } |
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 * @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
|
64 */ |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 public int getStartChangeset() { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 return csetRangeStart; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 } |
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 * @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
|
71 */ |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 public int getEndChangeset() { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
73 return csetRangeEnd; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 } |
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 public void init(int changelogRevisionIndex) { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
77 csetRangeEnd = changelogRevisionIndex; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 // 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
|
79 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
|
80 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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 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
|
86 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
|
87 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
88 // 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
|
89 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
|
90 // 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
|
91 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
|
92 // 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
|
93 // 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
|
94 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
|
95 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
|
96 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
|
97 queue.add(fileRevIndex); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
98 do { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
99 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
|
100 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
|
101 continue; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
102 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
103 seen.set(x); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
104 fileRevsToVisit.add(x); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
105 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
|
106 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
|
107 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
|
108 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
|
109 queue.addLast(p1); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
110 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
111 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
|
112 queue.addLast(p2); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
113 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
114 } while (!queue.isEmpty()); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
115 // 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
|
116 fileRevsToVisit.sort(false); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
117 } |
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 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
|
120 // 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
|
121 if (target == null) { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
122 return; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
123 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
124 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
|
125 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
|
126 } |
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 * 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
|
130 */ |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
131 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
|
132 csetRangeStart = firstChangelogRevOfInterest; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
133 if (firstChangelogRevOfInterest == 0) { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
134 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
|
135 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
136 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
|
137 // 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
|
138 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
|
139 i++; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
140 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
141 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
|
142 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
|
143 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
|
144 return; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
145 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
146 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
|
147 // 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
|
148 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
|
149 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
|
150 } |
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 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
|
153 // 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
|
154 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
|
155 if (iterateOrder == OldToNew) { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
156 // reverse return value |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
157 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
|
158 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
|
159 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
|
160 rv[a] = t; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
161 } |
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 return rv; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
164 } |
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 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
|
167 return file2changelog[fileRevIndex]; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
168 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
169 |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
170 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
|
171 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
|
172 // 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
|
173 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
|
174 fileParents[0] = originFileRev; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
175 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
|
176 return; |
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 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
|
179 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
|
180 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
181 |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
182 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
|
183 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
|
184 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
|
185 csetParents[0] = originChangelogRev; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
186 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
|
187 return; |
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 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
|
190 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
|
191 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
|
192 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
|
193 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
194 } |