Browse Source

Fix usage of FileSnapshot in RefDirectory

RefDirectory was not using FileSnapshot correctly in all places. This
is fixed with this commit. Additionally the constructors for the
different types of refs have been changed to take a FileSnapshot
instead of a modification time.

Change-Id: Ifb6a59e87e8b058a398c38cdfb9d648f0bad4bf8
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
tags/v1.0.0.201106011211-rc3
Christian Halstrick 13 years ago
parent
commit
475461d052

+ 22
- 21
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/RefDirectory.java View File

@@ -493,8 +493,9 @@ public class RefDirectory extends RefDatabase {
return leaf;
}

void storedSymbolicRef(RefDirectoryUpdate u, long modified, String target) {
putLooseRef(newSymbolicRef(modified, u.getRef().getName(), target));
void storedSymbolicRef(RefDirectoryUpdate u, FileSnapshot snapshot,
String target) {
putLooseRef(newSymbolicRef(snapshot, u.getRef().getName(), target));
fireRefsChanged();
}

@@ -526,10 +527,10 @@ public class RefDirectory extends RefDatabase {
return new RefDirectoryRename(from, to);
}

void stored(RefDirectoryUpdate update, long modified) {
void stored(RefDirectoryUpdate update, FileSnapshot snapshot) {
final ObjectId target = update.getNewObjectId().copy();
final Ref leaf = update.getRef().getLeaf();
putLooseRef(new LooseUnpeeled(modified, leaf.getName(), target));
putLooseRef(new LooseUnpeeled(snapshot, leaf.getName(), target));
}

private void putLooseRef(LooseRef ref) {
@@ -852,8 +853,7 @@ public class RefDirectory extends RefDatabase {
if (!currentSnapshot.isModified(path))
return ref;
name = ref.getName();
} else if (!path.exists())
return null;
}

final int limit = 4096;
final byte[] buf;
@@ -885,7 +885,7 @@ public class RefDirectory extends RefDatabase {
currentSnapshot.setClean(otherSnapshot);
return ref;
}
return newSymbolicRef(path.lastModified(), name, target);
return newSymbolicRef(otherSnapshot, name, target);
}

if (n < OBJECT_ID_STRING_LENGTH)
@@ -906,7 +906,7 @@ public class RefDirectory extends RefDatabase {
String content = RawParseUtils.decode(buf, 0, n);
throw new IOException(MessageFormat.format(JGitText.get().notARef, name, content));
}
return new LooseUnpeeled(path.lastModified(), name, id);
return new LooseUnpeeled(otherSnapshot, name, id);
}

private static boolean isSymRef(final byte[] buf, int n) {
@@ -1004,10 +1004,10 @@ public class RefDirectory extends RefDatabase {
}
}

private static LooseSymbolicRef newSymbolicRef(long lastModified,
private static LooseSymbolicRef newSymbolicRef(FileSnapshot snapshot,
String name, String target) {
Ref dst = new ObjectIdRef.Unpeeled(NEW, target, null);
return new LooseSymbolicRef(lastModified, name, dst);
return new LooseSymbolicRef(snapshot, name, dst);
}

private static interface LooseRef extends Ref {
@@ -1020,9 +1020,10 @@ public class RefDirectory extends RefDatabase {
implements LooseRef {
private final FileSnapshot snapShot;

LoosePeeledTag(long mtime, String refName, ObjectId id, ObjectId p) {
LoosePeeledTag(FileSnapshot snapshot, String refName, ObjectId id,
ObjectId p) {
super(LOOSE, refName, id, p);
snapShot = FileSnapshot.save(mtime);
this.snapShot = snapshot;
}

public FileSnapshot getSnapShot() {
@@ -1038,9 +1039,9 @@ public class RefDirectory extends RefDatabase {
implements LooseRef {
private final FileSnapshot snapShot;

LooseNonTag(long mtime, String refName, ObjectId id) {
LooseNonTag(FileSnapshot snapshot, String refName, ObjectId id) {
super(LOOSE, refName, id);
snapShot = FileSnapshot.save(mtime);
this.snapShot = snapshot;
}

public FileSnapshot getSnapShot() {
@@ -1054,11 +1055,11 @@ public class RefDirectory extends RefDatabase {

private final static class LooseUnpeeled extends ObjectIdRef.Unpeeled
implements LooseRef {
private final FileSnapshot snapShot;
private FileSnapshot snapShot;

LooseUnpeeled(long mtime, String refName, ObjectId id) {
LooseUnpeeled(FileSnapshot snapShot, String refName, ObjectId id) {
super(LOOSE, refName, id);
snapShot = FileSnapshot.save(mtime);
this.snapShot = snapShot;
}

public FileSnapshot getSnapShot() {
@@ -1067,10 +1068,10 @@ public class RefDirectory extends RefDatabase {

public LooseRef peel(ObjectIdRef newLeaf) {
if (newLeaf.getPeeledObjectId() != null)
return new LoosePeeledTag(snapShot.lastModified(), getName(),
return new LoosePeeledTag(snapShot, getName(),
getObjectId(), newLeaf.getPeeledObjectId());
else
return new LooseNonTag(snapShot.lastModified(), getName(),
return new LooseNonTag(snapShot, getName(),
getObjectId());
}
}
@@ -1079,9 +1080,9 @@ public class RefDirectory extends RefDatabase {
LooseRef {
private final FileSnapshot snapShot;

LooseSymbolicRef(long mtime, String refName, Ref target) {
LooseSymbolicRef(FileSnapshot snapshot, String refName, Ref target) {
super(refName, target);
snapShot = FileSnapshot.save(mtime);
this.snapShot = snapshot;
}

public FileSnapshot getSnapShot() {

+ 2
- 2
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/RefDirectoryUpdate.java View File

@@ -121,7 +121,7 @@ class RefDirectoryUpdate extends RefUpdate {
}
if (!lock.commit())
return Result.LOCK_FAILURE;
database.stored(this, lock.getCommitLastModified());
database.stored(this, lock.getCommitSnapshot());
return status;
}

@@ -159,7 +159,7 @@ class RefDirectoryUpdate extends RefUpdate {
database.log(this, msg, false);
if (!lock.commit())
return Result.LOCK_FAILURE;
database.storedSymbolicRef(this, lock.getCommitLastModified(), target);
database.storedSymbolicRef(this, lock.getCommitSnapshot(), target);

if (getRef().getStorage() == Ref.Storage.NEW)
return Result.NEW;

Loading…
Cancel
Save