Browse Source

Merge "A stages field and getter for GitIndex entry introduced"

tags/v0.8.1
Robin Rosenberg 14 years ago
parent
commit
0df679aea1
1 changed files with 23 additions and 0 deletions
  1. 23
    0
      org.eclipse.jgit/src/org/eclipse/jgit/lib/GitIndex.java

+ 23
- 0
org.eclipse.jgit/src/org/eclipse/jgit/lib/GitIndex.java View File

entries.clear(); entries.clear();
for (int i = 0; i < header.entries; ++i) { for (int i = 0; i < header.entries; ++i) {
Entry entry = new Entry(buffer); Entry entry = new Entry(buffer);
final GitIndex.Entry existing = entries.get(entry.name);
entries.put(entry.name, entry); entries.put(entry.name, entry);
if (existing != null) {
entry.stages |= existing.stages;
}
} }
lastCacheTime = cacheFile.lastModified(); lastCacheTime = cacheFile.lastModified();
} finally { } finally {


private byte[] name; private byte[] name;


private int stages;

Entry(byte[] key, File f, int stage) Entry(byte[] key, File f, int stage)
throws IOException { throws IOException {
ctime = f.lastModified() * 1000000L; ctime = f.lastModified() * 1000000L;
sha1 = writer.writeBlob(f); sha1 = writer.writeBlob(f);
name = key; name = key;
flags = (short) ((stage << 12) | name.length); // TODO: fix flags flags = (short) ((stage << 12) | name.length); // TODO: fix flags
stages = (1 >> getStage());
} }


Entry(byte[] key, File f, int stage, byte[] newContent) Entry(byte[] key, File f, int stage, byte[] newContent)
sha1 = writer.writeBlob(newContent); sha1 = writer.writeBlob(newContent);
name = key; name = key;
flags = (short) ((stage << 12) | name.length); // TODO: fix flags flags = (short) ((stage << 12) | name.length); // TODO: fix flags
stages = (1 >> getStage());
} }


Entry(TreeEntry f, int stage) { Entry(TreeEntry f, int stage) {
sha1 = f.getId(); sha1 = f.getId();
name = Constants.encode(f.getFullName()); name = Constants.encode(f.getFullName());
flags = (short) ((stage << 12) | name.length); // TODO: fix flags flags = (short) ((stage << 12) | name.length); // TODO: fix flags
stages = (1 >> getStage());
} }


Entry(ByteBuffer b) { Entry(ByteBuffer b) {
b.get(sha1bytes); b.get(sha1bytes);
sha1 = ObjectId.fromRaw(sha1bytes); sha1 = ObjectId.fromRaw(sha1bytes);
flags = b.getShort(); flags = b.getShort();
stages = (1 << getStage());
name = new byte[flags & 0xFFF]; name = new byte[flags & 0xFFF];
b.get(name); b.get(name);
b b
return false; 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 // for testing
void forceRecheck() { void forceRecheck() {
mtime = -1; mtime = -1;

Loading…
Cancel
Save