comparison src/org/tmatesoft/hg/core/HgFileRevision.java @ 345:58725dd511b3

Provide access to revision's origins
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 22 Nov 2011 03:14:40 +0100
parents ee6b467c1a5f
children 5f9073eabf06
comparison
equal deleted inserted replaced
344:168f1994de7e 345:58725dd511b3
19 import org.tmatesoft.hg.repo.HgDataFile; 19 import org.tmatesoft.hg.repo.HgDataFile;
20 import org.tmatesoft.hg.repo.HgInternals; 20 import org.tmatesoft.hg.repo.HgInternals;
21 import org.tmatesoft.hg.repo.HgRepository; 21 import org.tmatesoft.hg.repo.HgRepository;
22 import org.tmatesoft.hg.util.ByteChannel; 22 import org.tmatesoft.hg.util.ByteChannel;
23 import org.tmatesoft.hg.util.CancelledException; 23 import org.tmatesoft.hg.util.CancelledException;
24 import org.tmatesoft.hg.util.Pair;
24 import org.tmatesoft.hg.util.Path; 25 import org.tmatesoft.hg.util.Path;
25 26
26 /** 27 /**
27 * Keeps together information about specific file revision 28 * Keeps together information about specific file revision
28 * 29 *
33 private final HgRepository repo; 34 private final HgRepository repo;
34 private final Nodeid revision; 35 private final Nodeid revision;
35 private final Path path; 36 private final Path path;
36 private Path origin; 37 private Path origin;
37 private Boolean isCopy = null; // null means not yet known 38 private Boolean isCopy = null; // null means not yet known
39 private Pair<Nodeid, Nodeid> parents;
38 40
39 public HgFileRevision(HgRepository hgRepo, Nodeid rev, Path p) { 41 public HgFileRevision(HgRepository hgRepo, Nodeid rev, Path p) {
40 if (hgRepo == null || rev == null || p == null) { 42 if (hgRepo == null || rev == null || p == null) {
41 // since it's package local, it is our code to blame for non validated arguments 43 // since it's package local, it is our code to blame for non validated arguments
42 throw new IllegalArgumentException(); 44 throw new IllegalArgumentException();
73 return origin; 75 return origin;
74 } 76 }
75 return null; 77 return null;
76 } 78 }
77 79
80 /**
81 * Access revisions this file revision originates from.
82 * Note, these revisions are records in the file history, not that of the whole repository (aka changeset revisions)
83 * In most cases, only one parent revision would be present, only for merge revisions one can expect both.
84 *
85 * @return parent revisions of this file revision, with {@link Nodeid#NULL} for missing values.
86 */
87 public Pair<Nodeid, Nodeid> getParents() {
88 if (parents == null) {
89 HgDataFile fn = repo.getFileNode(path);
90 int localRevision = fn.getLocalRevision(revision);
91 int[] pr = new int[2];
92 byte[] p1 = new byte[20], p2 = new byte[20];
93 // XXX Revlog#parents is not the best method to use here
94 // need smth that gives Nodeids (piped through Pool<Nodeid> from repo's context)
95 fn.parents(localRevision, pr, p1, p2);
96 parents = new Pair<Nodeid, Nodeid>(Nodeid.fromBinary(p1, 0), Nodeid.fromBinary(p2, 0));
97 }
98 return parents;
99 }
100
78 public void putContentTo(ByteChannel sink) throws HgDataStreamException, CancelledException { 101 public void putContentTo(ByteChannel sink) throws HgDataStreamException, CancelledException {
79 HgDataFile fn = repo.getFileNode(path); 102 HgDataFile fn = repo.getFileNode(path);
80 int localRevision = fn.getLocalRevision(revision); 103 int localRevision = fn.getLocalRevision(revision);
81 fn.contentWithFilters(localRevision, sink); 104 fn.contentWithFilters(localRevision, sink);
82 } 105 }