Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/AddRevInspector.java @ 663:46b56864b483
Pull: phase2 - update phases from remote, fncache with added files. Tests
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 10 Jul 2013 16:41:49 +0200 |
parents | 4fd317a2fecf |
children | ae2d439fbed3 |
comparison
equal
deleted
inserted
replaced
662:af5223b86dd3 | 663:46b56864b483 |
---|---|
14 * the terms of a license other than GNU General Public License | 14 * the terms of a license other than GNU General Public License |
15 * contact TMate Software at support@hg4j.com | 15 * contact TMate Software at support@hg4j.com |
16 */ | 16 */ |
17 package org.tmatesoft.hg.internal; | 17 package org.tmatesoft.hg.internal; |
18 | 18 |
19 import java.io.IOException; | |
19 import java.util.HashMap; | 20 import java.util.HashMap; |
20 import java.util.Set; | 21 import java.util.Set; |
21 | 22 |
22 import org.tmatesoft.hg.core.HgIOException; | 23 import org.tmatesoft.hg.core.HgIOException; |
23 import org.tmatesoft.hg.core.Nodeid; | 24 import org.tmatesoft.hg.core.Nodeid; |
28 import org.tmatesoft.hg.repo.HgRepository; | 29 import org.tmatesoft.hg.repo.HgRepository; |
29 import org.tmatesoft.hg.repo.HgRuntimeException; | 30 import org.tmatesoft.hg.repo.HgRuntimeException; |
30 import org.tmatesoft.hg.util.Pair; | 31 import org.tmatesoft.hg.util.Pair; |
31 | 32 |
32 /** | 33 /** |
34 * FIXME pretty much alike HgCloneCommand.WriteDownMate, shall converge | |
35 * | |
33 * @author Artem Tikhomirov | 36 * @author Artem Tikhomirov |
34 * @author TMate Software Ltd. | 37 * @author TMate Software Ltd. |
35 */ | 38 */ |
36 public final class AddRevInspector implements HgBundle.Inspector { | 39 public final class AddRevInspector implements HgBundle.Inspector { |
37 private final Internals repo; | 40 private final Internals repo; |
38 private final Transaction tr; | 41 private final Transaction tr; |
42 private final FNCacheFile.Mediator fncache; | |
39 private Set<Nodeid> added; | 43 private Set<Nodeid> added; |
40 private RevlogStreamWriter revlog; | 44 private RevlogStreamWriter revlog; |
41 private RevMap clogRevs; | 45 private RevMap clogRevs; |
42 private RevMap revlogRevs; | 46 private RevMap revlogRevs; |
47 private HgDataFile fileNode; | |
48 private boolean newFile = false; | |
43 | 49 |
44 public AddRevInspector(Internals implRepo, Transaction transaction) { | 50 public AddRevInspector(Internals implRepo, Transaction transaction) { |
45 repo = implRepo; | 51 repo = implRepo; |
46 tr = transaction; | 52 tr = transaction; |
53 fncache = new FNCacheFile.Mediator(implRepo); | |
47 } | 54 } |
48 | 55 |
49 public void changelogStart() throws HgRuntimeException { | 56 public void changelogStart() throws HgRuntimeException { |
50 // TODO Auto-generated method stub | |
51 RevlogStream rs = repo.getImplAccess().getChangelogStream(); | 57 RevlogStream rs = repo.getImplAccess().getChangelogStream(); |
52 revlog = new RevlogStreamWriter(repo, rs, tr); | 58 revlog = new RevlogStreamWriter(repo, rs, tr); |
53 revlogRevs = clogRevs = new RevMap(rs); | 59 revlogRevs = clogRevs = new RevMap(rs); |
54 } | 60 } |
55 | 61 |
69 revlog = null; | 75 revlog = null; |
70 revlogRevs = null; | 76 revlogRevs = null; |
71 } | 77 } |
72 | 78 |
73 public void fileStart(String name) throws HgRuntimeException { | 79 public void fileStart(String name) throws HgRuntimeException { |
74 HgDataFile df = repo.getRepo().getFileNode(name); | 80 fileNode = repo.getRepo().getFileNode(name); |
75 RevlogStream rs = repo.getImplAccess().getStream(df); | 81 newFile = !fileNode.exists(); |
82 RevlogStream rs = repo.getImplAccess().getStream(fileNode); | |
76 revlog = new RevlogStreamWriter(repo, rs, tr); | 83 revlog = new RevlogStreamWriter(repo, rs, tr); |
77 revlogRevs = new RevMap(rs); | 84 revlogRevs = new RevMap(rs); |
78 // FIXME collect new files and update fncache | |
79 } | 85 } |
80 | 86 |
81 public void fileEnd(String name) throws HgRuntimeException { | 87 public void fileEnd(String name) throws HgRuntimeException { |
88 if (newFile) { | |
89 fncache.registerNew(fileNode.getPath(), revlog.getRevlogStream()); | |
90 } | |
82 revlog = null; | 91 revlog = null; |
83 revlogRevs = null; | 92 revlogRevs = null; |
84 } | 93 } |
85 | 94 |
86 public boolean element(GroupElement ge) throws HgRuntimeException { | 95 public boolean element(GroupElement ge) throws HgRuntimeException { |
87 assert clogRevs != null; | 96 assert clogRevs != null; |
88 assert revlogRevs != null; | 97 assert revlogRevs != null; |
98 if (revlog.getRevlogStream().findRevisionIndex(ge.node()) != HgRepository.BAD_REVISION) { | |
99 // HgRemoteRepository.getChanges(common) builds a bundle that includes these common | |
100 // revisions. Hence, shall not add these common (i.e. known locally) revisions | |
101 // once again | |
102 return true; | |
103 } | |
89 try { | 104 try { |
90 Pair<Integer, Nodeid> newRev = revlog.addPatchRevision(ge, clogRevs, revlogRevs); | 105 Pair<Integer, Nodeid> newRev = revlog.addPatchRevision(ge, clogRevs, revlogRevs); |
91 revlogRevs.update(newRev.first(), newRev.second()); | 106 revlogRevs.update(newRev.first(), newRev.second()); |
92 return true; | 107 return true; |
93 } catch (HgIOException ex) { | 108 } catch (HgIOException ex) { |
95 } | 110 } |
96 } | 111 } |
97 | 112 |
98 public RevisionSet addedChangesets() { | 113 public RevisionSet addedChangesets() { |
99 return new RevisionSet(added); | 114 return new RevisionSet(added); |
115 } | |
116 | |
117 public void done() throws IOException { | |
118 fncache.complete(); | |
100 } | 119 } |
101 | 120 |
102 private static class RevMap implements RevlogStreamWriter.RevisionToIndexMap { | 121 private static class RevMap implements RevlogStreamWriter.RevisionToIndexMap { |
103 | 122 |
104 private final RevlogStream revlog; | 123 private final RevlogStream revlog; |