Mercurial > jhg
comparison src/org/tmatesoft/hg/repo/HgMergeState.java @ 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)
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 16 Aug 2012 17:08:34 +0200 |
parents | 12f668401613 |
children | 6526d8adbc0f |
comparison
equal
deleted
inserted
replaced
489:9c0138cda59a | 490:b3c16d1aede0 |
---|---|
27 import java.util.Collections; | 27 import java.util.Collections; |
28 import java.util.List; | 28 import java.util.List; |
29 | 29 |
30 import org.tmatesoft.hg.core.HgFileRevision; | 30 import org.tmatesoft.hg.core.HgFileRevision; |
31 import org.tmatesoft.hg.core.Nodeid; | 31 import org.tmatesoft.hg.core.Nodeid; |
32 import org.tmatesoft.hg.internal.Internals; | |
32 import org.tmatesoft.hg.internal.ManifestRevision; | 33 import org.tmatesoft.hg.internal.ManifestRevision; |
33 import org.tmatesoft.hg.internal.Pool; | 34 import org.tmatesoft.hg.internal.Pool; |
34 import org.tmatesoft.hg.util.Pair; | 35 import org.tmatesoft.hg.util.Pair; |
35 import org.tmatesoft.hg.util.Path; | 36 import org.tmatesoft.hg.util.Path; |
36 import org.tmatesoft.hg.util.PathRewrite; | 37 import org.tmatesoft.hg.util.PathRewrite; |
81 public HgFileRevision getCommonAncestor() { | 82 public HgFileRevision getCommonAncestor() { |
82 return ancestor; | 83 return ancestor; |
83 } | 84 } |
84 } | 85 } |
85 | 86 |
86 private final HgRepository repo; | 87 private final Internals repo; |
87 private Entry[] entries; | 88 private Entry[] entries; |
88 | 89 |
89 HgMergeState(HgRepository hgRepo) { | 90 HgMergeState(Internals internalRepo) { |
90 repo = hgRepo; | 91 repo = internalRepo; |
91 } | 92 } |
92 | 93 |
93 /** | 94 /** |
94 * Update our knowledge about repository's merge state | 95 * Update our knowledge about repository's merge state |
95 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em> | 96 * @throws HgRuntimeException subclass thereof to indicate issues with the library. <em>Runtime exception</em> |
96 */ | 97 */ |
97 public void refresh() throws HgRuntimeException { | 98 public void refresh() throws HgRuntimeException { |
99 final HgRepository hgRepo = repo.getRepo(); | |
98 entries = null; | 100 entries = null; |
99 // it's possible there are two parents but no merge/state, we shall report this case as 'merging', with proper | 101 // it's possible there are two parents but no merge/state, we shall report this case as 'merging', with proper |
100 // first and second parent values | 102 // first and second parent values |
101 stateParent = Nodeid.NULL; | 103 stateParent = Nodeid.NULL; |
102 Pool<Nodeid> nodeidPool = new Pool<Nodeid>(); | 104 Pool<Nodeid> nodeidPool = new Pool<Nodeid>(); |
103 Pool<Path> fnamePool = new Pool<Path>(); | 105 Pool<Path> fnamePool = new Pool<Path>(); |
104 Pair<Nodeid, Nodeid> wcParents = repo.getWorkingCopyParents(); | 106 Pair<Nodeid, Nodeid> wcParents = hgRepo.getWorkingCopyParents(); |
105 wcp1 = nodeidPool.unify(wcParents.first()); wcp2 = nodeidPool.unify(wcParents.second()); | 107 wcp1 = nodeidPool.unify(wcParents.first()); wcp2 = nodeidPool.unify(wcParents.second()); |
106 final File f = new File(repo.getRepositoryRoot(), "merge/state"); | 108 final File f = repo.getFileFromRepoDir("merge/state"); |
107 if (!f.canRead()) { | 109 if (!f.canRead()) { |
108 // empty state | 110 // empty state |
109 return; | 111 return; |
110 } | 112 } |
111 try { | 113 try { |
113 // pipe (already normalized) names from mergestate through same pool of filenames as use manifest revisions | 115 // pipe (already normalized) names from mergestate through same pool of filenames as use manifest revisions |
114 Path.Source pathPool = new Path.SimpleSource(new PathRewrite.Empty(), fnamePool); | 116 Path.Source pathPool = new Path.SimpleSource(new PathRewrite.Empty(), fnamePool); |
115 final ManifestRevision m1 = new ManifestRevision(nodeidPool, fnamePool); | 117 final ManifestRevision m1 = new ManifestRevision(nodeidPool, fnamePool); |
116 final ManifestRevision m2 = new ManifestRevision(nodeidPool, fnamePool); | 118 final ManifestRevision m2 = new ManifestRevision(nodeidPool, fnamePool); |
117 if (!wcp2.isNull()) { | 119 if (!wcp2.isNull()) { |
118 final int rp2 = repo.getChangelog().getRevisionIndex(wcp2); | 120 final int rp2 = hgRepo.getChangelog().getRevisionIndex(wcp2); |
119 repo.getManifest().walk(rp2, rp2, m2); | 121 hgRepo.getManifest().walk(rp2, rp2, m2); |
120 } | 122 } |
121 BufferedReader br = new BufferedReader(new FileReader(f)); | 123 BufferedReader br = new BufferedReader(new FileReader(f)); |
122 String s = br.readLine(); | 124 String s = br.readLine(); |
123 stateParent = nodeidPool.unify(Nodeid.fromAscii(s)); | 125 stateParent = nodeidPool.unify(Nodeid.fromAscii(s)); |
124 final int rp1 = repo.getChangelog().getRevisionIndex(stateParent); | 126 final int rp1 = hgRepo.getChangelog().getRevisionIndex(stateParent); |
125 repo.getManifest().walk(rp1, rp1, m1); | 127 hgRepo.getManifest().walk(rp1, rp1, m1); |
126 while ((s = br.readLine()) != null) { | 128 while ((s = br.readLine()) != null) { |
127 String[] r = s.split("\\00"); | 129 String[] r = s.split("\\00"); |
128 Path p1fname = pathPool.path(r[3]); | 130 Path p1fname = pathPool.path(r[3]); |
129 Nodeid nidP1 = m1.nodeid(p1fname); | 131 Nodeid nidP1 = m1.nodeid(p1fname); |
130 Nodeid nidCA = nodeidPool.unify(Nodeid.fromAscii(r[5])); | 132 Nodeid nidCA = nodeidPool.unify(Nodeid.fromAscii(r[5])); |
131 HgFileRevision p1 = new HgFileRevision(repo, nidP1, m1.flags(p1fname), p1fname); | 133 HgFileRevision p1 = new HgFileRevision(hgRepo, nidP1, m1.flags(p1fname), p1fname); |
132 HgFileRevision ca; | 134 HgFileRevision ca; |
133 if (nidCA == nidP1 && r[3].equals(r[4])) { | 135 if (nidCA == nidP1 && r[3].equals(r[4])) { |
134 ca = p1; | 136 ca = p1; |
135 } else { | 137 } else { |
136 ca = new HgFileRevision(repo, nidCA, null, pathPool.path(r[4])); | 138 ca = new HgFileRevision(hgRepo, nidCA, null, pathPool.path(r[4])); |
137 } | 139 } |
138 HgFileRevision p2; | 140 HgFileRevision p2; |
139 if (!wcp2.isNull() || !r[6].equals(r[4])) { | 141 if (!wcp2.isNull() || !r[6].equals(r[4])) { |
140 final Path p2fname = pathPool.path(r[6]); | 142 final Path p2fname = pathPool.path(r[6]); |
141 Nodeid nidP2 = m2.nodeid(p2fname); | 143 Nodeid nidP2 = m2.nodeid(p2fname); |
142 if (nidP2 == null) { | 144 if (nidP2 == null) { |
143 assert false : "There's not enough information (or I don't know where to look) in merge/state to find out what's the second parent"; | 145 assert false : "There's not enough information (or I don't know where to look) in merge/state to find out what's the second parent"; |
144 nidP2 = NULL; | 146 nidP2 = NULL; |
145 } | 147 } |
146 p2 = new HgFileRevision(repo, nidP2, m2.flags(p2fname), p2fname); | 148 p2 = new HgFileRevision(hgRepo, nidP2, m2.flags(p2fname), p2fname); |
147 } else { | 149 } else { |
148 // no second parent known. no idea what to do here, assume linear merge, use common ancestor as parent | 150 // no second parent known. no idea what to do here, assume linear merge, use common ancestor as parent |
149 p2 = ca; | 151 p2 = ca; |
150 } | 152 } |
151 final Kind k; | 153 final Kind k; |