Skip to content
Snippets Groups Projects
Commit a496410d authored by Robin Rosenberg's avatar Robin Rosenberg
Browse files

A stages field and getter for GitIndex entry introduced


Currently, if the Index contains a file in more than one stage, only
the last entry (containing the highest stage) will be registered in
GitIndex. For applications it can be useful to not only know about the
highest stage, but also which other stages are present, e.g. to detect
the type of conflict the file is in.

Change-Id: I2d4ff9f6023335d9ba6ea25d8e77c8e283ae53cb
Signed-off-by: default avatarRobin Rosenberg <robin.rosenberg@dewire.com>
parent 23583e59
No related branches found
No related tags found
No related merge requests found
......@@ -244,7 +244,11 @@ public void read() throws IOException {
entries.clear();
for (int i = 0; i < header.entries; ++i) {
Entry entry = new Entry(buffer);
final GitIndex.Entry existing = entries.get(entry.name);
entries.put(entry.name, entry);
if (existing != null) {
entry.stages |= existing.stages;
}
}
lastCacheTime = cacheFile.lastModified();
} finally {
......@@ -374,6 +378,8 @@ public class Entry {
private byte[] name;
private int stages;
Entry(byte[] key, File f, int stage)
throws IOException {
ctime = f.lastModified() * 1000000L;
......@@ -391,6 +397,7 @@ public class Entry {
sha1 = writer.writeBlob(f);
name = key;
flags = (short) ((stage << 12) | name.length); // TODO: fix flags
stages = (1 >> getStage());
}
Entry(byte[] key, File f, int stage, byte[] newContent)
......@@ -410,6 +417,7 @@ public class Entry {
sha1 = writer.writeBlob(newContent);
name = key;
flags = (short) ((stage << 12) | name.length); // TODO: fix flags
stages = (1 >> getStage());
}
Entry(TreeEntry f, int stage) {
......@@ -429,6 +437,7 @@ public class Entry {
sha1 = f.getId();
name = Constants.encode(f.getFullName());
flags = (short) ((stage << 12) | name.length); // TODO: fix flags
stages = (1 >> getStage());
}
Entry(ByteBuffer b) {
......@@ -445,6 +454,7 @@ public class Entry {
b.get(sha1bytes);
sha1 = ObjectId.fromRaw(sha1bytes);
flags = b.getShort();
stages = (1 << getStage());
name = new byte[flags & 0xFFF];
b.get(name);
b
......@@ -643,6 +653,19 @@ public boolean isModified(File wd, boolean forceContentCheck) {
return false;
}
/**
* Returns the stages in which the entry's file is recorded in the index.
* The stages are bit-encoded: bit N is set if the file is present
* in stage N. In particular, the N-th bit will be set if this entry
* itself is in stage N (see getStage()).
*
* @return flags denoting stages
* @see #getStage()
*/
public int getStages() {
return stages;
}
// for testing
void forceRecheck() {
mtime = -1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment