Mercurial > hg4j
comparison src/org/tmatesoft/hg/internal/AddRevInspector.java @ 660:4fd317a2fecf
Pull: phase1 get remote changes and add local revisions
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 09 Jul 2013 21:46:45 +0200 |
parents | |
children | 46b56864b483 |
comparison
equal
deleted
inserted
replaced
658:d10399f80f4e | 660:4fd317a2fecf |
---|---|
1 /* | |
2 * Copyright (c) 2013 TMate Software Ltd | |
3 * | |
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 | |
6 * the Free Software Foundation; version 2 of the License. | |
7 * | |
8 * This program is distributed in the hope that it will be useful, | |
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 * GNU General Public License for more details. | |
12 * | |
13 * For information on how to redistribute this software under | |
14 * the terms of a license other than GNU General Public License | |
15 * contact TMate Software at support@hg4j.com | |
16 */ | |
17 package org.tmatesoft.hg.internal; | |
18 | |
19 import java.util.HashMap; | |
20 import java.util.Set; | |
21 | |
22 import org.tmatesoft.hg.core.HgIOException; | |
23 import org.tmatesoft.hg.core.Nodeid; | |
24 import org.tmatesoft.hg.repo.HgBundle; | |
25 import org.tmatesoft.hg.repo.HgBundle.GroupElement; | |
26 import org.tmatesoft.hg.repo.HgDataFile; | |
27 import org.tmatesoft.hg.repo.HgInvalidControlFileException; | |
28 import org.tmatesoft.hg.repo.HgRepository; | |
29 import org.tmatesoft.hg.repo.HgRuntimeException; | |
30 import org.tmatesoft.hg.util.Pair; | |
31 | |
32 /** | |
33 * @author Artem Tikhomirov | |
34 * @author TMate Software Ltd. | |
35 */ | |
36 public final class AddRevInspector implements HgBundle.Inspector { | |
37 private final Internals repo; | |
38 private final Transaction tr; | |
39 private Set<Nodeid> added; | |
40 private RevlogStreamWriter revlog; | |
41 private RevMap clogRevs; | |
42 private RevMap revlogRevs; | |
43 | |
44 public AddRevInspector(Internals implRepo, Transaction transaction) { | |
45 repo = implRepo; | |
46 tr = transaction; | |
47 } | |
48 | |
49 public void changelogStart() throws HgRuntimeException { | |
50 // TODO Auto-generated method stub | |
51 RevlogStream rs = repo.getImplAccess().getChangelogStream(); | |
52 revlog = new RevlogStreamWriter(repo, rs, tr); | |
53 revlogRevs = clogRevs = new RevMap(rs); | |
54 } | |
55 | |
56 public void changelogEnd() throws HgRuntimeException { | |
57 revlog = null; | |
58 revlogRevs = null; | |
59 added = clogRevs.added(); | |
60 } | |
61 | |
62 public void manifestStart() throws HgRuntimeException { | |
63 RevlogStream rs = repo.getImplAccess().getManifestStream(); | |
64 revlog = new RevlogStreamWriter(repo, rs, tr); | |
65 revlogRevs = new RevMap(rs); | |
66 } | |
67 | |
68 public void manifestEnd() throws HgRuntimeException { | |
69 revlog = null; | |
70 revlogRevs = null; | |
71 } | |
72 | |
73 public void fileStart(String name) throws HgRuntimeException { | |
74 HgDataFile df = repo.getRepo().getFileNode(name); | |
75 RevlogStream rs = repo.getImplAccess().getStream(df); | |
76 revlog = new RevlogStreamWriter(repo, rs, tr); | |
77 revlogRevs = new RevMap(rs); | |
78 // FIXME collect new files and update fncache | |
79 } | |
80 | |
81 public void fileEnd(String name) throws HgRuntimeException { | |
82 revlog = null; | |
83 revlogRevs = null; | |
84 } | |
85 | |
86 public boolean element(GroupElement ge) throws HgRuntimeException { | |
87 assert clogRevs != null; | |
88 assert revlogRevs != null; | |
89 try { | |
90 Pair<Integer, Nodeid> newRev = revlog.addPatchRevision(ge, clogRevs, revlogRevs); | |
91 revlogRevs.update(newRev.first(), newRev.second()); | |
92 return true; | |
93 } catch (HgIOException ex) { | |
94 throw new HgInvalidControlFileException(ex, true); | |
95 } | |
96 } | |
97 | |
98 public RevisionSet addedChangesets() { | |
99 return new RevisionSet(added); | |
100 } | |
101 | |
102 private static class RevMap implements RevlogStreamWriter.RevisionToIndexMap { | |
103 | |
104 private final RevlogStream revlog; | |
105 private HashMap<Nodeid, Integer> added = new HashMap<Nodeid, Integer>(); | |
106 | |
107 public RevMap(RevlogStream revlogStream) { | |
108 revlog = revlogStream; | |
109 } | |
110 | |
111 public int revisionIndex(Nodeid revision) { | |
112 Integer a = added.get(revision); | |
113 if (a != null) { | |
114 return a; | |
115 } | |
116 int f = revlog.findRevisionIndex(revision); | |
117 return f == HgRepository.BAD_REVISION ? HgRepository.NO_REVISION : f; | |
118 } | |
119 | |
120 public void update(Integer revIndex, Nodeid rev) { | |
121 added.put(rev, revIndex); | |
122 } | |
123 | |
124 Set<Nodeid> added() { | |
125 return added.keySet(); | |
126 } | |
127 } | |
128 } |