|
|
@ -66,13 +66,19 @@ import org.eclipse.jgit.lib.Constants; |
|
|
|
import org.eclipse.jgit.lib.ObjectId; |
|
|
|
import org.eclipse.jgit.lib.ObjectId; |
|
|
|
import org.eclipse.jgit.lib.StoredConfig; |
|
|
|
import org.eclipse.jgit.lib.StoredConfig; |
|
|
|
import org.eclipse.jgit.util.FS; |
|
|
|
import org.eclipse.jgit.util.FS; |
|
|
|
|
|
|
|
import org.eclipse.jgit.util.FileUtils; |
|
|
|
import org.eclipse.jgit.util.IO; |
|
|
|
import org.eclipse.jgit.util.IO; |
|
|
|
import org.eclipse.jgit.util.RawParseUtils; |
|
|
|
import org.eclipse.jgit.util.RawParseUtils; |
|
|
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* The configuration file that is stored in the file of the file system. |
|
|
|
* The configuration file that is stored in the file of the file system. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class FileBasedConfig extends StoredConfig { |
|
|
|
public class FileBasedConfig extends StoredConfig { |
|
|
|
|
|
|
|
private final static Logger LOG = LoggerFactory |
|
|
|
|
|
|
|
.getLogger(FileBasedConfig.class); |
|
|
|
|
|
|
|
|
|
|
|
private final File configFile; |
|
|
|
private final File configFile; |
|
|
|
|
|
|
|
|
|
|
|
private final FS fs; |
|
|
|
private final FS fs; |
|
|
@ -141,40 +147,58 @@ public class FileBasedConfig extends StoredConfig { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void load() throws IOException, ConfigInvalidException { |
|
|
|
public void load() throws IOException, ConfigInvalidException { |
|
|
|
final FileSnapshot oldSnapshot = snapshot; |
|
|
|
final int maxStaleRetries = 5; |
|
|
|
final FileSnapshot newSnapshot = FileSnapshot.save(getFile()); |
|
|
|
int retries = 0; |
|
|
|
try { |
|
|
|
while (true) { |
|
|
|
final byte[] in = IO.readFully(getFile()); |
|
|
|
final FileSnapshot oldSnapshot = snapshot; |
|
|
|
final ObjectId newHash = hash(in); |
|
|
|
final FileSnapshot newSnapshot = FileSnapshot.save(getFile()); |
|
|
|
if (hash.equals(newHash)) { |
|
|
|
try { |
|
|
|
if (oldSnapshot.equals(newSnapshot)) |
|
|
|
final byte[] in = IO.readFully(getFile()); |
|
|
|
oldSnapshot.setClean(newSnapshot); |
|
|
|
final ObjectId newHash = hash(in); |
|
|
|
else |
|
|
|
if (hash.equals(newHash)) { |
|
|
|
snapshot = newSnapshot; |
|
|
|
if (oldSnapshot.equals(newSnapshot)) { |
|
|
|
} else { |
|
|
|
oldSnapshot.setClean(newSnapshot); |
|
|
|
final String decoded; |
|
|
|
} else { |
|
|
|
if (isUtf8(in)) { |
|
|
|
snapshot = newSnapshot; |
|
|
|
decoded = RawParseUtils.decode(RawParseUtils.UTF8_CHARSET, |
|
|
|
} |
|
|
|
in, 3, in.length); |
|
|
|
|
|
|
|
utf8Bom = true; |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
decoded = RawParseUtils.decode(in); |
|
|
|
final String decoded; |
|
|
|
|
|
|
|
if (isUtf8(in)) { |
|
|
|
|
|
|
|
decoded = RawParseUtils.decode( |
|
|
|
|
|
|
|
RawParseUtils.UTF8_CHARSET, in, 3, in.length); |
|
|
|
|
|
|
|
utf8Bom = true; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
decoded = RawParseUtils.decode(in); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
fromText(decoded); |
|
|
|
|
|
|
|
snapshot = newSnapshot; |
|
|
|
|
|
|
|
hash = newHash; |
|
|
|
} |
|
|
|
} |
|
|
|
fromText(decoded); |
|
|
|
return; |
|
|
|
|
|
|
|
} catch (FileNotFoundException noFile) { |
|
|
|
|
|
|
|
if (configFile.exists()) { |
|
|
|
|
|
|
|
throw noFile; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
clear(); |
|
|
|
snapshot = newSnapshot; |
|
|
|
snapshot = newSnapshot; |
|
|
|
hash = newHash; |
|
|
|
return; |
|
|
|
} |
|
|
|
} catch (IOException e) { |
|
|
|
} catch (FileNotFoundException noFile) { |
|
|
|
if (FileUtils.isStaleFileHandle(e) |
|
|
|
if (configFile.exists()) { |
|
|
|
&& retries < maxStaleRetries) { |
|
|
|
throw noFile; |
|
|
|
if (LOG.isDebugEnabled()) { |
|
|
|
|
|
|
|
LOG.debug(MessageFormat.format( |
|
|
|
|
|
|
|
JGitText.get().configHandleIsStale, |
|
|
|
|
|
|
|
Integer.valueOf(retries)), e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
retries++; |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
throw new IOException(MessageFormat |
|
|
|
|
|
|
|
.format(JGitText.get().cannotReadFile, getFile()), e); |
|
|
|
|
|
|
|
} catch (ConfigInvalidException e) { |
|
|
|
|
|
|
|
throw new ConfigInvalidException(MessageFormat |
|
|
|
|
|
|
|
.format(JGitText.get().cannotReadFile, getFile()), e); |
|
|
|
} |
|
|
|
} |
|
|
|
clear(); |
|
|
|
|
|
|
|
snapshot = newSnapshot; |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
|
|
|
|
throw new IOException(MessageFormat |
|
|
|
|
|
|
|
.format(JGitText.get().cannotReadFile, getFile()), e); |
|
|
|
|
|
|
|
} catch (ConfigInvalidException e) { |
|
|
|
|
|
|
|
throw new ConfigInvalidException(MessageFormat.format(JGitText.get().cannotReadFile, getFile()), e); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|