Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/SubrepoManager.java @ 442:6865eb742883
Tests for subrepo API, refactor status tests for reuse, better subrepos API
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Fri, 27 Apr 2012 20:57:20 +0200 |
parents | 9c9c442b5f2e |
children | e4ee4bf4c7d0 |
comparison
equal
deleted
inserted
replaced
441:2a08466838d3 | 442:6865eb742883 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2011 TMate Software Ltd | 2 * Copyright (c) 2011-2012 TMate Software Ltd |
3 * | 3 * |
4 * This program is free software; you can redistribute it and/or modify | 4 * This program is free software; you can redistribute it and/or modify |
5 * it under the terms of the GNU General Public License as published by | 5 * it under the terms of the GNU General Public License as published by |
6 * the Free Software Foundation; version 2 of the License. | 6 * the Free Software Foundation; version 2 of the License. |
7 * | 7 * |
25 import java.util.HashMap; | 25 import java.util.HashMap; |
26 import java.util.LinkedList; | 26 import java.util.LinkedList; |
27 import java.util.List; | 27 import java.util.List; |
28 import java.util.Map; | 28 import java.util.Map; |
29 | 29 |
30 import org.tmatesoft.hg.core.Nodeid; | |
31 import org.tmatesoft.hg.repo.HgInternals; | |
30 import org.tmatesoft.hg.repo.HgInvalidControlFileException; | 32 import org.tmatesoft.hg.repo.HgInvalidControlFileException; |
31 import org.tmatesoft.hg.repo.HgRepository; | 33 import org.tmatesoft.hg.repo.HgRepository; |
32 import org.tmatesoft.hg.repo.HgSubrepoLocation; | 34 import org.tmatesoft.hg.repo.HgSubrepoLocation; |
35 import org.tmatesoft.hg.util.Path; | |
33 | 36 |
34 /** | 37 /** |
35 * | 38 * |
39 * @see http://mercurial.selenic.com/wiki/SubrepoWork | |
40 * @see http://mercurial.selenic.com/wiki/Subrepository | |
36 * @author Artem Tikhomirov | 41 * @author Artem Tikhomirov |
37 * @author TMate Software Ltd. | 42 * @author TMate Software Ltd. |
38 */ | 43 */ |
39 public class SubrepoManager /* XXX RepoChangeNotifier, RepoChangeListener */{ | 44 public class SubrepoManager /* XXX RepoChangeNotifier, RepoChangeListener */{ |
40 | 45 |
73 | 78 |
74 private List<HgSubrepoLocation> readConfig(BufferedReader br, Map<String, String> substate) throws IOException { | 79 private List<HgSubrepoLocation> readConfig(BufferedReader br, Map<String, String> substate) throws IOException { |
75 try { | 80 try { |
76 String line; | 81 String line; |
77 LinkedList<HgSubrepoLocation> res = new LinkedList<HgSubrepoLocation>(); | 82 LinkedList<HgSubrepoLocation> res = new LinkedList<HgSubrepoLocation>(); |
83 HgInternals hgRepoInternal = new HgInternals(repo); | |
78 while ((line = br.readLine()) != null) { | 84 while ((line = br.readLine()) != null) { |
79 int sep = line.indexOf('='); | 85 int sep = line.indexOf('='); |
80 if (sep == -1) { | 86 if (sep == -1) { |
81 continue; | 87 continue; |
82 } | 88 } |
83 // since both key and value are referenced from HgSubrepoLocation, doesn't make sense | 89 // since both key and value are referenced from HgSubrepoLocation, doesn't make sense |
84 // to have separate String instances (new String(line.substring())) | 90 // to have separate String instances (new String(line.substring())) |
85 String key = line.substring(0, sep).trim(); | 91 String key = line.substring(0, sep).trim(); |
86 String value = line.substring(sep + 1).trim(); | 92 String value = line.substring(sep + 1).trim(); |
87 if (value.length() == 0) { | 93 if (key.length() == 0 || value.length() == 0) { |
88 // XXX log bad line? | 94 // XXX log bad line? |
89 continue; | 95 continue; |
90 } | 96 } |
91 HgSubrepoLocation.Kind kind = HgSubrepoLocation.Kind.Hg; | 97 HgSubrepoLocation.Kind kind = HgSubrepoLocation.Kind.Hg; |
92 int kindEnd = value.indexOf(']', 1); | 98 int kindEnd = value.indexOf(']', 1); |
98 } else if ("git".equals(kindStr)) { | 104 } else if ("git".equals(kindStr)) { |
99 kind = HgSubrepoLocation.Kind.Git; | 105 kind = HgSubrepoLocation.Kind.Git; |
100 } | 106 } |
101 } | 107 } |
102 // TODO respect paths mappings in config file | 108 // TODO respect paths mappings in config file |
103 HgSubrepoLocation loc = new HgSubrepoLocation(repo, key, value, kind, substate.get(key)); | 109 // |
110 // apparently, key value can't end with '/', `hg commit` fails if it does: | |
111 // abort: path ends in directory separator: fourth/ | |
112 Path p = Path.create(key.charAt(key.length()-1) == '/' ? key : key + '/'); | |
113 String revValue = substate.get(key); | |
114 HgSubrepoLocation loc = hgRepoInternal.newSubrepo(p, value, kind, revValue == null ? null : Nodeid.fromAscii(revValue)); | |
104 res.add(loc); | 115 res.add(loc); |
105 } | 116 } |
106 return Arrays.asList(res.toArray(new HgSubrepoLocation[res.size()])); | 117 return Arrays.asList(res.toArray(new HgSubrepoLocation[res.size()])); |
107 } finally { | 118 } finally { |
108 br.close(); | 119 br.close(); |
109 } | 120 } |
110 } | 121 } |
111 | 122 |
112 private Map<String, String> readState(BufferedReader br) throws IOException { | 123 private Map<String, String> readState(BufferedReader br) throws IOException { |
124 // TODO reuse for other files with <revision><space><value> format, like .hgtags | |
113 HashMap<String, String> rv = new HashMap<String, String>(); | 125 HashMap<String, String> rv = new HashMap<String, String>(); |
114 try { | 126 try { |
115 String line; | 127 String line; |
116 while ((line = br.readLine()) != null) { | 128 while ((line = br.readLine()) != null) { |
117 int sep = line.trim().indexOf(' '); | 129 int sep = line.trim().indexOf(' '); |