annotate src/org/tmatesoft/hg/repo/HgBranches.java @ 703:7839ff0bfd78

Refactor: move diff/blame related code to a separate package
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 14 Aug 2013 14:51:51 +0200
parents af5223b86dd3
children
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.HashMap;
659
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
31 import java.util.Iterator;
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;
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
43 import org.tmatesoft.hg.internal.FileUtils;
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
44 import org.tmatesoft.hg.internal.Internals;
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
45 import org.tmatesoft.hg.repo.HgChangelog.RawChangeset;
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
46 import org.tmatesoft.hg.util.ProgressSupport;
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 /**
659
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
49 * Access information about branches in the repository
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
50 *
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
51 * @author Artem Tikhomirov
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
52 * @author TMate Software Ltd.
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
53 */
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
54 public class HgBranches {
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
55
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
56 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
57 private final ChangelogMonitor repoChangeTracker;
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
58 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
59 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
60
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
61 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
62 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
63 repoChangeTracker = new ChangelogMonitor(internals.getRepo());
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
64 }
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
65
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 340
diff changeset
66 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
67 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
68 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
69 int lastInCache = -1;
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
70 if (!branchheadsCache.canRead()) {
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
71 return lastInCache;
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
72 }
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
73 BufferedReader br = null; // TODO replace with LineReader
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
74 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
75 try {
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
76 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
77 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
78 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
79 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
80 return lastInCache;
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
81 }
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
82 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
83 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
84 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
85 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
86 // 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
87 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
88 }
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
89 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
90 String[] elements = spacePattern.split(line.trim());
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
91 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
92 // bad entry
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
93 continue;
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
94 }
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
95 // 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
96 String branchName = new String(elements[elements.length-1]);
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
97 List<Nodeid> heads = branchHeads.get(elements[1]);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
98 if (heads == null) {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
99 branchHeads.put(branchName, heads = new LinkedList<Nodeid>());
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 heads.add(Nodeid.fromAscii(elements[0]));
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
102 }
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
103 for (Map.Entry<String, List<Nodeid>> e : branchHeads.entrySet()) {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
104 Nodeid[] heads = e.getValue().toArray(new Nodeid[e.getValue().size()]);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
105 BranchInfo bi = new BranchInfo(e.getKey(), heads);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
106 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
107 }
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
108 return lastInCache;
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
109 } catch (IOException ex) {
348
a0864b2892cd Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 340
diff changeset
110 // 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
111 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
112 // 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
113 } 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
114 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
115 // FALL THROUGH
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
116 } catch (HgRuntimeException ex) {
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
117 // if happens, log error and pretend there's no 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
118 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
119 // FALL THROUGH
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
120 } finally {
654
12a4f60ea972 1) Console push tool. 2) Pass class to blame into FileUtils
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
121 new FileUtils(repo.getSessionContext().getLog(), this).closeQuietly(br);
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
122 }
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
123 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
124 }
656
a937e63b6e02 Performance: rebuild information about branches takes too long (my improvement: 3 times, 11-15 s to less than 4 sec)
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 654
diff changeset
125
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
126 void collect(final ProgressSupport ps) throws HgRuntimeException {
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
127 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
128 final HgRepository repo = internalRepo.getRepo();
659
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
129 final HgChangelog clog = repo.getChangelog();
657
6334b0267103 ParentChildMap can supply RevisionMap. Refactor ArrayHelper to keep most of sorted/reverse index magic inside
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 656
diff changeset
130 final HgRevisionMap<HgChangelog> rmap;
659
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
131 ps.start(1 + clog.getRevisionCount() * 2);
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
132 //
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
133 int lastCached = readCache();
659
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
134 isCacheActual = lastCached == clog.getLastRevision();
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
135 if (!isCacheActual) {
659
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
136 // XXX need a way to share HgParentChildMap<HgChangelog>
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
137 final HgParentChildMap<HgChangelog> pw = new HgParentChildMap<HgChangelog>(clog);
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
138 pw.init();
659
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
139 ps.worked(clog.getRevisionCount());
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
140 //
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
141 // 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
142 final HashMap<String, Nodeid> branchStart = new HashMap<String, Nodeid>();
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
143 // 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
144 final HashMap<String, List<Nodeid>> branchHeads = new HashMap<String, List<Nodeid>>();
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
145 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
146
659
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
147 private final ArrayList<Nodeid> parents = new ArrayList<Nodeid>(3);
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
148
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
149 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
150 String branchName = cset.branch();
659
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
151 List<Nodeid> _branchHeads;
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
152 // there are chances (with --force key) branch can get more than one start
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
153 // revision. Neither BranchInfo nor this code support this scenario at the moment.
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
154 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
155 branchStart.put(branchName, nodeid);
659
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
156 branchHeads.put(branchName, _branchHeads = 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
157 } else {
659
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
158 _branchHeads = branchHeads.get(branchName);
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
159 if (_branchHeads == null) {
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
160 branchHeads.put(branchName, _branchHeads = new LinkedList<Nodeid>());
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
161 }
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
162 }
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
163 // so far present node is the best candidate for head
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
164 _branchHeads.add(nodeid);
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
165 parents.clear();
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
166 // parents of this node, however, cease to be heads (if they are from this branch)
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
167 pw.appendParentsOf(nodeid, parents);
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
168 _branchHeads.removeAll(parents);
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
169 ps.worked(1);
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
170 }
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
171 };
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
172 // XXX alternatively may iterate with pw.all().subList(lastCached)
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
173 // but need an effective way to find out branch of particular changeset
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
174 clog.range(lastCached == -1 ? 0 : lastCached+1, HgRepository.TIP, insp);
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
175 //
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
176 // build BranchInfo, based on found and cached
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
177 for (String bn : branchStart.keySet()) {
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
178 BranchInfo bi = branches.get(bn);
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
179 if (bi != null) {
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
180 // combine heads found so far with those cached
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
181 LinkedHashSet<Nodeid> oldHeads = new LinkedHashSet<Nodeid>(bi.getHeads());
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
182 // expect size of both oldHeads and newHeads sets to be small, and for x for hence acceptable.
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
183 for (Nodeid newHead : branchHeads.get(bn)) {
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
184 for (Iterator<Nodeid> it = oldHeads.iterator(); it.hasNext();) {
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
185 if (pw.isChild(it.next(), newHead)) {
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
186 it.remove();
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
187 }
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
188 }
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
189 }
659
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
190 oldHeads.addAll(branchHeads.get(bn));
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
191 assert oldHeads.size() > 0;
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
192 bi = new BranchInfo(bn, bi.getStart(), oldHeads.toArray(new Nodeid[oldHeads.size()]));
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
193 } else {
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
194 Nodeid[] heads = branchHeads.get(bn).toArray(new Nodeid[0]);
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
195 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
196 }
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
197 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
198 }
657
6334b0267103 ParentChildMap can supply RevisionMap. Refactor ArrayHelper to keep most of sorted/reverse index magic inside
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 656
diff changeset
199 rmap = pw.getRevisionMap();
6334b0267103 ParentChildMap can supply RevisionMap. Refactor ArrayHelper to keep most of sorted/reverse index magic inside
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 656
diff changeset
200 } else { // !cacheActual
6334b0267103 ParentChildMap can supply RevisionMap. Refactor ArrayHelper to keep most of sorted/reverse index magic inside
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 656
diff changeset
201 rmap = new HgRevisionMap<HgChangelog>(clog).init();
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
202 }
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
203 for (BranchInfo bi : branches.values()) {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
204 bi.validate(clog, rmap);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
205 }
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
206 repoChangeTracker.touch();
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
207 ps.done();
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
208 }
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
209
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
210 public List<BranchInfo> getAllBranches() throws HgInvalidControlFileException {
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
211 return new LinkedList<BranchInfo>(branches.values());
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
212
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
213 }
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
214
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
215 public BranchInfo getBranch(String name) throws HgInvalidControlFileException {
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
216 return branches.get(name);
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
217 }
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
218
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
219 /**
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
220 * 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
221 * 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
222 * @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
223 * @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
224 */
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
225 @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
226 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
227 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
228 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
229 }
354
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
230 File branchheadsCache = getCacheFile();
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
231 if (!branchheadsCache.exists()) {
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
232 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
233 branchheadsCache.createNewFile();
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
234 }
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
235 if (!branchheadsCache.canWrite()) {
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
236 return;
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
237 }
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
238 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
239 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
240 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
241 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
242 bw.write(lastNid.toString());
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
243 bw.write((int) ' ');
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
244 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
245 bw.write("\n");
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
246 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
247 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
248 bw.write(nid.toString());
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
249 bw.write((int) ' ');
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
250 bw.write(bi.getName());
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
251 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
252 }
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
253 }
354
5f9073eabf06 Propagate errors with exceptions up to a end client
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 348
diff changeset
254 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
255 }
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
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
257 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
258 // prior to 1.8 used to be .hg/branchheads.cache
659
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
259 // since 2.5 there is filter suffix
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
260 File f = internalRepo.getFileFromRepoDir("cache/branchheads-base");
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
261 if (f.exists()) {
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
262 return f;
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
263 }
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
264 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
265 }
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
266
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
267 /*package-local*/ void reloadIfChanged(ProgressSupport ps) throws HgRuntimeException {
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
268 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
269 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
270 }
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
271 }
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
272
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
273 public static class BranchInfo {
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
274 private final String name;
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
275 private List<Nodeid> heads;
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
276 private boolean closed;
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
277 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
278 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
279
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
280 // 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
281 // possible to determine.
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
282 BranchInfo(String branchName, Nodeid first, Nodeid[] branchHeads) {
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
283 name = branchName;
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
284 start = first;
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
285 heads = Arrays.asList(branchHeads);
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
286 }
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
287
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
288 // 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
289 // 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
290 BranchInfo(String branchName, Nodeid[] branchHeads) {
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
291 this(branchName, Nodeid.NULL, branchHeads);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
292 }
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
293
628
6526d8adbc0f Explicit HgRuntimeException to facilitate easy switch from runtime to checked exceptions
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 610
diff changeset
294 void validate(HgChangelog clog, HgRevisionMap<HgChangelog> rmap) throws HgRuntimeException {
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
295 int[] localCset = new int[heads.size()];
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
296 int i = 0;
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
297 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
298 localCset[i++] = rmap.revisionIndex(h);
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
299 }
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
300 // [0] tipmost, [1] tipmost open
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
301 final Nodeid[] tipmost = new Nodeid[] {null, null};
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
302 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
303 final ArrayList<Nodeid> _closedHeads = new ArrayList<Nodeid>(heads.size());
308
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
304 clog.range(new HgChangelog.Inspector() {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
305
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
306 public void next(int revisionNumber, Nodeid nodeid, RawChangeset cset) {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
307 assert heads.contains(nodeid);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
308 tipmost[0] = nodeid;
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
309 if (!"1".equals(cset.extras().get("close"))) {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
310 tipmost[1] = nodeid;
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
311 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
312 } else {
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
313 _closedHeads.add(nodeid);
308
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 }
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
316 }, localCset);
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
317 closed = allClosed[0];
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
318 Nodeid[] outcome = new Nodeid[localCset.length];
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
319 i = 0;
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
320 if (!closed && tipmost[1] != null) {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
321 outcome[i++] = tipmost[1];
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
322 if (i < outcome.length && !tipmost[0].equals(tipmost[1])) {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
323 outcome[i++] = tipmost[0];
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
324 }
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
325 } else {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
326 outcome[i++] = tipmost[0];
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 for (Nodeid h : heads) {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
329 if (!h.equals(tipmost[0]) && !h.equals(tipmost[1])) {
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
330 outcome[i++] = h;
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
331 }
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
332 }
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
333 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
334 if (closed) {
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
335 // no need
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
336 closedHeads = null;
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
337 } else {
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
338 _closedHeads.trimToSize();
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
339 closedHeads = _closedHeads;
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
340 }
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
341 }
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
342
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
343 public String getName() {
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
344 return name;
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
345 }
308
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 * @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
348 */
3f40262153a4 Recognize closed branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 295
diff changeset
349 public boolean isClosed() {
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
350 return closed;
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
351 }
315
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
352
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
353 /**
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
354 * @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
355 */
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
356 public List<Nodeid> getHeads() {
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
357 return heads;
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
358 }
315
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
359
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
360 /**
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
361 *
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
362 * @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
363 * @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
364 * @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
365 */
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
366 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
367 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
368 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
369 }
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
370 if (closed) {
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
371 return true;
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
372 }
8952f89be195 Allow to query specific branch heads if they are closed
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 309
diff changeset
373 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
374 }
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
375 // public Nodeid getTip() {
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
376 // }
659
a5cf64f2e7e4 Poor performance when reading/collecting branch information. Respect new cache location for recent mercurial revisions. Use different algorithm to build branch cache
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 628
diff changeset
377 // XXX Not public as there are chances for few possible branch starts, and I need to decide how to handle that
236
883300108179 Speed up branches calculation when cached branch information is available
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents: 220
diff changeset
378 /*public*/ Nodeid getStart() {
220
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
379 // first node where branch appears
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
380 return start;
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 }
8de327242aa0 Basic information about branches
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff changeset
383 }