Mercurial > hg4j
annotate src/org/tmatesoft/hg/internal/SubrepoManager.java @ 551:4ea0351ca878
Better (precise) name for diff facility, tests
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 20 Feb 2013 18:19:52 +0100 |
parents | 6865eb742883 |
children | e4ee4bf4c7d0 |
rev | line source |
---|---|
239
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
442
6865eb742883
Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
423
diff
changeset
|
2 * Copyright (c) 2011-2012 TMate Software Ltd |
239
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.internal; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import java.io.BufferedReader; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 import java.io.File; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 import java.io.FileReader; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 import java.io.IOException; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
23 import java.util.Arrays; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 import java.util.Collections; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 import java.util.HashMap; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
26 import java.util.LinkedList; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
27 import java.util.List; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
28 import java.util.Map; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 |
442
6865eb742883
Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
423
diff
changeset
|
30 import org.tmatesoft.hg.core.Nodeid; |
6865eb742883
Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
423
diff
changeset
|
31 import org.tmatesoft.hg.repo.HgInternals; |
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:
348
diff
changeset
|
32 import org.tmatesoft.hg.repo.HgInvalidControlFileException; |
239
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 import org.tmatesoft.hg.repo.HgRepository; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 import org.tmatesoft.hg.repo.HgSubrepoLocation; |
442
6865eb742883
Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
423
diff
changeset
|
35 import org.tmatesoft.hg.util.Path; |
239
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 /** |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 * |
442
6865eb742883
Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
423
diff
changeset
|
39 * @see http://mercurial.selenic.com/wiki/SubrepoWork |
6865eb742883
Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
423
diff
changeset
|
40 * @see http://mercurial.selenic.com/wiki/Subrepository |
239
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 * @author Artem Tikhomirov |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 * @author TMate Software Ltd. |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 */ |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 public class SubrepoManager /* XXX RepoChangeNotifier, RepoChangeListener */{ |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 private final HgRepository repo; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 private List<HgSubrepoLocation> subRepos; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 public SubrepoManager(HgRepository hgRepo) { |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 assert hgRepo != null; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 repo = hgRepo; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 } |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 |
348
a0864b2892cd
Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
54 private List<HgSubrepoLocation> readActualState() throws HgInvalidControlFileException { |
239
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 File hgsubFile = new File(repo.getWorkingDir(), ".hgsub"); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 if (!hgsubFile.canRead()) { |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
57 return Collections.emptyList(); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 } |
348
a0864b2892cd
Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
59 Map<String, String> state; // path -> revision |
a0864b2892cd
Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
60 File hgstateFile = null; |
239
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 try { |
348
a0864b2892cd
Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
62 hgstateFile = new File(repo.getWorkingDir(), ".hgsubstate"); |
239
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 if (hgstateFile.canRead()) { |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 state = readState(new BufferedReader(new FileReader(hgstateFile))); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
65 } else { |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
66 state = Collections.emptyMap(); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
67 } |
348
a0864b2892cd
Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
68 } catch (IOException ex) { |
a0864b2892cd
Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
69 throw new HgInvalidControlFileException("Subrepo state read failed", ex, hgstateFile); |
a0864b2892cd
Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
70 } |
a0864b2892cd
Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
71 try { |
239
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 BufferedReader br = new BufferedReader(new FileReader(hgsubFile)); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
73 return readConfig(br, state); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 } catch (IOException ex) { |
348
a0864b2892cd
Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
75 throw new HgInvalidControlFileException("Subrepo state read failed", ex, hgsubFile); |
239
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 } |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
77 } |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 private List<HgSubrepoLocation> readConfig(BufferedReader br, Map<String, String> substate) throws IOException { |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 try { |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 String line; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 LinkedList<HgSubrepoLocation> res = new LinkedList<HgSubrepoLocation>(); |
442
6865eb742883
Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
423
diff
changeset
|
83 HgInternals hgRepoInternal = new HgInternals(repo); |
239
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 while ((line = br.readLine()) != null) { |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
85 int sep = line.indexOf('='); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
86 if (sep == -1) { |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 continue; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
88 } |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
89 // since both key and value are referenced from HgSubrepoLocation, doesn't make sense |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
90 // to have separate String instances (new String(line.substring())) |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
91 String key = line.substring(0, sep).trim(); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
92 String value = line.substring(sep + 1).trim(); |
442
6865eb742883
Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
423
diff
changeset
|
93 if (key.length() == 0 || value.length() == 0) { |
239
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
94 // XXX log bad line? |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
95 continue; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 } |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 HgSubrepoLocation.Kind kind = HgSubrepoLocation.Kind.Hg; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
98 int kindEnd = value.indexOf(']', 1); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
99 if (value.charAt(0) == '[' && kindEnd != -1) { |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
100 String kindStr = value.substring(1, kindEnd); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
101 value = value.substring(kindEnd + 1); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
102 if ("svn".equals(kindStr)) { |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
103 kind = HgSubrepoLocation.Kind.SVN; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
104 } else if ("git".equals(kindStr)) { |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
105 kind = HgSubrepoLocation.Kind.Git; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
106 } |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
107 } |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
108 // TODO respect paths mappings in config file |
442
6865eb742883
Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
423
diff
changeset
|
109 // |
6865eb742883
Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
423
diff
changeset
|
110 // apparently, key value can't end with '/', `hg commit` fails if it does: |
6865eb742883
Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
423
diff
changeset
|
111 // abort: path ends in directory separator: fourth/ |
6865eb742883
Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
423
diff
changeset
|
112 Path p = Path.create(key.charAt(key.length()-1) == '/' ? key : key + '/'); |
6865eb742883
Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
423
diff
changeset
|
113 String revValue = substate.get(key); |
6865eb742883
Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
423
diff
changeset
|
114 HgSubrepoLocation loc = hgRepoInternal.newSubrepo(p, value, kind, revValue == null ? null : Nodeid.fromAscii(revValue)); |
239
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
115 res.add(loc); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
116 } |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
117 return Arrays.asList(res.toArray(new HgSubrepoLocation[res.size()])); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
118 } finally { |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
119 br.close(); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
120 } |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
121 } |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
122 |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
123 private Map<String, String> readState(BufferedReader br) throws IOException { |
442
6865eb742883
Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
423
diff
changeset
|
124 // TODO reuse for other files with <revision><space><value> format, like .hgtags |
239
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
125 HashMap<String, String> rv = new HashMap<String, String>(); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
126 try { |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
127 String line; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
128 while ((line = br.readLine()) != null) { |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
129 int sep = line.trim().indexOf(' '); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
130 if (sep != -1) { |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
131 rv.put(line.substring(sep+1).trim(), line.substring(0, sep).trim()); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
132 } |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
133 } |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
134 } finally { |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
135 br.close(); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
136 } |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
137 return rv; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
138 } |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
139 |
348
a0864b2892cd
Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
140 /*public to allow access from HgRepository, otherwise package-local*/ |
a0864b2892cd
Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
141 public void read() throws HgInvalidControlFileException { |
a0864b2892cd
Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
142 subRepos = readActualState(); |
a0864b2892cd
Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
143 } |
a0864b2892cd
Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
144 |
239
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
145 public List<HgSubrepoLocation> all(/*int revision, or TIP|WC*/) { |
348
a0864b2892cd
Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
146 assert subRepos != null; |
239
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
147 return subRepos; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
148 } |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
149 } |