@ -548,7 +548,7 @@ public class RefDirectory extends RefDatabase {
throw new IOException ( MessageFormat . format (
throw new IOException ( MessageFormat . format (
JGitText . get ( ) . cannotLockFile , packedRefsFile ) ) ;
JGitText . get ( ) . cannotLockFile , packedRefsFile ) ) ;
try {
try {
PackedRefList cur = readPackedRefs ( 0 , 0 ) ;
PackedRefList cur = readPackedRefs ( ) ;
int idx = cur . find ( name ) ;
int idx = cur . find ( name ) ;
if ( 0 < = idx )
if ( 0 < = idx )
commitPackedRefs ( lck , cur . remove ( idx ) , packed ) ;
commitPackedRefs ( lck , cur . remove ( idx ) , packed ) ;
@ -690,21 +690,19 @@ public class RefDirectory extends RefDatabase {
}
}
private PackedRefList getPackedRefs ( ) throws IOException {
private PackedRefList getPackedRefs ( ) throws IOException {
long size = packedRefsFile . length ( ) ;
long mtime = size ! = 0 ? packedRefsFile . lastModified ( ) : 0 ;
final PackedRefList curList = packedRefs . get ( ) ;
final PackedRefList curList = packedRefs . get ( ) ;
if ( size = = curList . lastSize & & mtime = = curList . lastModified )
if ( ! curList . snapshot . isModified ( packedRefsFile ) )
return curList ;
return curList ;
final PackedRefList newList = readPackedRefs ( size , mtime ) ;
final PackedRefList newList = readPackedRefs ( ) ;
if ( packedRefs . compareAndSet ( curList , newList ) )
if ( packedRefs . compareAndSet ( curList , newList ) )
modCnt . incrementAndGet ( ) ;
modCnt . incrementAndGet ( ) ;
return newList ;
return newList ;
}
}
private PackedRefList readPackedRefs ( long size , long mtime )
private PackedRefList readPackedRefs ( )
throws IOException {
throws IOException {
final FileSnapshot snapshot = FileSnapshot . save ( packedRefsFile ) ;
final BufferedReader br ;
final BufferedReader br ;
try {
try {
br = new BufferedReader ( new InputStreamReader ( new FileInputStream (
br = new BufferedReader ( new InputStreamReader ( new FileInputStream (
@ -714,7 +712,7 @@ public class RefDirectory extends RefDatabase {
return PackedRefList . NO_PACKED_REFS ;
return PackedRefList . NO_PACKED_REFS ;
}
}
try {
try {
return new PackedRefList ( parsePackedRefs ( br ) , size , mtime ) ;
return new PackedRefList ( parsePackedRefs ( br ) , snapshot ) ;
} finally {
} finally {
br . close ( ) ;
br . close ( ) ;
}
}
@ -780,7 +778,7 @@ public class RefDirectory extends RefDatabase {
protected void writeFile ( String name , byte [ ] content )
protected void writeFile ( String name , byte [ ] content )
throws IOException {
throws IOException {
lck . setFSync ( true ) ;
lck . setFSync ( true ) ;
lck . setNeedStatInformation ( true ) ;
lck . setNeedSnapshot ( true ) ;
try {
try {
lck . write ( content ) ;
lck . write ( content ) ;
} catch ( IOException ioe ) {
} catch ( IOException ioe ) {
@ -795,8 +793,8 @@ public class RefDirectory extends RefDatabase {
if ( ! lck . commit ( ) )
if ( ! lck . commit ( ) )
throw new ObjectWritingException ( MessageFormat . format ( JGitText . get ( ) . unableToWrite , name ) ) ;
throw new ObjectWritingException ( MessageFormat . format ( JGitText . get ( ) . unableToWrite , name ) ) ;
packedRefs . compareAndSet ( oldPackedList , new PackedRefList ( refs ,
packedRefs . compareAndSet ( oldPackedList , new PackedRefList (
content . length , lck . getCommitLastModified ( ) ) ) ;
refs , lck . getCommitSnapshot ( ) ) ) ;
}
}
} . writePackedRefs ( ) ;
} . writePackedRefs ( ) ;
}
}
@ -968,19 +966,14 @@ public class RefDirectory extends RefDatabase {
}
}
private static class PackedRefList extends RefList < Ref > {
private static class PackedRefList extends RefList < Ref > {
static final PackedRefList NO_PACKED_REFS = new PackedRefList ( RefList
static final PackedRefList NO_PACKED_REFS = new PackedRefList (
. emptyList ( ) , 0 , 0 ) ;
RefList . emptyList ( ) , FileSnapshot . MISSING_FILE ) ;
/** Last length of the packed-refs file when we read it. */
final long lastSize ;
/** Last modified time of the packed-refs file when we read it. */
final FileSnapshot snapshot ;
final long lastModified ;
PackedRefList ( RefList < Ref > src , long size , long mtime ) {
PackedRefList ( RefList < Ref > src , FileSnapshot s ) {
super ( src ) ;
super ( src ) ;
lastSize = size ;
snapshot = s ;
lastModified = mtime ;
}
}
}
}