Mercurial > jhg
annotate src/org/tmatesoft/hg/internal/FileHistory.java @ 697:24f4efedc9d5
Respect the fact ssh and http protocols use different compression approach to sent changegroup data
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 06 Aug 2013 13:34:34 +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.NewToOld; |
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
|
20 import static org.tmatesoft.hg.core.HgIterateDirection.OldToNew; |
596
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 import java.util.Collections; |
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.LinkedList; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 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
|
26 import org.tmatesoft.hg.core.Nodeid; |
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
|
27 import org.tmatesoft.hg.internal.FileRenameHistory.Chunk; |
596
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; |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
624
diff
changeset
|
29 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
|
30 |
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 * History of a file, with copy/renames, and corresponding revision information. |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 * Facility for file history iteration. |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 * |
624
507602cb4fb3
FIXMEs and TODOs: pay some technical debt
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
596
diff
changeset
|
35 * TODO [post-1.1] Utilize in HgLogCommand and anywhere else we need to follow file history |
596
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 class FileHistory { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 private LinkedList<FileRevisionHistoryChunk> fileCompleteHistory = new LinkedList<FileRevisionHistoryChunk>(); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 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
|
44 private final int csetTo; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 private final int csetFrom; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 public FileHistory(HgDataFile file, int fromChangeset, int toChangeset) { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 df = file; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 csetFrom = fromChangeset; |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 csetTo = toChangeset; |
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 |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 public int getStartChangeset() { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 return csetFrom; |
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 public int getEndChangeset() { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 return csetTo; |
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 |
628
6526d8adbc0f
Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
624
diff
changeset
|
61 public void build() throws HgRuntimeException { |
596
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 fileCompleteHistory.clear(); // just in case, #build() is not expected to be called more than once |
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
|
63 Nodeid fileRev = df.getRepo().getManifest().getFileRevision(csetTo, df.getPath()); |
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
|
64 int fileRevIndex = df.getRevisionIndex(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
|
65 FileRenameHistory frh = new FileRenameHistory(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
|
66 if (frh.isOutOfRange(df, fileRevIndex)) { |
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
|
67 return; |
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
|
68 } |
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
|
69 frh.build(df, fileRevIndex); |
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
|
70 FileRevisionHistoryChunk prevChunk = null; |
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
|
71 for (Chunk c : frh.iterate(OldToNew)) { |
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 FileRevisionHistoryChunk fileHistory = new FileRevisionHistoryChunk(c.file(), c.firstCset(), c.lastCset(), c.firstFileRev(), c.lastFileRev()); |
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
|
73 fileHistory.init(); |
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
|
74 if (fileHistory.revisionCount() == 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
|
75 // no revisions on our cset range of interest |
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
|
76 continue; |
596
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
77 } |
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
|
78 if (prevChunk != null) { |
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 prevChunk.linkTo(fileHistory); |
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
|
80 } |
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
|
81 fileCompleteHistory.addLast(fileHistory); // to get the list in old-to-new order |
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 prevChunk = fileHistory; |
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
|
83 } |
596
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 // fileCompleteHistory is in (origin, intermediate target, ultimate target) order |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
85 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
86 |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 public Iterable<FileRevisionHistoryChunk> iterate(HgIterateDirection order) { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
88 if (order == NewToOld) { |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
89 return ReverseIterator.reversed(fileCompleteHistory); |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
90 } |
43cfa08ff3fd
HgBlameFacility refactoring: extract code to build file history that spans renames
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
91 return Collections.unmodifiableList(fileCompleteHistory); |
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 } |