Mercurial > hg4j
annotate src/org/tmatesoft/hg/internal/SubrepoManager.java @ 685:9897cbfd2790
Towards ssh remote repositories: use ganymed library for ssh transport
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 25 Jul 2013 21:32:09 +0200 |
parents | e4ee4bf4c7d0 |
children |
rev | line source |
---|---|
239
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
571
e4ee4bf4c7d0
Let session context control creation of Path instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
442
diff
changeset
|
2 * Copyright (c) 2011-2013 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); |
571
e4ee4bf4c7d0
Let session context control creation of Path instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
442
diff
changeset
|
84 final Path.Source pathFactory = repo.getSessionContext().getPathFactory(); |
239
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
85 while ((line = br.readLine()) != null) { |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
86 int sep = line.indexOf('='); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 if (sep == -1) { |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
88 continue; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
89 } |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
90 // 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
|
91 // to have separate String instances (new String(line.substring())) |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
92 String key = line.substring(0, sep).trim(); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
93 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
|
94 if (key.length() == 0 || value.length() == 0) { |
239
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
95 // XXX log bad line? |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 continue; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 } |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
98 HgSubrepoLocation.Kind kind = HgSubrepoLocation.Kind.Hg; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
99 int kindEnd = value.indexOf(']', 1); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
100 if (value.charAt(0) == '[' && kindEnd != -1) { |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
101 String kindStr = value.substring(1, kindEnd); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
102 value = value.substring(kindEnd + 1); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
103 if ("svn".equals(kindStr)) { |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
104 kind = HgSubrepoLocation.Kind.SVN; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
105 } else if ("git".equals(kindStr)) { |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
106 kind = HgSubrepoLocation.Kind.Git; |
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 } |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
109 // 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
|
110 // |
6865eb742883
Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
423
diff
changeset
|
111 // 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
|
112 // abort: path ends in directory separator: fourth/ |
571
e4ee4bf4c7d0
Let session context control creation of Path instances
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
442
diff
changeset
|
113 Path p = pathFactory.path(key.charAt(key.length()-1) == '/' ? key : key + '/'); |
442
6865eb742883
Tests for subrepo API, refactor status tests for reuse, better subrepos API
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
423
diff
changeset
|
114 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
|
115 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
|
116 res.add(loc); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
117 } |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
118 return Arrays.asList(res.toArray(new HgSubrepoLocation[res.size()])); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
119 } finally { |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
120 br.close(); |
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 |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
124 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
|
125 // 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
|
126 HashMap<String, String> rv = new HashMap<String, String>(); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
127 try { |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
128 String line; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
129 while ((line = br.readLine()) != null) { |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
130 int sep = line.trim().indexOf(' '); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
131 if (sep != -1) { |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
132 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
|
133 } |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
134 } |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
135 } finally { |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
136 br.close(); |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
137 } |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
138 return rv; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
139 } |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
140 |
348
a0864b2892cd
Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
141 /*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
|
142 public void read() throws HgInvalidControlFileException { |
a0864b2892cd
Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
143 subRepos = readActualState(); |
a0864b2892cd
Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
144 } |
a0864b2892cd
Expose errors reading mercurial control files with exception
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
295
diff
changeset
|
145 |
239
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
146 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
|
147 assert subRepos != null; |
239
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
148 return subRepos; |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
149 } |
df9d2854d3d6
Initial access to subrepositories
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
150 } |