Mercurial > hg4j
comparison src/org/tmatesoft/hg/internal/DirstateBuilder.java @ 529:95bdcf75e71e
Command to schedule addition/removal of repository files
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 21 Jan 2013 19:41:51 +0100 |
parents | 2f9ed6bcefa2 |
children | bd5926e24aa3 |
comparison
equal
deleted
inserted
replaced
528:f7fbf48b9383 | 529:95bdcf75e71e |
---|---|
81 // `hg revert` puts "n 0 -1 unset" for the reverted file, so shall we | 81 // `hg revert` puts "n 0 -1 unset" for the reverted file, so shall we |
82 forget(fname); | 82 forget(fname); |
83 normal.put(fname, new HgDirstate.Record(0, -1, -1, fname, null)); | 83 normal.put(fname, new HgDirstate.Record(0, -1, -1, fname, null)); |
84 } | 84 } |
85 | 85 |
86 private void forget(Path fname) { | 86 public void recordAdded(Path fname, Flags flags, int size) { |
87 normal.remove(fname); | 87 forget(fname); |
88 added.remove(fname); | 88 added.put(fname, new HgDirstate.Record(0, -1, -1, fname, null)); |
89 removed.remove(fname); | 89 } |
90 merged.remove(fname); | 90 |
91 public void recordRemoved(Path fname) { | |
92 HgDirstate.Record r = forget(fname); | |
93 HgDirstate.Record n; | |
94 if (r == null) { | |
95 n = new HgDirstate.Record(0, -1, -1, fname, null); | |
96 } else { | |
97 n = new HgDirstate.Record(r.mode(), r.size(), r.modificationTime(), fname, r.copySource()); | |
98 } | |
99 removed.put(fname, n); | |
100 } | |
101 | |
102 private HgDirstate.Record forget(Path fname) { | |
103 HgDirstate.Record r; | |
104 if ((r = normal.remove(fname)) != null) { | |
105 return r; | |
106 } | |
107 if ((r = added.remove(fname)) != null) { | |
108 return r; | |
109 } | |
110 if ((r = removed.remove(fname)) != null) { | |
111 return r; | |
112 } | |
113 return merged.remove(fname); | |
91 } | 114 } |
92 | 115 |
93 public void serialize(WritableByteChannel dest) throws IOException { | 116 public void serialize(WritableByteChannel dest) throws IOException { |
94 assert parent1 != null : "Parent(s) of the working directory shall be set first"; | 117 assert parent1 != null : "Parent(s) of the working directory shall be set first"; |
95 ByteBuffer bb = ByteBuffer.allocate(256); | 118 ByteBuffer bb = ByteBuffer.allocate(256); |
103 } | 126 } |
104 bb.clear(); | 127 bb.clear(); |
105 // entries | 128 // entries |
106 @SuppressWarnings("unchecked") | 129 @SuppressWarnings("unchecked") |
107 Map<Path, HgDirstate.Record>[] all = new Map[] {normal, added, removed, merged}; | 130 Map<Path, HgDirstate.Record>[] all = new Map[] {normal, added, removed, merged}; |
131 ByteBuffer recordTypes = ByteBuffer.allocate(4); | |
132 recordTypes.put((byte) 'n').put((byte) 'a').put((byte) 'r').put((byte) 'm').flip(); | |
108 for (Map<Path, HgDirstate.Record> m : all) { | 133 for (Map<Path, HgDirstate.Record> m : all) { |
134 final byte recordType = recordTypes.get(); | |
109 for (HgDirstate.Record r : m.values()) { | 135 for (HgDirstate.Record r : m.values()) { |
110 // regular entry is 1+4+4+4+4+fname.length bytes | 136 // regular entry is 1+4+4+4+4+fname.length bytes |
111 // it might get extended with copy origin, prepended with 0 byte | 137 // it might get extended with copy origin, prepended with 0 byte |
112 byte[] fname = encodingHelper.toDirstate(r.name()); | 138 byte[] fname = encodingHelper.toDirstate(r.name()); |
113 byte[] copyOrigin = r.copySource() == null ? null : encodingHelper.toDirstate(r.copySource()); | 139 byte[] copyOrigin = r.copySource() == null ? null : encodingHelper.toDirstate(r.copySource()); |
114 int length = fname.length + (copyOrigin == null ? 0 : (1 + copyOrigin.length)); | 140 int length = fname.length + (copyOrigin == null ? 0 : (1 + copyOrigin.length)); |
115 bb = ensureCapacity(bb, 17 + length); | 141 bb = ensureCapacity(bb, 17 + length); |
116 bb.put((byte) 'n'); | 142 bb.put(recordType); |
117 bb.putInt(r.mode()); | 143 bb.putInt(r.mode()); |
118 bb.putInt(r.size()); | 144 bb.putInt(r.size()); |
119 bb.putInt(r.modificationTime()); | 145 bb.putInt(r.modificationTime()); |
120 bb.putInt(length); | 146 bb.putInt(length); |
121 bb.put(fname); | 147 bb.put(fname); |