annotate src/org/tmatesoft/hg/repo/HgBranches.java @ 311:b9592e21176a

Tests for array sort and reverse index building helper
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 26 Sep 2011 04:06:04 +0200
parents 962f78aac342
children 8952f89be195
rev   line source
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
1 /*
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2011 TMate Software Ltd
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
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
19 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
20 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
21 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
22 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
23 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
24 import java.io.IOException;
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
25 import java.util.Arrays;
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
26 import java.util.Collections;
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
27 import java.util.HashMap;
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
28 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
29 import java.util.LinkedHashSet;
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
30 import java.util.LinkedList;
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
31 import java.util.List;
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
32 import java.util.Map;
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
33 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
34 import java.util.regex.Pattern;
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
35
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
36 import org.tmatesoft.hg.core.Nodeid;
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
37 import org.tmatesoft.hg.internal.Experimental;
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
38 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset;
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
39 import org.tmatesoft.hg.util.ProgressSupport;
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
40
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
41 /**
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
42 *
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
43 * @author Artem Tikhomirov
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
44 * @author TMate Software Ltd.
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 */
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 public class HgBranches {
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 private final Map<String, BranchInfo> branches = new TreeMap<String, BranchInfo>();
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
49 private final HgRepository repo;
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
50 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
51
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 HgBranches(HgRepository hgRepo) {
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 repo = hgRepo;
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 }
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
56 private int 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
57 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
58 int lastInCache = -1;
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
59 if (!branchheadsCache.canRead()) {
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
60 return lastInCache;
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
61 }
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
62 BufferedReader br = null;
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
63 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
64 try {
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
65 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
66 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
67 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
68 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
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 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
72 lastInCache = Integer.parseInt(cacheIdentity[1]);
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
73 // XXX may want to check if nodeid of cset from repo.getChangelog() of lastInCache index match cacheIdentity[0]
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
74 //
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
75 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
76 String[] elements = spacePattern.split(line.trim());
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
77 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
78 // bad entry
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
79 continue;
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
80 }
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
81 // 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
82 String branchName = new String(elements[elements.length-1]);
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
83 List<Nodeid> heads = branchHeads.get(elements[1]);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
84 if (heads == null) {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
85 branchHeads.put(branchName, heads = new LinkedList<Nodeid>());
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
86 }
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
87 heads.add(Nodeid.fromAscii(elements[0]));
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
88 }
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
89 for (Map.Entry<String, List<Nodeid>> e : branchHeads.entrySet()) {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
90 Nodeid[] heads = e.getValue().toArray(new Nodeid[e.getValue().size()]);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
91 BranchInfo bi = new BranchInfo(e.getKey(), heads);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
92 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
93 }
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
94 return lastInCache;
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
95 } catch (IOException ex) {
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 244
diff changeset
96 repo.getContext().getLog().warn(getClass(), ex, null); // log error, but otherwise do nothing
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
97 } finally {
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
98 if (br != null) {
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
99 try {
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
100 br.close();
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
101 } catch (IOException ex) {
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 244
diff changeset
102 repo.getContext().getLog().info(getClass(), 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
103 }
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
104 }
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 -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
107 }
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
108
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
109 void collect(final ProgressSupport ps) {
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
110 branches.clear();
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
111 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
112 //
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
113 int lastCached = readCache();
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
114 /*
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
115 * Next code was supposed to fill missing aspects of the BranchInfo, but is too slow
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
116 *
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
117 if (lastCached != -1 && lastCached <= repo.getChangelog().getLastRevision()) {
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
118 LinkedList<BranchInfo> incompleteBranches = new LinkedList<HgBranches.BranchInfo>(branches.values());
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
119 for (BranchInfo bi : incompleteBranches) {
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
120 LinkedList<Nodeid> closedHeads = new LinkedList<Nodeid>();
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
121 for (Nodeid h : bi.getHeads()) {
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
122 if ("1".equals(repo.getChangelog().changeset(h).extras().get("close"))) {
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
123 closedHeads.add(h);
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
124 }
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
125 }
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
126 HashSet<Nodeid> earliest = new HashSet<Nodeid>(bi.getHeads());
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
127 HashSet<Nodeid> visited = new HashSet<Nodeid>();
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
128 ArrayList<Nodeid> parents = new ArrayList<Nodeid>(2);
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
129 HashSet<Nodeid> candidate = new HashSet<Nodeid>();
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
130 do {
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
131 candidate.clear();
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
132 for (Nodeid e : earliest) {
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
133 parents.clear();
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
134 if (pw.appendParentsOf(e, parents)) {
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
135 // at least one parent
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
136 Nodeid p1 = parents.get(0);
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
137 if (p1 != null && !visited.contains(p1) && bi.getName().equals(repo.getChangelog().changeset(p1).branch())) {
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
138 visited.add(p1);
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
139 candidate.add(p1);
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
140 }
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
141 Nodeid p2 = parents.size() > 1 ? parents.get(1) : null;
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
142 if (p2 != null && !visited.contains(p2) && bi.getName().equals(repo.getChangelog().changeset(p2).branch())) {
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
143 visited.add(p2);
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
144 candidate.add(p2);
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
145 }
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
146 }
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
147 }
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
148 if (!candidate.isEmpty()) {
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
149 earliest.clear();
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
150 earliest.addAll(candidate);
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
151 }
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
152 } while (!candidate.isEmpty());
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
153 // earliest can't be empty, we've started with non-empty heads.
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
154 Nodeid first = null;
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
155 if (earliest.size() == 1) {
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
156 first = earliest.iterator().next();
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
157 } else {
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
158 int earliestRevNum = Integer.MAX_VALUE;
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
159 for (Nodeid e : earliest) {
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
160 int x = repo.getChangelog().getLocalRevision(e);
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
161 if (x < earliestRevNum) {
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
162 earliestRevNum = x;
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
163 first = e;
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
164 }
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
165 }
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
166 }
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
167 assert first != null;
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
168 System.out.println("Updated branch " + bi.getName());
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
169 branches.put(bi.getName(), new BranchInfo(bi.getName(), first, bi.getHeads().toArray(new Nodeid[0]), closedHeads.size() == bi.getHeads().size()));
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
170 }
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
171 }
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
172 */
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
173 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
174 if (!isCacheActual) {
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
175 final HgChangelog.ParentWalker pw = repo.getChangelog().new ParentWalker();
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
176 pw.init();
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
177 ps.worked(repo.getChangelog().getRevisionCount());
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
178 // 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
179 final HashMap<String, Nodeid> branchStart = new HashMap<String, Nodeid>();
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
180 // 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
181 final HashMap<String, Nodeid> branchLastSeen = new HashMap<String, Nodeid>();
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
182 // 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
183 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
184 // 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
185 // 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
186 // 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
187 // 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
188 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
189 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
190
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
191 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
192 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
193 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
194 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
195 branchHeads.put(branchName, new LinkedList<Nodeid>());
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
196 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
197 } else {
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
198 final List<Nodeid> headCandidates = branchHeadCandidates.get(branchName);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
199 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
200 // 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
201 // 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
202 // 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
203 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
204 // 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
205 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
206 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
207 }
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
208 }
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
209 }
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
210 List<Nodeid> immediateChildren = pw.directChildren(nodeid);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
211 if (immediateChildren.size() > 0) {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
212 // 1) children may be in another branch
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
213 // 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
214 // we need to record all these as potential heads
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
215 //
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
216 // 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
217 branchLastSeen.put(branchName, nodeid);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
218 branchHeadCandidates.get(branchName).addAll(immediateChildren);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
219 } else {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
220 // 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
221 branchHeads.get(branchName).add(nodeid);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
222 }
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
223 ps.worked(1);
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 };
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
226 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
227 // 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
228 for (String bn : branchLastSeen.keySet()) {
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
229 // 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
230 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
231 }
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
232 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
233 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
234 if (bi != null) {
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
235 // 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
236 // 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
237 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
238 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
239 // 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
240 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
241 if (!newChildren.isEmpty()) {
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
242 // 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
243 // 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
244 // 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
245 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
246 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
247 heads.remove(oldHead);
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
248 break;
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
249 }
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
250 }
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
251 } // 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
252 }
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
253 heads.addAll(branchHeads.get(bn));
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
254 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
255 } else {
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
256 Nodeid[] heads = branchHeads.get(bn).toArray(new Nodeid[0]);
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
257 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
258 }
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
259 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
260 }
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
261 }
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
262 final HgChangelog clog = repo.getChangelog();
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
263 final HgChangelog.RevisionMap rmap = clog.new RevisionMap().init();
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
264 for (BranchInfo bi : branches.values()) {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
265 bi.validate(clog, rmap);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
266 }
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
267 ps.done();
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
268 }
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
269
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
270 public List<BranchInfo> getAllBranches() {
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
271 return new LinkedList<BranchInfo>(branches.values());
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
272
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
273 }
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
274
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
275 public BranchInfo getBranch(String name) {
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
276 return branches.get(name);
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
277 }
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
278
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 * 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
281 * Cache file gets overwritten only if it is out of date (i.e. misses some branch information)
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 @Experimental(reason="Usage of cache isn't supposed to be public knowledge")
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 public void writeCache() {
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 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
286 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
287 }
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
288 try {
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
289 File branchheadsCache = 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
290 if (!branchheadsCache.exists()) {
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
291 branchheadsCache.getParentFile().mkdirs(); // just in case cache/ doesn't exist jet
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
292 branchheadsCache.createNewFile();
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
293 }
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 if (!branchheadsCache.canWrite()) {
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
295 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
296 }
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
297 final int lastRev = 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
298 final Nodeid lastNid = repo.getChangelog().getRevision(lastRev);
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
299 BufferedWriter bw = new BufferedWriter(new FileWriter(branchheadsCache));
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
300 bw.write(lastNid.toString());
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
301 bw.write((int) ' ');
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
302 bw.write(Integer.toString(lastRev));
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
303 bw.write("\n");
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
304 for (BranchInfo bi : branches.values()) {
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
305 for (Nodeid nid : bi.getHeads()) {
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
306 bw.write(nid.toString());
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
307 bw.write((int) ' ');
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
308 bw.write(bi.getName());
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
309 bw.write("\n");
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
310 }
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
311 }
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
312 bw.close();
295
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 244
diff changeset
313 } catch (IOException ex) {
981f9f50bb6c Issue 11: Error log facility. SessionContext to share common facilities
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 244
diff changeset
314 repo.getContext().getLog().error(getClass(), ex, "Error writing branch cache file");
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
315 }
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
316 }
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
317
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
318 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
319 // prior to 1.8 used to be .hg/branchheads.cache
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
320 return new File(repo.getRepositoryRoot(), "cache/branchheads");
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
321 }
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
322
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
323 public static class BranchInfo {
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
324 private final String name;
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
325 private List<Nodeid> heads;
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
326 private boolean closed;
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
327 private final Nodeid start;
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
328
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
329 // 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
330 // possible to determine.
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
331 BranchInfo(String branchName, Nodeid first, Nodeid[] branchHeads) {
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
332 name = branchName;
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
333 start = first;
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
334 heads = Arrays.asList(branchHeads);
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
335 }
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
336
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
337 // 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
338 // 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
339 BranchInfo(String branchName, Nodeid[] branchHeads) {
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
340 this(branchName, Nodeid.NULL, branchHeads);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
341 }
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
342
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
343 void validate(HgChangelog clog, HgChangelog.RevisionMap rmap) {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
344 int[] localCset = new int[heads.size()];
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
345 int i = 0;
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
346 for (Nodeid h : heads) {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
347 localCset[i++] = rmap.localRevision(h);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
348 }
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
349 // [0] tipmost, [1] tipmost open
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
350 final Nodeid[] tipmost = new Nodeid[] {null, null};
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
351 final boolean[] allClosed = new boolean[] { true };
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
352 clog.range(new HgChangelog.Inspector() {
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 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
355 assert heads.contains(nodeid);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
356 tipmost[0] = nodeid;
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
357 if (!"1".equals(cset.extras().get("close"))) {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
358 tipmost[1] = nodeid;
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
359 allClosed[0] = false;
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
360 }
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
361 }
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
362 }, localCset);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
363 closed = allClosed[0];
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
364 Nodeid[] outcome = new Nodeid[localCset.length];
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
365 i = 0;
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
366 if (!closed && tipmost[1] != null) {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
367 outcome[i++] = tipmost[1];
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
368 if (i < outcome.length && !tipmost[0].equals(tipmost[1])) {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
369 outcome[i++] = tipmost[0];
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 } else {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
372 outcome[i++] = tipmost[0];
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
373 }
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
374 for (Nodeid h : heads) {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
375 if (!h.equals(tipmost[0]) && !h.equals(tipmost[1])) {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
376 outcome[i++] = h;
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
377 }
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
378 }
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
379 heads = Arrays.asList(outcome);
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
380 }
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
381
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
382 public String getName() {
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
383 return name;
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
384 }
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
385 /**
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
386 * @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
387 */
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
388 public boolean isClosed() {
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
389 return closed;
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
390 }
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
391 public List<Nodeid> getHeads() {
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
392 return heads;
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
393 }
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
394 // public Nodeid getTip() {
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
395 // }
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
396 /*public*/ Nodeid getStart() {
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
397 // first node where branch appears
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
398 return start;
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
399 }
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
400 }
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
401 }