Mercurial > jhg
annotate src/org/tmatesoft/hg/internal/FileRevisionHistoryChunk.java @ 692:e970b333f284
Refactor HgLogCommand to utilize correct file.isCopy(int)
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Sat, 03 Aug 2013 17:11:33 +0200 |
parents | 72fc7774b87e |
children |
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.repo.HgDataFile; |
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.HgRepository; |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
625
diff
changeset
|
30 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
|
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; |
691
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
43 // parent pairs of complete file history, index offset by fileRevFrom |
596
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; |
691
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
45 // map file revision to changelog revision (sparse array, only file revisions to visit are set), index offset by fileRevFrom |
596
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; |
691
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
48 private final int csetFrom, csetTo; |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
49 private final int fileRevFrom, fileRevTo; |
596
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 |
691
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
52 public FileRevisionHistoryChunk(HgDataFile file, int csetStart, int csetEnd, int fileStart, int fileEnd) { |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
53 assert fileEnd >= fileStart; |
596
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 df = file; |
691
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
55 csetFrom = csetStart; |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
56 csetTo = csetEnd; |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
57 fileRevFrom = fileStart; |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
58 fileRevTo = fileEnd; |
596
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
59 } |
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 * @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
|
63 */ |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 public HgDataFile getFile() { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 return df; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 } |
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 * @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
|
70 */ |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
71 public int getStartChangeset() { |
691
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
72 return csetFrom; |
596
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
73 } |
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 * @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
|
77 */ |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 public int getEndChangeset() { |
691
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
79 return csetTo; |
596
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 |
691
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
82 public void init() throws HgRuntimeException { |
596
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
83 int[] fileRevParents = new int[2]; |
691
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
84 final int totalFileRevs = fileRevTo - fileRevFrom + 1; |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
85 fileParentRevs = new IntVector(totalFileRevs * 2, 0); |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
86 // pretend parents of fileRevStart are not set, regardless of actual state as we are not going to visit them anyway |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
87 fileParentRevs.add(NO_REVISION, NO_REVISION); |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
88 // XXX df.indexWalk(fileRevStart, fileRevEnd, ) might be more effective |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
89 for (int i = fileRevFrom+1; i <= fileRevTo; i++) { |
596
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
90 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
|
91 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
|
92 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
93 // fileRevsToVisit keep file change ancestry from new to old |
691
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
94 fileRevsToVisit = new IntVector(totalFileRevs, 0); |
596
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
95 // keep map of file revision to changelog revision |
691
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
96 file2changelog = new int[totalFileRevs]; |
596
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 // 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
|
98 // 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
|
99 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
|
100 LinkedList<Integer> queue = new LinkedList<Integer>(); |
691
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
101 BitSet seen = new BitSet(totalFileRevs); |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
102 queue.add(fileRevTo); |
596
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
103 do { |
691
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
104 int fileRev = queue.removeFirst(); |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
105 int offFileRev = fileRev - fileRevFrom; |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
106 if (seen.get(offFileRev)) { |
596
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
107 continue; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
108 } |
691
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
109 seen.set(offFileRev); |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
110 int csetRev = df.getChangesetRevisionIndex(fileRev); |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
111 if (csetRev < csetFrom || csetRev > csetTo) { |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
112 continue; |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
113 } |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
114 fileRevsToVisit.add(fileRev); |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
115 |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
116 file2changelog[offFileRev] = csetRev; |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
117 int p1 = fileParentRevs.get(2*offFileRev); |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
118 int p2 = fileParentRevs.get(2*offFileRev + 1); |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
119 if (p1 != NO_REVISION && p1 >= fileRevFrom) { |
596
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
120 queue.addLast(p1); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
121 } |
691
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
122 if (p2 != NO_REVISION && p2 >= fileRevFrom) { |
596
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
123 queue.addLast(p2); |
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 } while (!queue.isEmpty()); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
126 // 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
|
127 fileRevsToVisit.sort(false); |
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 |
691
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
130 public void linkTo(FileRevisionHistoryChunk next) { |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
131 // assume that init() has been called already |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
132 if (next == null) { |
596
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
133 return; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
134 } |
691
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
135 next.originFileRev = fileRevsToVisit.get(0); // files to visit are new to old |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
136 next.originChangelogRev = changeset(next.originFileRev); |
596
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
137 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
138 |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
139 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
|
140 // 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
|
141 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
|
142 if (iterateOrder == OldToNew) { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
143 // reverse return value |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
144 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
|
145 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
|
146 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
|
147 rv[a] = t; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
148 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
149 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
150 return rv; |
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 |
625
b4948b159ab1
Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
596
diff
changeset
|
153 /** |
b4948b159ab1
Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
596
diff
changeset
|
154 * @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
|
155 */ |
b4948b159ab1
Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
596
diff
changeset
|
156 public int revisionCount() { |
b4948b159ab1
Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
596
diff
changeset
|
157 return fileRevsToVisit.size(); |
b4948b159ab1
Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
596
diff
changeset
|
158 } |
b4948b159ab1
Refactor internals of blame support, tests
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
596
diff
changeset
|
159 |
596
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
160 public int changeset(int fileRevIndex) { |
691
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
161 return file2changelog[fileRevIndex - fileRevFrom]; |
596
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 public void fillFileParents(int fileRevIndex, int[] fileParents) { |
691
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
165 if (fileRevIndex == fileRevFrom && originFileRev != BAD_REVISION) { |
596
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
166 // 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
|
167 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
|
168 fileParents[0] = originFileRev; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
169 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
|
170 return; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
171 } |
691
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
172 int x = fileRevIndex - fileRevFrom; |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
173 fileParents[0] = fileParentRevs.get(x * 2); |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
174 fileParents[1] = fileParentRevs.get(x * 2 + 1); |
596
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
175 } |
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 public void fillCsetParents(int fileRevIndex, int[] csetParents) { |
691
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
178 if (fileRevIndex == fileRevFrom && originFileRev != BAD_REVISION) { |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
179 assert originChangelogRev != NO_REVISION; |
596
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
180 csetParents[0] = originChangelogRev; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
181 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
|
182 return; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
183 } |
691
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
184 int x = fileRevIndex - fileRevFrom; |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
185 int fp1 = fileParentRevs.get(x * 2); |
72fc7774b87e
Fix file.isCopy() for blame/annotate. Refactor status and blame to use newly introduced FileHistory helper that builds file rename history
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
628
diff
changeset
|
186 int fp2 = fileParentRevs.get(x * 2 + 1); |
596
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
187 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
|
188 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
|
189 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
190 } |