summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2017-12-16 14:04:01 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2017-12-16 14:04:01 +0100
commited38840ebae6f9173deaf91c20396622d6a0407f (patch)
tree2e56fc73211d19d7d2ec39f6073cf083ab043286
parent99e70530b918fdbe453524bf165844ad65da581f (diff)
parent1e56842742ebd42e46206b0a870d24217e5a7be8 (diff)
downloadjgit-ed38840ebae6f9173deaf91c20396622d6a0407f.tar.gz
jgit-ed38840ebae6f9173deaf91c20396622d6a0407f.zip
Merge branch 'stable-4.9'
* stable-4.9: Prepare 4.9.3-SNAPSHOT builds JGit v4.9.2.201712150930-r Write packed-refs directly when cloning Change-Id: I3b0fad9c45cdf3a918ddb8ea4a37b8d3403aae90 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackedBatchRefUpdate.java16
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java26
2 files changed, 37 insertions, 5 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackedBatchRefUpdate.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackedBatchRefUpdate.java
index ad2500059a..a69f519280 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackedBatchRefUpdate.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackedBatchRefUpdate.java
@@ -186,11 +186,19 @@ class PackedBatchRefUpdate extends BatchRefUpdate {
Map<String, LockFile> locks = null;
refdb.inProcessPackedRefsLock.lock();
try {
- locks = lockLooseRefs(pending);
- if (locks == null) {
- return;
+ PackedRefList oldPackedList;
+ if (!refdb.isInClone()) {
+ locks = lockLooseRefs(pending);
+ if (locks == null) {
+ return;
+ }
+ oldPackedList = refdb.pack(locks);
+ } else {
+ // During clone locking isn't needed since no refs exist yet.
+ // This also helps to avoid problems with refs only differing in
+ // case on a case insensitive filesystem (bug 528497)
+ oldPackedList = refdb.getPackedRefs();
}
- PackedRefList oldPackedList = refdb.pack(locks);
RefList<Ref> newRefs = applyUpdates(walk, oldPackedList, pending);
if (newRefs == null) {
return;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
index a44acacd12..bd39e65657 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
@@ -65,6 +65,7 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.InterruptedIOException;
+import java.nio.file.Files;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.text.MessageFormat;
@@ -901,7 +902,7 @@ public class RefDirectory extends RefDatabase {
return ref;
}
- private PackedRefList getPackedRefs() throws IOException {
+ PackedRefList getPackedRefs() throws IOException {
boolean trustFolderStat = getRepository().getConfig().getBoolean(
ConfigConstants.CONFIG_CORE_SECTION,
ConfigConstants.CONFIG_KEY_TRUSTFOLDERSTAT, true);
@@ -1188,6 +1189,29 @@ public class RefDirectory extends RefDatabase {
&& buf[4] == ' ';
}
+ /**
+ * Detect if we are in a clone command execution
+ *
+ * @return {@code true} if we are currently cloning a repository
+ * @throws IOException
+ */
+ boolean isInClone() throws IOException {
+ return hasDanglingHead() && !packedRefsFile.exists() && !hasLooseRef();
+ }
+
+ private boolean hasDanglingHead() throws IOException {
+ Ref head = exactRef(Constants.HEAD);
+ if (head != null) {
+ ObjectId id = head.getObjectId();
+ return id == null || id.equals(ObjectId.zeroId());
+ }
+ return false;
+ }
+
+ private boolean hasLooseRef() throws IOException {
+ return Files.walk(refsDir.toPath()).anyMatch(Files::isRegularFile);
+ }
+
/** If the parent should fire listeners, fires them. */
void fireRefsChanged() {
final int last = lastNotifiedModCnt.get();