@ -842,19 +842,22 @@ public class RefDirectory extends RefDatabase {
return n ;
return n ;
}
}
@SuppressWarnings ( "null" )
private LooseRef scanRef ( LooseRef ref , String name ) throws IOException {
private LooseRef scanRef ( LooseRef ref , String name ) throws IOException {
final File path = fileFor ( name ) ;
final File path = fileFor ( name ) ;
final long modified = path . lastModified ( ) ;
FileSnapshot currentSnapshot = null ;
if ( ref ! = null ) {
if ( ref ! = null ) {
if ( ref . getLastModified ( ) = = modified )
currentSnapshot = ref . getSnapShot ( ) ;
if ( ! currentSnapshot . isModified ( path ) )
return ref ;
return ref ;
name = ref . getName ( ) ;
name = ref . getName ( ) ;
} else if ( modified = = 0 )
} else if ( ! path . exists ( ) )
return null ;
return null ;
final int limit = 4096 ;
final int limit = 4096 ;
final byte [ ] buf ;
final byte [ ] buf ;
FileSnapshot otherSnapshot = FileSnapshot . save ( path ) ;
try {
try {
buf = IO . readSome ( path , limit ) ;
buf = IO . readSome ( path , limit ) ;
} catch ( FileNotFoundException noFile ) {
} catch ( FileNotFoundException noFile ) {
@ -877,7 +880,12 @@ public class RefDirectory extends RefDatabase {
throw new IOException ( MessageFormat . format ( JGitText . get ( ) . notARef , name , content ) ) ;
throw new IOException ( MessageFormat . format ( JGitText . get ( ) . notARef , name , content ) ) ;
}
}
final String target = RawParseUtils . decode ( buf , 5 , n ) ;
final String target = RawParseUtils . decode ( buf , 5 , n ) ;
return newSymbolicRef ( modified , name , target ) ;
if ( ref ! = null & & ref . isSymbolic ( )
& & ref . getTarget ( ) . getName ( ) . equals ( target ) ) {
currentSnapshot . setClean ( otherSnapshot ) ;
return ref ;
}
return newSymbolicRef ( path . lastModified ( ) , name , target ) ;
}
}
if ( n < OBJECT_ID_STRING_LENGTH )
if ( n < OBJECT_ID_STRING_LENGTH )
@ -886,13 +894,19 @@ public class RefDirectory extends RefDatabase {
final ObjectId id ;
final ObjectId id ;
try {
try {
id = ObjectId . fromString ( buf , 0 ) ;
id = ObjectId . fromString ( buf , 0 ) ;
if ( ref ! = null & & ! ref . isSymbolic ( )
& & ref . getTarget ( ) . getObjectId ( ) . equals ( id ) ) {
currentSnapshot . setClean ( otherSnapshot ) ;
return ref ;
}
} catch ( IllegalArgumentException notRef ) {
} catch ( IllegalArgumentException notRef ) {
while ( 0 < n & & Character . isWhitespace ( buf [ n - 1 ] ) )
while ( 0 < n & & Character . isWhitespace ( buf [ n - 1 ] ) )
n - - ;
n - - ;
String content = RawParseUtils . decode ( buf , 0 , n ) ;
String content = RawParseUtils . decode ( buf , 0 , n ) ;
throw new IOException ( MessageFormat . format ( JGitText . get ( ) . notARef , name , content ) ) ;
throw new IOException ( MessageFormat . format ( JGitText . get ( ) . notARef , name , content ) ) ;
}
}
return new LooseUnpeeled ( modified , name , id ) ;
return new LooseUnpeeled ( path . lastModified ( ) , name , id ) ;
}
}
private static boolean isSymRef ( final byte [ ] buf , int n ) {
private static boolean isSymRef ( final byte [ ] buf , int n ) {
@ -997,22 +1011,22 @@ public class RefDirectory extends RefDatabase {
}
}
private static interface LooseRef extends Ref {
private static interface LooseRef extends Ref {
long getLastModified ( ) ;
FileSnapshot getSnapShot ( ) ;
LooseRef peel ( ObjectIdRef newLeaf ) ;
LooseRef peel ( ObjectIdRef newLeaf ) ;
}
}
private final static class LoosePeeledTag extends ObjectIdRef . PeeledTag
private final static class LoosePeeledTag extends ObjectIdRef . PeeledTag
implements LooseRef {
implements LooseRef {
private final long lastModified ;
private final FileSnapshot snapShot ;
LoosePeeledTag ( long mtime , String refName , ObjectId id , ObjectId p ) {
LoosePeeledTag ( long mtime , String refName , ObjectId id , ObjectId p ) {
super ( LOOSE , refName , id , p ) ;
super ( LOOSE , refName , id , p ) ;
this . lastModified = mtime ;
snapShot = FileSnapshot . save ( mtime ) ;
}
}
public long getLastModified ( ) {
public FileSnapshot getSnapShot ( ) {
return lastModified ;
return snapShot ;
}
}
public LooseRef peel ( ObjectIdRef newLeaf ) {
public LooseRef peel ( ObjectIdRef newLeaf ) {
@ -1022,15 +1036,15 @@ public class RefDirectory extends RefDatabase {
private final static class LooseNonTag extends ObjectIdRef . PeeledNonTag
private final static class LooseNonTag extends ObjectIdRef . PeeledNonTag
implements LooseRef {
implements LooseRef {
private final long lastModified ;
private final FileSnapshot snapShot ;
LooseNonTag ( long mtime , String refName , ObjectId id ) {
LooseNonTag ( long mtime , String refName , ObjectId id ) {
super ( LOOSE , refName , id ) ;
super ( LOOSE , refName , id ) ;
this . lastModified = mtime ;
snapShot = FileSnapshot . save ( mtime ) ;
}
}
public long getLastModified ( ) {
public FileSnapshot getSnapShot ( ) {
return lastModified ;
return snapShot ;
}
}
public LooseRef peel ( ObjectIdRef newLeaf ) {
public LooseRef peel ( ObjectIdRef newLeaf ) {
@ -1040,37 +1054,38 @@ public class RefDirectory extends RefDatabase {
private final static class LooseUnpeeled extends ObjectIdRef . Unpeeled
private final static class LooseUnpeeled extends ObjectIdRef . Unpeeled
implements LooseRef {
implements LooseRef {
private final long lastModified ;
private final FileSnapshot snapShot ;
LooseUnpeeled ( long mtime , String refName , ObjectId id ) {
LooseUnpeeled ( long mtime , String refName , ObjectId id ) {
super ( LOOSE , refName , id ) ;
super ( LOOSE , refName , id ) ;
this . lastModified = mtime ;
snapShot = FileSnapshot . save ( mtime ) ;
}
}
public long getLastModified ( ) {
public FileSnapshot getSnapShot ( ) {
return lastModified ;
return snapShot ;
}
}
public LooseRef peel ( ObjectIdRef newLeaf ) {
public LooseRef peel ( ObjectIdRef newLeaf ) {
if ( newLeaf . getPeeledObjectId ( ) ! = null )
if ( newLeaf . getPeeledObjectId ( ) ! = null )
return new LoosePeeledTag ( lastModified , getName ( ) ,
return new LoosePeeledTag ( snapShot . lastModified ( ) , getName ( ) ,
getObjectId ( ) , newLeaf . getPeeledObjectId ( ) ) ;
getObjectId ( ) , newLeaf . getPeeledObjectId ( ) ) ;
else
else
return new LooseNonTag ( lastModified , getName ( ) , getObjectId ( ) ) ;
return new LooseNonTag ( snapShot . lastModified ( ) , getName ( ) ,
getObjectId ( ) ) ;
}
}
}
}
private final static class LooseSymbolicRef extends SymbolicRef implements
private final static class LooseSymbolicRef extends SymbolicRef implements
LooseRef {
LooseRef {
private final long lastModified ;
private final FileSnapshot snapShot ;
LooseSymbolicRef ( long mtime , String refName , Ref target ) {
LooseSymbolicRef ( long mtime , String refName , Ref target ) {
super ( refName , target ) ;
super ( refName , target ) ;
this . lastModified = mtime ;
snapShot = FileSnapshot . save ( mtime ) ;
}
}
public long getLastModified ( ) {
public FileSnapshot getSnapShot ( ) {
return lastModified ;
return snapShot ;
}
}
public LooseRef peel ( ObjectIdRef newLeaf ) {
public LooseRef peel ( ObjectIdRef newLeaf ) {