Don't use deprecated LockFile constructor

Change-Id: Ibc3e2f3372e1a65732dd6d3c71cec53fb1aa15e2
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
This commit is contained in:
David Pursehouse 2016-02-15 18:44:24 +09:00
parent 979fa19110
commit e96cb22a43
12 changed files with 17 additions and 31 deletions

View File

@ -905,7 +905,7 @@ private static File nameFor(ObjectDirectory odb, ObjectId name, String t) {
private void writeFile(final File p, final byte[] bin) throws IOException, private void writeFile(final File p, final byte[] bin) throws IOException,
ObjectWritingException { ObjectWritingException {
final LockFile lck = new LockFile(p, db.getFS()); final LockFile lck = new LockFile(p);
if (!lck.lock()) if (!lck.lock())
throw new ObjectWritingException("Can't write " + p); throw new ObjectWritingException("Can't write " + p);
try { try {

View File

@ -235,7 +235,7 @@ private void detachHead() throws IOException {
final ObjectId id = db.resolve(Constants.HEAD); final ObjectId id = db.resolve(Constants.HEAD);
if (!ObjectId.isId(head) && id != null) { if (!ObjectId.isId(head) && id != null) {
final LockFile lf; final LockFile lf;
lf = new LockFile(new File(db.getDirectory(), Constants.HEAD), db.getFS()); lf = new LockFile(new File(db.getDirectory(), Constants.HEAD));
if (!lf.lock()) if (!lf.lock())
throw new IOException(MessageFormat.format(CLIText.get().cannotLock, Constants.HEAD)); throw new IOException(MessageFormat.format(CLIText.get().cannotLock, Constants.HEAD));
lf.write(id); lf.write(id);
@ -263,7 +263,7 @@ private void recreateRefs() throws Exception {
protected void writeFile(final String name, final byte[] content) protected void writeFile(final String name, final byte[] content)
throws IOException { throws IOException {
final File file = new File(db.getDirectory(), name); final File file = new File(db.getDirectory(), name);
final LockFile lck = new LockFile(file, db.getFS()); final LockFile lck = new LockFile(file);
if (!lck.lock()) if (!lck.lock())
throw new ObjectWritingException(MessageFormat.format(CLIText.get().cantWrite, file)); throw new ObjectWritingException(MessageFormat.format(CLIText.get().cantWrite, file));
try { try {

View File

@ -118,7 +118,7 @@ public void whileRefLockedRefNotPackedNoError()
tr.lightweightTag("t1", a); tr.lightweightTag("t1", a);
tr.lightweightTag("t2", a); tr.lightweightTag("t2", a);
LockFile refLock = new LockFile(new File(repo.getDirectory(), LockFile refLock = new LockFile(new File(repo.getDirectory(),
"refs/tags/t1"), repo.getFS()); "refs/tags/t1"));
try { try {
refLock.lock(); refLock.lock();
gc.packRefs(); gc.packRefs();

View File

@ -71,7 +71,7 @@ public void lockFailedExceptionRecovery() throws Exception {
git.add().addFilepattern("file.txt").call(); git.add().addFilepattern("file.txt").call();
assertNotNull(git.commit().setMessage("edit file").call()); assertNotNull(git.commit().setMessage("edit file").call());
LockFile lf = new LockFile(db.getIndexFile(), db.getFS()); LockFile lf = new LockFile(db.getIndexFile());
assertTrue(lf.lock()); assertTrue(lf.lock());
try { try {
git.checkout().setName(commit1.name()).call(); git.checkout().setName(commit1.name()).call();

View File

@ -581,14 +581,13 @@ public void testUpdateRefLockFailureLocked() throws IOException {
RefUpdate updateRef = db.updateRef("refs/heads/master"); RefUpdate updateRef = db.updateRef("refs/heads/master");
updateRef.setNewObjectId(pid); updateRef.setNewObjectId(pid);
LockFile lockFile1 = new LockFile(new File(db.getDirectory(), LockFile lockFile1 = new LockFile(new File(db.getDirectory(),
"refs/heads/master"), db.getFS()); "refs/heads/master"));
try { try {
assertTrue(lockFile1.lock()); // precondition to test assertTrue(lockFile1.lock()); // precondition to test
Result update = updateRef.update(); Result update = updateRef.update();
assertEquals(Result.LOCK_FAILURE, update); assertEquals(Result.LOCK_FAILURE, update);
assertEquals(opid, db.resolve("refs/heads/master")); assertEquals(opid, db.resolve("refs/heads/master"));
LockFile lockFile2 = new LockFile(new File(db.getDirectory(),"refs/heads/master"), LockFile lockFile2 = new LockFile(new File(db.getDirectory(),"refs/heads/master"));
db.getFS());
assertFalse(lockFile2.lock()); // was locked, still is assertFalse(lockFile2.lock()); // was locked, still is
} finally { } finally {
lockFile1.unlock(); lockFile1.unlock();
@ -731,8 +730,7 @@ public void tryRenameWhenLocked(String toLock, String fromName,
"logs/" + fromName).exists()); "logs/" + fromName).exists());
// "someone" has branch X locked // "someone" has branch X locked
LockFile lockFile = new LockFile(new File(db.getDirectory(), toLock), LockFile lockFile = new LockFile(new File(db.getDirectory(), toLock));
db.getFS());
try { try {
assertTrue(lockFile.lock()); assertTrue(lockFile.lock());

View File

@ -344,9 +344,6 @@ public static DirCache lock(final File indexLocation, final FS fs,
/** Our active lock (if we hold it); null if we don't have it locked. */ /** Our active lock (if we hold it); null if we don't have it locked. */
private LockFile myLock; private LockFile myLock;
/** file system abstraction **/
private final FS fs;
/** Keep track of whether the index has changed or not */ /** Keep track of whether the index has changed or not */
private FileSnapshot snapshot; private FileSnapshot snapshot;
@ -376,7 +373,6 @@ public static DirCache lock(final File indexLocation, final FS fs,
*/ */
public DirCache(final File indexLocation, final FS fs) { public DirCache(final File indexLocation, final FS fs) {
liveFile = indexLocation; liveFile = indexLocation;
this.fs = fs;
clear(); clear();
} }
@ -611,7 +607,7 @@ private static boolean is_DIRC(final byte[] hdr) {
public boolean lock() throws IOException { public boolean lock() throws IOException {
if (liveFile == null) if (liveFile == null)
throw new IOException(JGitText.get().dirCacheDoesNotHaveABackingFile); throw new IOException(JGitText.get().dirCacheDoesNotHaveABackingFile);
final LockFile tmp = new LockFile(liveFile, fs); final LockFile tmp = new LockFile(liveFile);
if (tmp.lock()) { if (tmp.lock()) {
tmp.setNeedStatInformation(true); tmp.setNeedStatInformation(true);
myLock = tmp; myLock = tmp;

View File

@ -354,7 +354,7 @@ && getDirectory().getName().startsWith(".")) //$NON-NLS-1$
ConfigConstants.CONFIG_KEY_WORKTREE, getWorkTree() ConfigConstants.CONFIG_KEY_WORKTREE, getWorkTree()
.getAbsolutePath()); .getAbsolutePath());
LockFile dotGitLockFile = new LockFile(new File(workTree, LockFile dotGitLockFile = new LockFile(new File(workTree,
Constants.DOT_GIT), getFS()); Constants.DOT_GIT));
try { try {
if (dotGitLockFile.lock()) { if (dotGitLockFile.lock()) {
dotGitLockFile.write(Constants.encode(Constants.GITDIR dotGitLockFile.write(Constants.encode(Constants.GITDIR

View File

@ -53,7 +53,6 @@
/** Keeps track of a {@link PackFile}'s associated <code>.keep</code> file. */ /** Keeps track of a {@link PackFile}'s associated <code>.keep</code> file. */
public class PackLock { public class PackLock {
private final File keepFile; private final File keepFile;
private final FS fs;
/** /**
* Create a new lock for a pack file. * Create a new lock for a pack file.
@ -67,7 +66,6 @@ public PackLock(final File packFile, final FS fs) {
final File p = packFile.getParentFile(); final File p = packFile.getParentFile();
final String n = packFile.getName(); final String n = packFile.getName();
keepFile = new File(p, n.substring(0, n.length() - 5) + ".keep"); //$NON-NLS-1$ keepFile = new File(p, n.substring(0, n.length() - 5) + ".keep"); //$NON-NLS-1$
this.fs = fs;
} }
/** /**
@ -84,7 +82,7 @@ public boolean lock(String msg) throws IOException {
return false; return false;
if (!msg.endsWith("\n")) //$NON-NLS-1$ if (!msg.endsWith("\n")) //$NON-NLS-1$
msg += "\n"; //$NON-NLS-1$ msg += "\n"; //$NON-NLS-1$
final LockFile lf = new LockFile(keepFile, fs); final LockFile lf = new LockFile(keepFile);
if (!lf.lock()) if (!lf.lock())
return false; return false;
lf.write(Constants.encode(msg)); lf.write(Constants.encode(msg));

View File

@ -588,8 +588,7 @@ void delete(RefDirectoryUpdate update) throws IOException {
// we don't miss an edit made externally. // we don't miss an edit made externally.
final PackedRefList packed = getPackedRefs(); final PackedRefList packed = getPackedRefs();
if (packed.contains(name)) { if (packed.contains(name)) {
LockFile lck = new LockFile(packedRefsFile, LockFile lck = new LockFile(packedRefsFile);
update.getRepository().getFS());
if (!lck.lock()) if (!lck.lock())
throw new LockFailedException(packedRefsFile); throw new LockFailedException(packedRefsFile);
try { try {
@ -639,7 +638,7 @@ public void pack(List<String> refs) throws IOException {
FS fs = parent.getFS(); FS fs = parent.getFS();
// Lock the packed refs file and read the content // Lock the packed refs file and read the content
LockFile lck = new LockFile(packedRefsFile, fs); LockFile lck = new LockFile(packedRefsFile);
if (!lck.lock()) if (!lck.lock())
throw new IOException(MessageFormat.format( throw new IOException(MessageFormat.format(
JGitText.get().cannotLock, packedRefsFile)); JGitText.get().cannotLock, packedRefsFile));
@ -670,8 +669,7 @@ public void pack(List<String> refs) throws IOException {
File refFile = fileFor(refName); File refFile = fileFor(refName);
if (!fs.exists(refFile)) if (!fs.exists(refFile))
continue; continue;
LockFile rLck = new LockFile(refFile, LockFile rLck = new LockFile(refFile);
parent.getFS());
if (!rLck.lock()) if (!rLck.lock())
continue; continue;
try { try {

View File

@ -79,7 +79,7 @@ protected boolean tryLock(boolean deref) throws IOException {
if (deref) if (deref)
dst = dst.getLeaf(); dst = dst.getLeaf();
String name = dst.getName(); String name = dst.getName();
lock = new LockFile(database.fileFor(name), getRepository().getFS()); lock = new LockFile(database.fileFor(name));
if (lock.lock()) { if (lock.lock()) {
dst = database.getRef(name); dst = database.getRef(name);
setOldObjectId(dst != null ? dst.getObjectId() : null); setOldObjectId(dst != null ? dst.getObjectId() : null);

View File

@ -74,8 +74,6 @@
public class FileBasedConfig extends StoredConfig { public class FileBasedConfig extends StoredConfig {
private final File configFile; private final File configFile;
private final FS fs;
private boolean utf8Bom; private boolean utf8Bom;
private volatile FileSnapshot snapshot; private volatile FileSnapshot snapshot;
@ -109,7 +107,6 @@ public FileBasedConfig(File cfgLocation, FS fs) {
public FileBasedConfig(Config base, File cfgLocation, FS fs) { public FileBasedConfig(Config base, File cfgLocation, FS fs) {
super(base); super(base);
configFile = cfgLocation; configFile = cfgLocation;
this.fs = fs;
this.snapshot = FileSnapshot.DIRTY; this.snapshot = FileSnapshot.DIRTY;
this.hash = ObjectId.zeroId(); this.hash = ObjectId.zeroId();
} }
@ -203,7 +200,7 @@ public void save() throws IOException {
out = Constants.encode(text); out = Constants.encode(text);
} }
final LockFile lf = new LockFile(getFile(), fs); final LockFile lf = new LockFile(getFile());
if (!lf.lock()) if (!lf.lock())
throw new LockFailedException(getFile()); throw new LockFailedException(getFile());
try { try {

View File

@ -314,8 +314,7 @@ private void updateFETCH_HEAD(final FetchResult result) throws IOException {
File meta = transport.local.getDirectory(); File meta = transport.local.getDirectory();
if (meta == null) if (meta == null)
return; return;
final LockFile lock = new LockFile(new File(meta, "FETCH_HEAD"), //$NON-NLS-1$ final LockFile lock = new LockFile(new File(meta, "FETCH_HEAD")); //$NON-NLS-1$
transport.local.getFS());
try { try {
if (lock.lock()) { if (lock.lock()) {
final Writer w = new OutputStreamWriter(lock.getOutputStream()); final Writer w = new OutputStreamWriter(lock.getOutputStream());