Mercurial > jhg
annotate src/org/tmatesoft/hg/repo/HgBranches.java @ 619:868b2ffdcd5c
Close FIS, not FileChannel, to clear both references to FileDescriptor right away
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 17 May 2013 22:04:23 +0200 |
parents | 5c68567b3645 |
children | 6526d8adbc0f |
rev | line source |
---|---|
220
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
610
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
490
diff
changeset
|
2 * Copyright (c) 2011-2013 TMate Software Ltd |
220
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.repo; |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
456
909306e412e2
Refactor LogFacility and SessionContext, better API for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
433
diff
changeset
|
19 import static org.tmatesoft.hg.util.LogFacility.Severity.Error; |
909306e412e2
Refactor LogFacility and SessionContext, better API for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
433
diff
changeset
|
20 import static org.tmatesoft.hg.util.LogFacility.Severity.Warn; |
909306e412e2
Refactor LogFacility and SessionContext, better API for both
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
433
diff
changeset
|
21 |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
22 import java.io.BufferedReader; |
244
4b661efb9374
Use updated location of cache files (cache/ folder instead of .cache filename extension). Provide means to update (write down) cache for subsequent uses
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
23 import java.io.BufferedWriter; |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
24 import java.io.File; |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
25 import java.io.FileReader; |
244
4b661efb9374
Use updated location of cache files (cache/ folder instead of .cache filename extension). Provide means to update (write down) cache for subsequent uses
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
26 import java.io.FileWriter; |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
27 import java.io.IOException; |
315
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
28 import java.util.ArrayList; |
220
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 import java.util.Arrays; |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 import java.util.Collections; |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 import java.util.HashMap; |
308
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
32 import java.util.LinkedHashMap; |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
33 import java.util.LinkedHashSet; |
220
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 import java.util.LinkedList; |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 import java.util.List; |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 import java.util.Map; |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 import java.util.TreeMap; |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
38 import java.util.regex.Pattern; |
220
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 import org.tmatesoft.hg.core.Nodeid; |
610
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
490
diff
changeset
|
41 import org.tmatesoft.hg.internal.ChangelogMonitor; |
244
4b661efb9374
Use updated location of cache files (cache/ folder instead of .cache filename extension). Provide means to update (write down) cache for subsequent uses
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
42 import org.tmatesoft.hg.internal.Experimental; |
490
b3c16d1aede0
Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
456
diff
changeset
|
43 import org.tmatesoft.hg.internal.Internals; |
220
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset; |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 import org.tmatesoft.hg.util.ProgressSupport; |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 /** |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 * |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 * @author Artem Tikhomirov |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 * @author TMate Software Ltd. |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 */ |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 public class HgBranches { |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 |
610
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
490
diff
changeset
|
54 private final Internals internalRepo; |
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
490
diff
changeset
|
55 private final ChangelogMonitor repoChangeTracker; |
220
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 private final Map<String, BranchInfo> branches = new TreeMap<String, BranchInfo>(); |
244
4b661efb9374
Use updated location of cache files (cache/ folder instead of .cache filename extension). Provide means to update (write down) cache for subsequent uses
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
57 private boolean isCacheActual = false; |
4b661efb9374
Use updated location of cache files (cache/ folder instead of .cache filename extension). Provide means to update (write down) cache for subsequent uses
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
58 |
490
b3c16d1aede0
Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
456
diff
changeset
|
59 HgBranches(Internals internals) { |
b3c16d1aede0
Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
456
diff
changeset
|
60 internalRepo = internals; |
610
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
490
diff
changeset
|
61 repoChangeTracker = new ChangelogMonitor(internals.getRepo()); |
220
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 } |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 |
348
a0864b2892cd
Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
340
diff
changeset
|
64 private int readCache() { |
610
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
490
diff
changeset
|
65 final HgRepository repo = internalRepo.getRepo(); |
244
4b661efb9374
Use updated location of cache files (cache/ folder instead of .cache filename extension). Provide means to update (write down) cache for subsequent uses
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
66 File branchheadsCache = getCacheFile(); |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
67 int lastInCache = -1; |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
68 if (!branchheadsCache.canRead()) { |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
69 return lastInCache; |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
70 } |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
71 BufferedReader br = null; |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
72 final Pattern spacePattern = Pattern.compile(" "); |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
73 try { |
308
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
74 final LinkedHashMap<String, List<Nodeid>> branchHeads = new LinkedHashMap<String, List<Nodeid>>(); |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
75 br = new BufferedReader(new FileReader(branchheadsCache)); |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
76 String line = br.readLine(); |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
77 if (line == null || line.trim().length() == 0) { |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
78 return lastInCache; |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
79 } |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
80 String[] cacheIdentity = spacePattern.split(line.trim()); |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
81 lastInCache = Integer.parseInt(cacheIdentity[1]); |
340
a54bfe0db959
IAE using stale data from branchheads file (invalid due to repository rollback)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
315
diff
changeset
|
82 final int lastKnownRepoRevIndex = repo.getChangelog().getLastRevision(); |
a54bfe0db959
IAE using stale data from branchheads file (invalid due to repository rollback)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
315
diff
changeset
|
83 if (lastInCache > lastKnownRepoRevIndex || !repo.getChangelog().getRevision(lastKnownRepoRevIndex).equals(Nodeid.fromAscii(cacheIdentity[0]))) { |
a54bfe0db959
IAE using stale data from branchheads file (invalid due to repository rollback)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
315
diff
changeset
|
84 // there are chances cache file got invalid entries due to e.g. rollback operation |
a54bfe0db959
IAE using stale data from branchheads file (invalid due to repository rollback)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
315
diff
changeset
|
85 return -1; |
a54bfe0db959
IAE using stale data from branchheads file (invalid due to repository rollback)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
315
diff
changeset
|
86 } |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
87 while ((line = br.readLine()) != null) { |
244
4b661efb9374
Use updated location of cache files (cache/ folder instead of .cache filename extension). Provide means to update (write down) cache for subsequent uses
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
88 String[] elements = spacePattern.split(line.trim()); |
308
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
89 if (elements.length != 2) { |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
90 // bad entry |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
91 continue; |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
92 } |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
93 // I assume split returns substrings of the original string, hence copy of a branch name |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
94 String branchName = new String(elements[elements.length-1]); |
308
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
95 List<Nodeid> heads = branchHeads.get(elements[1]); |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
96 if (heads == null) { |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
97 branchHeads.put(branchName, heads = new LinkedList<Nodeid>()); |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
98 } |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
99 heads.add(Nodeid.fromAscii(elements[0])); |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
100 } |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
101 for (Map.Entry<String, List<Nodeid>> e : branchHeads.entrySet()) { |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
102 Nodeid[] heads = e.getValue().toArray(new Nodeid[e.getValue().size()]); |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
103 BranchInfo bi = new BranchInfo(e.getKey(), heads); |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
104 branches.put(e.getKey(), bi); |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
105 } |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
106 return lastInCache; |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
107 } catch (IOException ex) { |
348
a0864b2892cd
Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
340
diff
changeset
|
108 // log error, but otherwise do nothing |
490
b3c16d1aede0
Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
456
diff
changeset
|
109 repo.getSessionContext().getLog().dump(getClass(), Warn, ex, null); |
348
a0864b2892cd
Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
340
diff
changeset
|
110 // FALL THROUGH to return -1 indicating no cache information |
a0864b2892cd
Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
340
diff
changeset
|
111 } catch (NumberFormatException ex) { |
490
b3c16d1aede0
Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
456
diff
changeset
|
112 repo.getSessionContext().getLog().dump(getClass(), Warn, ex, null); |
348
a0864b2892cd
Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
340
diff
changeset
|
113 // FALL THROUGH |
354
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
114 } catch (HgInvalidControlFileException ex) { |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
115 // shall not happen, thus log as error |
490
b3c16d1aede0
Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
456
diff
changeset
|
116 repo.getSessionContext().getLog().dump(getClass(), Error, ex, null); |
354
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
117 // FALL THROUGH |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
118 } catch (HgInvalidRevisionException ex) { |
490
b3c16d1aede0
Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
456
diff
changeset
|
119 repo.getSessionContext().getLog().dump(getClass(), Error, ex, null); |
354
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
120 // FALL THROUGH |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
121 } finally { |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
122 if (br != null) { |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
123 try { |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
124 br.close(); |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
125 } catch (IOException ex) { |
490
b3c16d1aede0
Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
456
diff
changeset
|
126 repo.getSessionContext().getLog().dump(getClass(), Warn, ex, null); // ignore |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
127 } |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
128 } |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
129 } |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
130 return -1; // deliberately not lastInCache, to avoid anything but -1 when 1st line was read and there's error is in lines 2..end |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
131 } |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
132 |
366
189dc6dc1c3e
Use exceptions to expose errors reading mercurial data
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
354
diff
changeset
|
133 void collect(final ProgressSupport ps) throws HgInvalidControlFileException { |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
134 branches.clear(); |
610
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
490
diff
changeset
|
135 final HgRepository repo = internalRepo.getRepo(); |
220
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
136 ps.start(1 + repo.getChangelog().getRevisionCount() * 2); |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
137 // |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
138 int lastCached = readCache(); |
244
4b661efb9374
Use updated location of cache files (cache/ folder instead of .cache filename extension). Provide means to update (write down) cache for subsequent uses
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
139 isCacheActual = lastCached == repo.getChangelog().getLastRevision(); |
4b661efb9374
Use updated location of cache files (cache/ folder instead of .cache filename extension). Provide means to update (write down) cache for subsequent uses
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
140 if (!isCacheActual) { |
432
1fc0da631200
Revlog.ParentWalker helper class got promoted as TLC, renamed to HgParentChildMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
423
diff
changeset
|
141 final HgParentChildMap<HgChangelog> pw = new HgParentChildMap<HgChangelog>(repo.getChangelog()); |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
142 pw.init(); |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
143 ps.worked(repo.getChangelog().getRevisionCount()); |
308
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
144 // first revision branch found at |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
145 final HashMap<String, Nodeid> branchStart = new HashMap<String, Nodeid>(); |
308
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
146 // last revision seen for the branch |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
147 final HashMap<String, Nodeid> branchLastSeen = new HashMap<String, Nodeid>(); |
308
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
148 // revisions from the branch that have no children at all |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
149 final HashMap<String, List<Nodeid>> branchHeads = new HashMap<String, List<Nodeid>>(); |
309
962f78aac342
Branch with few children forked shall not ignore other children once one of them is processed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
308
diff
changeset
|
150 // revisions that are immediate children of a node from a given branch |
962f78aac342
Branch with few children forked shall not ignore other children once one of them is processed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
308
diff
changeset
|
151 // after iteration, there are some revisions left in this map (children of a branch last revision |
962f78aac342
Branch with few children forked shall not ignore other children once one of them is processed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
308
diff
changeset
|
152 // that doesn't belong to the branch. No use of this now, perhaps can deduce isInactive (e.g.those |
962f78aac342
Branch with few children forked shall not ignore other children once one of them is processed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
308
diff
changeset
|
153 // branches that have non-empty candidates are inactive if all their heads are roots for those left) |
308
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
154 final HashMap<String, List<Nodeid>> branchHeadCandidates = new HashMap<String, List<Nodeid>>(); |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
155 HgChangelog.Inspector insp = new HgChangelog.Inspector() { |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
156 |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
157 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) { |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
158 String branchName = cset.branch(); |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
159 if (!branchStart.containsKey(branchName)) { |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
160 branchStart.put(branchName, nodeid); |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
161 branchHeads.put(branchName, new LinkedList<Nodeid>()); |
308
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
162 branchHeadCandidates.put(branchName, new LinkedList<Nodeid>()); |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
163 } else { |
308
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
164 final List<Nodeid> headCandidates = branchHeadCandidates.get(branchName); |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
165 if (headCandidates.remove(nodeid)) { |
309
962f78aac342
Branch with few children forked shall not ignore other children once one of them is processed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
308
diff
changeset
|
166 // likely we don't need to keep parent anymore, as we found at least 1 child thereof to be at the same branch |
962f78aac342
Branch with few children forked shall not ignore other children once one of them is processed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
308
diff
changeset
|
167 // however, it's possible the child we found is a result of an earlier fork, and revision in the |
962f78aac342
Branch with few children forked shall not ignore other children once one of them is processed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
308
diff
changeset
|
168 // branchLastSeen is 'parallel' head, which needs to be kept |
962f78aac342
Branch with few children forked shall not ignore other children once one of them is processed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
308
diff
changeset
|
169 Nodeid lastSeenInBranch = branchLastSeen.get(branchName); |
962f78aac342
Branch with few children forked shall not ignore other children once one of them is processed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
308
diff
changeset
|
170 // check if current revision is on descendant line. Seems direct parents check is enough |
962f78aac342
Branch with few children forked shall not ignore other children once one of them is processed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
308
diff
changeset
|
171 if (pw.safeFirstParent(nodeid).equals(lastSeenInBranch) || pw.safeSecondParent(nodeid).equals(lastSeenInBranch)) { |
962f78aac342
Branch with few children forked shall not ignore other children once one of them is processed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
308
diff
changeset
|
172 branchLastSeen.remove(branchName); |
962f78aac342
Branch with few children forked shall not ignore other children once one of them is processed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
308
diff
changeset
|
173 } |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
174 } |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
175 } |
308
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
176 List<Nodeid> immediateChildren = pw.directChildren(nodeid); |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
177 if (immediateChildren.size() > 0) { |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
178 // 1) children may be in another branch |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
179 // and unless we later came across another element from this branch, |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
180 // we need to record all these as potential heads |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
181 // |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
182 // 2) head1 with children in different branch, and head2 in this branch without children |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
183 branchLastSeen.put(branchName, nodeid); |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
184 branchHeadCandidates.get(branchName).addAll(immediateChildren); |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
185 } else { |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
186 // no more children known for this node, it's (one of the) head of the branch |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
187 branchHeads.get(branchName).add(nodeid); |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
188 } |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
189 ps.worked(1); |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
190 } |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
191 }; |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
192 repo.getChangelog().range(lastCached == -1 ? 0 : lastCached+1, HgRepository.TIP, insp); |
308
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
193 // those last seen revisions from the branch that had no children from the same branch are heads. |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
194 for (String bn : branchLastSeen.keySet()) { |
308
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
195 // these are inactive branches? - there were children, but not from the same branch? |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
196 branchHeads.get(bn).add(branchLastSeen.get(bn)); |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
197 } |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
198 for (String bn : branchStart.keySet()) { |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
199 BranchInfo bi = branches.get(bn); |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
200 if (bi != null) { |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
201 // although heads from cache shall not intersect with heads after lastCached, |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
202 // use of LHS doesn't hurt (and makes sense e.g. if cache is not completely correct in my tests) |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
203 LinkedHashSet<Nodeid> heads = new LinkedHashSet<Nodeid>(bi.getHeads()); |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
204 for (Nodeid oldHead : bi.getHeads()) { |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
205 // XXX perhaps, need pw.canReach(Nodeid from, Collection<Nodeid> to) |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
206 List<Nodeid> newChildren = pw.childrenOf(Collections.singletonList(oldHead)); |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
207 if (!newChildren.isEmpty()) { |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
208 // likely not a head any longer, |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
209 // check if any new head can be reached from old one, and, if yes, |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
210 // do not consider that old head as head. |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
211 for (Nodeid newHead : branchHeads.get(bn)) { |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
212 if (newChildren.contains(newHead)) { |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
213 heads.remove(oldHead); |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
214 break; |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
215 } |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
216 } |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
217 } // else - oldHead still head for the branch |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
218 } |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
219 heads.addAll(branchHeads.get(bn)); |
308
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
220 bi = new BranchInfo(bn, bi.getStart(), heads.toArray(new Nodeid[0])); |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
221 } else { |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
222 Nodeid[] heads = branchHeads.get(bn).toArray(new Nodeid[0]); |
308
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
223 bi = new BranchInfo(bn, branchStart.get(bn), heads); |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
224 } |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
225 branches.put(bn, bi); |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
226 } |
220
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
227 } |
308
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
228 final HgChangelog clog = repo.getChangelog(); |
433
be697c3e951e
Revlog.RevisionMap helper class got promoted as TLC, renamed to HgRevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
432
diff
changeset
|
229 final HgRevisionMap<HgChangelog> rmap = new HgRevisionMap<HgChangelog>(clog).init(); |
308
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
230 for (BranchInfo bi : branches.values()) { |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
231 bi.validate(clog, rmap); |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
232 } |
610
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
490
diff
changeset
|
233 repoChangeTracker.touch(); |
220
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
234 ps.done(); |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
235 } |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
236 |
610
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
490
diff
changeset
|
237 public List<BranchInfo> getAllBranches() throws HgInvalidControlFileException { |
220
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
238 return new LinkedList<BranchInfo>(branches.values()); |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
239 |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
240 } |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
241 |
610
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
490
diff
changeset
|
242 public BranchInfo getBranch(String name) throws HgInvalidControlFileException { |
220
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
243 return branches.get(name); |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
244 } |
244
4b661efb9374
Use updated location of cache files (cache/ folder instead of .cache filename extension). Provide means to update (write down) cache for subsequent uses
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
245 |
4b661efb9374
Use updated location of cache files (cache/ folder instead of .cache filename extension). Provide means to update (write down) cache for subsequent uses
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
246 /** |
4b661efb9374
Use updated location of cache files (cache/ folder instead of .cache filename extension). Provide means to update (write down) cache for subsequent uses
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
247 * Writes down information about repository branches in a format Mercurial native client can understand. |
4b661efb9374
Use updated location of cache files (cache/ folder instead of .cache filename extension). Provide means to update (write down) cache for subsequent uses
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
248 * Cache file gets overwritten only if it is out of date (i.e. misses some branch information) |
354
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
249 * @throws IOException if write to cache file failed |
423
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
367
diff
changeset
|
250 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em> |
244
4b661efb9374
Use updated location of cache files (cache/ folder instead of .cache filename extension). Provide means to update (write down) cache for subsequent uses
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
251 */ |
4b661efb9374
Use updated location of cache files (cache/ folder instead of .cache filename extension). Provide means to update (write down) cache for subsequent uses
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
252 @Experimental(reason="Usage of cache isn't supposed to be public knowledge") |
423
9c9c442b5f2e
Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
367
diff
changeset
|
253 public void writeCache() throws IOException, HgRuntimeException { |
244
4b661efb9374
Use updated location of cache files (cache/ folder instead of .cache filename extension). Provide means to update (write down) cache for subsequent uses
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
254 if (isCacheActual) { |
4b661efb9374
Use updated location of cache files (cache/ folder instead of .cache filename extension). Provide means to update (write down) cache for subsequent uses
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
255 return; |
4b661efb9374
Use updated location of cache files (cache/ folder instead of .cache filename extension). Provide means to update (write down) cache for subsequent uses
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
256 } |
354
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
257 File branchheadsCache = getCacheFile(); |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
258 if (!branchheadsCache.exists()) { |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
259 branchheadsCache.getParentFile().mkdirs(); // just in case cache/ doesn't exist jet |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
260 branchheadsCache.createNewFile(); |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
261 } |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
262 if (!branchheadsCache.canWrite()) { |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
263 return; |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
264 } |
610
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
490
diff
changeset
|
265 final HgRepository repo = internalRepo.getRepo(); |
354
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
266 final int lastRev = repo.getChangelog().getLastRevision(); |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
267 final Nodeid lastNid = repo.getChangelog().getRevision(lastRev); |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
268 BufferedWriter bw = new BufferedWriter(new FileWriter(branchheadsCache)); |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
269 bw.write(lastNid.toString()); |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
270 bw.write((int) ' '); |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
271 bw.write(Integer.toString(lastRev)); |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
272 bw.write("\n"); |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
273 for (BranchInfo bi : branches.values()) { |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
274 for (Nodeid nid : bi.getHeads()) { |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
275 bw.write(nid.toString()); |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
276 bw.write((int) ' '); |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
277 bw.write(bi.getName()); |
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
278 bw.write("\n"); |
244
4b661efb9374
Use updated location of cache files (cache/ folder instead of .cache filename extension). Provide means to update (write down) cache for subsequent uses
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
279 } |
4b661efb9374
Use updated location of cache files (cache/ folder instead of .cache filename extension). Provide means to update (write down) cache for subsequent uses
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
280 } |
354
5f9073eabf06
Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
348
diff
changeset
|
281 bw.close(); |
244
4b661efb9374
Use updated location of cache files (cache/ folder instead of .cache filename extension). Provide means to update (write down) cache for subsequent uses
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
282 } |
4b661efb9374
Use updated location of cache files (cache/ folder instead of .cache filename extension). Provide means to update (write down) cache for subsequent uses
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
283 |
4b661efb9374
Use updated location of cache files (cache/ folder instead of .cache filename extension). Provide means to update (write down) cache for subsequent uses
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
284 private File getCacheFile() { |
4b661efb9374
Use updated location of cache files (cache/ folder instead of .cache filename extension). Provide means to update (write down) cache for subsequent uses
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
285 // prior to 1.8 used to be .hg/branchheads.cache |
490
b3c16d1aede0
Refactoring: move HgRepository's implementation aspects to Internals (which is now its imlementation counterpart and primary repository class to be used by other parts of the library)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
456
diff
changeset
|
286 return internalRepo.getFileFromRepoDir("cache/branchheads"); |
244
4b661efb9374
Use updated location of cache files (cache/ folder instead of .cache filename extension). Provide means to update (write down) cache for subsequent uses
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
287 } |
610
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
490
diff
changeset
|
288 |
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
490
diff
changeset
|
289 /*package-local*/ void reloadIfChanged(ProgressSupport ps) throws HgInvalidControlFileException { |
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
490
diff
changeset
|
290 if (repoChangeTracker.isChanged()) { |
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
490
diff
changeset
|
291 collect(ps); |
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
490
diff
changeset
|
292 } |
5c68567b3645
Refresh tags, branches, bookmarks and ignore when their files (or csets in the repo) are changed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
490
diff
changeset
|
293 } |
244
4b661efb9374
Use updated location of cache files (cache/ folder instead of .cache filename extension). Provide means to update (write down) cache for subsequent uses
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
236
diff
changeset
|
294 |
220
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
295 public static class BranchInfo { |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
296 private final String name; |
308
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
297 private List<Nodeid> heads; |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
298 private boolean closed; |
220
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
299 private final Nodeid start; |
315
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
300 private List<Nodeid> closedHeads; // subset of heads, those that bear 'closed' flag, or null if closed == true |
220
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
301 |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
302 // XXX in fact, few but not all branchHeads might be closed, and isClosed for whole branch is not |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
303 // possible to determine. |
308
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
304 BranchInfo(String branchName, Nodeid first, Nodeid[] branchHeads) { |
220
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
305 name = branchName; |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
306 start = first; |
308
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
307 heads = Arrays.asList(branchHeads); |
220
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
308 } |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
309 |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
310 // incomplete branch, there's not enough information at the time of creation. shall be replaced with |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
311 // proper BI in #collect() |
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
312 BranchInfo(String branchName, Nodeid[] branchHeads) { |
308
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
313 this(branchName, Nodeid.NULL, branchHeads); |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
314 } |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
315 |
433
be697c3e951e
Revlog.RevisionMap helper class got promoted as TLC, renamed to HgRevisionMap
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
432
diff
changeset
|
316 void validate(HgChangelog clog, HgRevisionMap<HgChangelog> rmap) throws HgInvalidControlFileException { |
308
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
317 int[] localCset = new int[heads.size()]; |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
318 int i = 0; |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
319 for (Nodeid h : heads) { |
367
2fadf8695f8a
Use 'revision index' instead of the vague 'local revision number' concept in the API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
366
diff
changeset
|
320 localCset[i++] = rmap.revisionIndex(h); |
308
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
321 } |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
322 // [0] tipmost, [1] tipmost open |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
323 final Nodeid[] tipmost = new Nodeid[] {null, null}; |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
324 final boolean[] allClosed = new boolean[] { true }; |
315
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
325 final ArrayList<Nodeid> _closedHeads = new ArrayList<Nodeid>(heads.size()); |
308
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
326 clog.range(new HgChangelog.Inspector() { |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
327 |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
328 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) { |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
329 assert heads.contains(nodeid); |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
330 tipmost[0] = nodeid; |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
331 if (!"1".equals(cset.extras().get("close"))) { |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
332 tipmost[1] = nodeid; |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
333 allClosed[0] = false; |
315
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
334 } else { |
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
335 _closedHeads.add(nodeid); |
308
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
336 } |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
337 } |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
338 }, localCset); |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
339 closed = allClosed[0]; |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
340 Nodeid[] outcome = new Nodeid[localCset.length]; |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
341 i = 0; |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
342 if (!closed && tipmost[1] != null) { |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
343 outcome[i++] = tipmost[1]; |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
344 if (i < outcome.length && !tipmost[0].equals(tipmost[1])) { |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
345 outcome[i++] = tipmost[0]; |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
346 } |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
347 } else { |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
348 outcome[i++] = tipmost[0]; |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
349 } |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
350 for (Nodeid h : heads) { |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
351 if (!h.equals(tipmost[0]) && !h.equals(tipmost[1])) { |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
352 outcome[i++] = h; |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
353 } |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
354 } |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
355 heads = Arrays.asList(outcome); |
315
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
356 if (closed) { |
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
357 // no need |
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
358 closedHeads = null; |
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
359 } else { |
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
360 _closedHeads.trimToSize(); |
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
361 closedHeads = _closedHeads; |
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
362 } |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
363 } |
220
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
364 |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
365 public String getName() { |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
366 return name; |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
367 } |
308
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
368 /** |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
369 * @return <code>true</code> if all heads of this branch are marked as closed |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
370 */ |
3f40262153a4
Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
371 public boolean isClosed() { |
220
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
372 return closed; |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
373 } |
315
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
374 |
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
375 /** |
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
376 * @return all heads for the branch, both open and closed, tip-most head first |
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
377 */ |
220
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
378 public List<Nodeid> getHeads() { |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
379 return heads; |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
380 } |
315
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
381 |
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
382 /** |
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
383 * |
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
384 * @param head one of revision from {@link #getHeads() heads} of this branch |
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
385 * @return true if this particular head is closed |
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
386 * @throws IllegalArgumentException if argument is not from {@link #getHeads() heads} of this branch |
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
387 */ |
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
388 public boolean isClosed(Nodeid head) { |
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
389 if (!heads.contains(head)) { |
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
390 throw new IllegalArgumentException(String.format("Revision %s does not belong to heads of %s branch", head, name), null); |
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
391 } |
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
392 if (closed) { |
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
393 return true; |
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
394 } |
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
395 return closedHeads.contains(head); |
8952f89be195
Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
309
diff
changeset
|
396 } |
220
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
397 // public Nodeid getTip() { |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
398 // } |
236
883300108179
Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
220
diff
changeset
|
399 /*public*/ Nodeid getStart() { |
220
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
400 // first node where branch appears |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
401 return start; |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
402 } |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
403 } |
8de327242aa0
Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
404 } |