Browse Source

Merge 'Fix usage of FileSnapshot in RefDirectory' into stable-1.0

* commit '475461d05266fe13b05bc2c6645b9ef928521b4c':
  Fix usage of FileSnapshot in RefDirectory

Change-Id: Ie65bd8b36f4c6a91602a94e9b54a04a4fb335897
stable-1.0
Shawn O. Pearce 14 years ago
parent
commit
cc319fff0d
  1. 43
      org.eclipse.jgit/src/org/eclipse/jgit/storage/file/RefDirectory.java
  2. 4
      org.eclipse.jgit/src/org/eclipse/jgit/storage/file/RefDirectoryUpdate.java

43
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/RefDirectory.java

@ -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() {

4
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/RefDirectoryUpdate.java

@ -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