summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2022-03-08 17:23:57 +0100
committerMatthias Sohn <matthias.sohn@sap.com>2022-03-09 21:45:35 +0100
commit338f2adf160fdd72ee137e416174526d5c35eb18 (patch)
tree2d55def305066a654c46e335ed840bda6fef1bea /org.eclipse.jgit
parent600e96dfdc6769b7da6e2b2daea74cf69791da7a (diff)
parent8f7ef245f0c156730ef74ff3fe838c330728fc7f (diff)
downloadjgit-338f2adf160fdd72ee137e416174526d5c35eb18.tar.gz
jgit-338f2adf160fdd72ee137e416174526d5c35eb18.zip
Merge branch 'stable-6.1'
* stable-6.1: Prepare 6.1.1-SNAPSHOT builds JGit v6.1.0.202203080745-r [checkout] Use .gitattributes from the commit to be checked out Don't use final for method parameters [push] support the "matching" RefSpecs ":" and "+:" [push] Call the pre-push hook later in the push process IndexDiff: use tree filter also for SubmoduleWalk Run license check with option -Ddash.projectId=technology.jgit Exclude transitive dependencies of sshd-sftp Update DEPENDENCIES for 6.1.0 release Add dependency to dash-licenses Fix typos of some keys in LfsText Sort LfsText entries alphabetically Support for "lfs.url" from ".lfsconfig" Change-Id: I1b9f0c0ed647837e00b9640d235dbfab2329c5a6
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/.settings/.api_filters20
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/attributes/AttributesHandler.java80
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java63
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java3
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java99
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/PushProcess.java204
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/RefSpec.java81
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/RemoteRefUpdate.java122
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java21
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java205
11 files changed, 661 insertions, 239 deletions
diff --git a/org.eclipse.jgit/.settings/.api_filters b/org.eclipse.jgit/.settings/.api_filters
index e026e31dc5..00b89a4b3d 100644
--- a/org.eclipse.jgit/.settings/.api_filters
+++ b/org.eclipse.jgit/.settings/.api_filters
@@ -39,6 +39,26 @@
</message_arguments>
</filter>
</resource>
+ <resource path="src/org/eclipse/jgit/merge/ResolveMerger.java" type="org.eclipse.jgit.merge.ResolveMerger">
+ <filter id="338792546">
+ <message_arguments>
+ <message_argument value="org.eclipse.jgit.merge.ResolveMerger"/>
+ <message_argument value="addCheckoutMetadata(String, Attributes)"/>
+ </message_arguments>
+ </filter>
+ <filter id="338792546">
+ <message_arguments>
+ <message_argument value="org.eclipse.jgit.merge.ResolveMerger"/>
+ <message_argument value="addToCheckout(String, DirCacheEntry, Attributes)"/>
+ </message_arguments>
+ </filter>
+ <filter id="338792546">
+ <message_arguments>
+ <message_argument value="org.eclipse.jgit.merge.ResolveMerger"/>
+ <message_argument value="processEntry(CanonicalTreeParser, CanonicalTreeParser, CanonicalTreeParser, DirCacheBuildIterator, WorkingTreeIterator, boolean, Attributes)"/>
+ </message_arguments>
+ </filter>
+ </resource>
<resource path="src/org/eclipse/jgit/transport/BasePackPushConnection.java" type="org.eclipse.jgit.transport.BasePackPushConnection">
<filter id="338792546">
<message_arguments>
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java
index 4f57f35127..08353dfdfa 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java
@@ -230,7 +230,7 @@ public class PushCommand extends
refSpecs.add(new RefSpec(getCurrentBranch()));
break;
case MATCHING:
- setPushAll();
+ refSpecs.add(new RefSpec(":")); //$NON-NLS-1$
break;
case NOTHING:
throw new InvalidRefNameException(
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/attributes/AttributesHandler.java b/org.eclipse.jgit/src/org/eclipse/jgit/attributes/AttributesHandler.java
index 638dd827ed..7ec78597fa 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/attributes/AttributesHandler.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/attributes/AttributesHandler.java
@@ -1,43 +1,11 @@
/*
- * Copyright (C) 2015, Ivan Motsch <ivan.motsch@bsiag.com>
+ * Copyright (C) 2015, 2022 Ivan Motsch <ivan.motsch@bsiag.com> and others
*
- * This program and the accompanying materials are made available
- * under the terms of the Eclipse Distribution License v1.0 which
- * accompanies this distribution, is reproduced below, and is
- * available at http://www.eclipse.org/org/documents/edl-v10.php
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Distribution License v. 1.0 which is available at
+ * https://www.eclipse.org/org/documents/edl-v10.php.
*
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the following
- * conditions are met:
- *
- * - Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * - Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following
- * disclaimer in the documentation and/or other materials provided
- * with the distribution.
- *
- * - Neither the name of the Eclipse Foundation, Inc. nor the
- * names of its contributors may be used to endorse or promote
- * products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
- * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * SPDX-License-Identifier: BSD-3-Clause
*/
package org.eclipse.jgit.attributes;
@@ -46,6 +14,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
+import java.util.function.Supplier;
import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.attributes.Attribute.State;
@@ -84,6 +53,8 @@ public class AttributesHandler {
private final TreeWalk treeWalk;
+ private final Supplier<CanonicalTreeParser> attributesTree;
+
private final AttributesNode globalNode;
private final AttributesNode infoNode;
@@ -98,22 +69,41 @@ public class AttributesHandler {
* @param treeWalk
* a {@link org.eclipse.jgit.treewalk.TreeWalk}
* @throws java.io.IOException
+ * @deprecated since 6.1, use {@link #AttributesHandler(TreeWalk, Supplier)}
+ * instead
*/
+ @Deprecated
public AttributesHandler(TreeWalk treeWalk) throws IOException {
+ this(treeWalk, () -> treeWalk.getTree(CanonicalTreeParser.class));
+ }
+
+ /**
+ * Create an {@link org.eclipse.jgit.attributes.AttributesHandler} with
+ * default rules as well as merged rules from global, info and worktree root
+ * attributes
+ *
+ * @param treeWalk
+ * a {@link org.eclipse.jgit.treewalk.TreeWalk}
+ * @param attributesTree
+ * the tree to read .gitattributes from
+ * @throws java.io.IOException
+ * @since 6.1
+ */
+ public AttributesHandler(TreeWalk treeWalk,
+ Supplier<CanonicalTreeParser> attributesTree) throws IOException {
this.treeWalk = treeWalk;
- AttributesNodeProvider attributesNodeProvider =treeWalk.getAttributesNodeProvider();
+ this.attributesTree = attributesTree;
+ AttributesNodeProvider attributesNodeProvider = treeWalk
+ .getAttributesNodeProvider();
this.globalNode = attributesNodeProvider != null
? attributesNodeProvider.getGlobalAttributesNode() : null;
this.infoNode = attributesNodeProvider != null
? attributesNodeProvider.getInfoAttributesNode() : null;
AttributesNode rootNode = attributesNode(treeWalk,
- rootOf(
- treeWalk.getTree(WorkingTreeIterator.class)),
- rootOf(
- treeWalk.getTree(DirCacheIterator.class)),
- rootOf(treeWalk
- .getTree(CanonicalTreeParser.class)));
+ rootOf(treeWalk.getTree(WorkingTreeIterator.class)),
+ rootOf(treeWalk.getTree(DirCacheIterator.class)),
+ rootOf(attributesTree.get()));
expansions.put(BINARY_RULE_KEY, BINARY_RULE_ATTRIBUTES);
for (AttributesNode node : new AttributesNode[] { globalNode, rootNode,
@@ -152,7 +142,7 @@ public class AttributesHandler {
isDirectory,
treeWalk.getTree(WorkingTreeIterator.class),
treeWalk.getTree(DirCacheIterator.class),
- treeWalk.getTree(CanonicalTreeParser.class),
+ attributesTree.get(),
attributes);
// Gets the attributes located in the global attribute file
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java
index c904a782db..3d50a82155 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java
@@ -4,7 +4,8 @@
* Copyright (C) 2008, Roger C. Soares <rogersoares@intelinet.com.br>
* Copyright (C) 2006, Shawn O. Pearce <spearce@spearce.org>
* Copyright (C) 2010, Chrisian Halstrick <christian.halstrick@sap.com>
- * Copyright (C) 2019-2020, Andre Bossert <andre.bossert@siemens.com>
+ * Copyright (C) 2019, 2020, Andre Bossert <andre.bossert@siemens.com>
+ * Copyright (C) 2017, 2022, Thomas Wolf <thomas.wolf@paranor.ch> and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
@@ -299,7 +300,7 @@ public class DirCacheCheckout {
walk = new NameConflictTreeWalk(repo);
builder = dc.builder();
- addTree(walk, headCommitTree);
+ walk.setHead(addTree(walk, headCommitTree));
addTree(walk, mergeCommitTree);
int dciPos = walk.addTree(new DirCacheBuildIterator(builder));
walk.addTree(workingTree);
@@ -315,13 +316,6 @@ public class DirCacheCheckout {
}
}
- private void addTree(TreeWalk tw, ObjectId id) throws MissingObjectException, IncorrectObjectTypeException, IOException {
- if (id == null)
- tw.addTree(new EmptyTreeIterator());
- else
- tw.addTree(id);
- }
-
/**
* Scan index and merge tree (no HEAD). Used e.g. for initial checkout when
* there is no head yet.
@@ -341,7 +335,7 @@ public class DirCacheCheckout {
builder = dc.builder();
walk = new NameConflictTreeWalk(repo);
- addTree(walk, mergeCommitTree);
+ walk.setHead(addTree(walk, mergeCommitTree));
int dciPos = walk.addTree(new DirCacheBuildIterator(builder));
walk.addTree(workingTree);
workingTree.setDirCacheIterator(walk, dciPos);
@@ -356,6 +350,14 @@ public class DirCacheCheckout {
conflicts.removeAll(removed);
}
+ private int addTree(TreeWalk tw, ObjectId id) throws MissingObjectException,
+ IncorrectObjectTypeException, IOException {
+ if (id == null) {
+ return tw.addTree(new EmptyTreeIterator());
+ }
+ return tw.addTree(id);
+ }
+
/**
* Processing an entry in the context of {@link #prescanOneTree()} when only
* one tree is given
@@ -382,17 +384,14 @@ public class DirCacheCheckout {
// failOnConflict is false. Putting something to conflicts
// would mean we delete it. Instead we want the mergeCommit
// content to be checked out.
- update(m.getEntryPathString(), m.getEntryObjectId(),
- m.getEntryFileMode());
+ update(m);
}
} else
- update(m.getEntryPathString(), m.getEntryObjectId(),
- m.getEntryFileMode());
+ update(m);
} else if (f == null || !m.idEqual(i)) {
// The working tree file is missing or the merge content differs
// from index content
- update(m.getEntryPathString(), m.getEntryObjectId(),
- m.getEntryFileMode());
+ update(m);
} else if (i.getDirCacheEntry() != null) {
// The index contains a file (and not a folder)
if (f.isModified(i.getDirCacheEntry(), true,
@@ -400,8 +399,7 @@ public class DirCacheCheckout {
|| i.getDirCacheEntry().getStage() != 0)
// The working tree file is dirty or the index contains a
// conflict
- update(m.getEntryPathString(), m.getEntryObjectId(),
- m.getEntryFileMode());
+ update(m);
else {
// update the timestamp of the index with the one from the
// file if not set, as we are sure to be in sync here.
@@ -802,7 +800,7 @@ public class DirCacheCheckout {
if (f != null && isModifiedSubtree_IndexWorkingtree(name)) {
conflict(name, dce, h, m); // 1
} else {
- update(name, mId, mMode); // 2
+ update(1, name, mId, mMode); // 2
}
break;
@@ -828,7 +826,7 @@ public class DirCacheCheckout {
// are found later
break;
case 0xD0F: // 19
- update(name, mId, mMode);
+ update(1, name, mId, mMode);
break;
case 0xDF0: // conflict without a rule
case 0x0FD: // 15
@@ -839,7 +837,7 @@ public class DirCacheCheckout {
if (isModifiedSubtree_IndexWorkingtree(name))
conflict(name, dce, h, m); // 8
else
- update(name, mId, mMode); // 7
+ update(1, name, mId, mMode); // 7
} else
conflict(name, dce, h, m); // 9
break;
@@ -859,7 +857,7 @@ public class DirCacheCheckout {
break;
case 0x0DF: // 16 17
if (!isModifiedSubtree_IndexWorkingtree(name))
- update(name, mId, mMode);
+ update(1, name, mId, mMode);
else
conflict(name, dce, h, m);
break;
@@ -929,7 +927,7 @@ public class DirCacheCheckout {
// At least one of Head, Index, Merge is not empty
// -> only Merge contains something for this path. Use it!
// Potentially update the file
- update(name, mId, mMode); // 1
+ update(1, name, mId, mMode); // 1
else if (m == null)
// Nothing in Merge
// Something in Head
@@ -947,7 +945,7 @@ public class DirCacheCheckout {
// find in Merge. Potentially updates the file.
if (equalIdAndMode(hId, hMode, mId, mMode)) {
if (initialCheckout || force) {
- update(name, mId, mMode);
+ update(1, name, mId, mMode);
} else {
keep(name, dce, f);
}
@@ -1131,7 +1129,7 @@ public class DirCacheCheckout {
// TODO check that we don't overwrite some unsaved
// file content
- update(name, mId, mMode);
+ update(1, name, mId, mMode);
} else if (dce != null
&& (f != null && f.isModified(dce, true,
this.walk.getObjectReader()))) {
@@ -1150,7 +1148,7 @@ public class DirCacheCheckout {
// -> Standard case when switching between branches:
// Nothing new in index but something different in
// Merge. Update index and file
- update(name, mId, mMode);
+ update(1, name, mId, mMode);
}
} else {
// Head differs from index or merge is same as index
@@ -1237,12 +1235,17 @@ public class DirCacheCheckout {
removed.add(path);
}
- private void update(String path, ObjectId mId, FileMode mode)
- throws IOException {
+ private void update(CanonicalTreeParser tree) throws IOException {
+ update(0, tree.getEntryPathString(), tree.getEntryObjectId(),
+ tree.getEntryFileMode());
+ }
+
+ private void update(int index, String path, ObjectId mId,
+ FileMode mode) throws IOException {
if (!FileMode.TREE.equals(mode)) {
updated.put(path, new CheckoutMetadata(
- walk.getEolStreamType(CHECKOUT_OP),
- walk.getFilterCommand(Constants.ATTR_FILTER_TYPE_SMUDGE)));
+ walk.getCheckoutEolStreamType(index),
+ walk.getSmudgeCommand(index)));
DirCacheEntry entry = new DirCacheEntry(path, DirCacheEntry.STAGE_0);
entry.setObjectId(mId);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
index 28ea927b14..df9fd47efa 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
@@ -568,6 +568,9 @@ public class IndexDiff {
if (ignoreSubmoduleMode != IgnoreSubmoduleMode.ALL) {
try (SubmoduleWalk smw = new SubmoduleWalk(repository)) {
smw.setTree(new DirCacheIterator(dirCache));
+ if (filter != null) {
+ smw.setFilter(filter);
+ }
smw.setBuilderFactory(factory);
while (smw.next()) {
IgnoreSubmoduleMode localIgnoreSubmoduleMode = ignoreSubmoduleMode;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java
index 7767662867..b9ab1d1b7a 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java
@@ -3,7 +3,7 @@
* Copyright (C) 2010-2012, Matthias Sohn <matthias.sohn@sap.com>
* Copyright (C) 2012, Research In Motion Limited
* Copyright (C) 2017, Obeo (mathieu.cartaud@obeo.fr)
- * Copyright (C) 2018, Thomas Wolf <thomas.wolf@paranor.ch> and others
+ * Copyright (C) 2018, 2022 Thomas Wolf <thomas.wolf@paranor.ch> and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
@@ -276,11 +276,15 @@ public class ResolveMerger extends ThreeWayMerger {
private ContentMergeStrategy contentStrategy = ContentMergeStrategy.CONFLICT;
/**
- * Keeps {@link CheckoutMetadata} for {@link #checkout()} and
- * {@link #cleanUp()}.
+ * Keeps {@link CheckoutMetadata} for {@link #checkout()}.
*/
private Map<String, CheckoutMetadata> checkoutMetadata;
+ /**
+ * Keeps {@link CheckoutMetadata} for {@link #cleanUp()}.
+ */
+ private Map<String, CheckoutMetadata> cleanupMetadata;
+
private static MergeAlgorithm getMergeAlgorithm(Config config) {
SupportedAlgorithm diffAlg = config.getEnum(
CONFIG_DIFF_SECTION, null, CONFIG_KEY_ALGORITHM,
@@ -383,12 +387,14 @@ public class ResolveMerger extends ThreeWayMerger {
}
if (!inCore) {
checkoutMetadata = new HashMap<>();
+ cleanupMetadata = new HashMap<>();
}
try {
return mergeTrees(mergeBase(), sourceTrees[0], sourceTrees[1],
false);
} finally {
checkoutMetadata = null;
+ cleanupMetadata = null;
if (implicitDirCache) {
dircache.unlock();
}
@@ -447,7 +453,7 @@ public class ResolveMerger extends ThreeWayMerger {
DirCacheEntry entry = dc.getEntry(mpath);
if (entry != null) {
DirCacheCheckout.checkoutEntry(db, entry, reader, false,
- checkoutMetadata.get(mpath));
+ cleanupMetadata.get(mpath));
}
mpathsIt.remove();
}
@@ -501,22 +507,26 @@ public class ResolveMerger extends ThreeWayMerger {
* Remembers the {@link CheckoutMetadata} for the given path; it may be
* needed in {@link #checkout()} or in {@link #cleanUp()}.
*
+ * @param map
+ * to add the metadata to
* @param path
* of the current node
* @param attributes
- * for the current node
+ * to use for determining the metadata
* @throws IOException
* if the smudge filter cannot be determined
- * @since 5.1
+ * @since 6.1
*/
- protected void addCheckoutMetadata(String path, Attributes attributes)
+ protected void addCheckoutMetadata(Map<String, CheckoutMetadata> map,
+ String path, Attributes attributes)
throws IOException {
- if (checkoutMetadata != null) {
+ if (map != null) {
EolStreamType eol = EolStreamTypeUtil.detectStreamType(
- OperationType.CHECKOUT_OP, workingTreeOptions, attributes);
+ OperationType.CHECKOUT_OP, workingTreeOptions,
+ attributes);
CheckoutMetadata data = new CheckoutMetadata(eol,
- tw.getFilterCommand(Constants.ATTR_FILTER_TYPE_SMUDGE));
- checkoutMetadata.put(path, data);
+ tw.getSmudgeCommand(attributes));
+ map.put(path, data);
}
}
@@ -529,15 +539,17 @@ public class ResolveMerger extends ThreeWayMerger {
* @param entry
* to add
* @param attributes
- * for the current entry
+ * the {@link Attributes} of the trees
* @throws IOException
* if the {@link CheckoutMetadata} cannot be determined
- * @since 5.1
+ * @since 6.1
*/
protected void addToCheckout(String path, DirCacheEntry entry,
- Attributes attributes) throws IOException {
+ Attributes[] attributes)
+ throws IOException {
toBeCheckedOut.put(path, entry);
- addCheckoutMetadata(path, attributes);
+ addCheckoutMetadata(cleanupMetadata, path, attributes[T_OURS]);
+ addCheckoutMetadata(checkoutMetadata, path, attributes[T_THEIRS]);
}
/**
@@ -549,7 +561,7 @@ public class ResolveMerger extends ThreeWayMerger {
* @param isFile
* whether it is a file
* @param attributes
- * for the entry
+ * to use for determining the {@link CheckoutMetadata}
* @throws IOException
* if the {@link CheckoutMetadata} cannot be determined
* @since 5.1
@@ -558,7 +570,7 @@ public class ResolveMerger extends ThreeWayMerger {
Attributes attributes) throws IOException {
toBeDeleted.add(path);
if (isFile) {
- addCheckoutMetadata(path, attributes);
+ addCheckoutMetadata(cleanupMetadata, path, attributes);
}
}
@@ -599,7 +611,7 @@ public class ResolveMerger extends ThreeWayMerger {
* see
* {@link org.eclipse.jgit.merge.ResolveMerger#mergeTrees(AbstractTreeIterator, RevTree, RevTree, boolean)}
* @param attributes
- * the attributes defined for this entry
+ * the {@link Attributes} for the three trees
* @return <code>false</code> if the merge will fail because the index entry
* didn't match ours or the working-dir file was dirty and a
* conflict occurred
@@ -607,12 +619,12 @@ public class ResolveMerger extends ThreeWayMerger {
* @throws org.eclipse.jgit.errors.IncorrectObjectTypeException
* @throws org.eclipse.jgit.errors.CorruptObjectException
* @throws java.io.IOException
- * @since 4.9
+ * @since 6.1
*/
protected boolean processEntry(CanonicalTreeParser base,
CanonicalTreeParser ours, CanonicalTreeParser theirs,
DirCacheBuildIterator index, WorkingTreeIterator work,
- boolean ignoreConflicts, Attributes attributes)
+ boolean ignoreConflicts, Attributes[] attributes)
throws MissingObjectException, IncorrectObjectTypeException,
CorruptObjectException, IOException {
enterSubtree = true;
@@ -729,7 +741,7 @@ public class ResolveMerger extends ThreeWayMerger {
// Base, ours, and theirs all contain a folder: don't delete
return true;
}
- addDeletion(tw.getPathString(), nonTree(modeO), attributes);
+ addDeletion(tw.getPathString(), nonTree(modeO), attributes[T_OURS]);
return true;
}
@@ -772,7 +784,7 @@ public class ResolveMerger extends ThreeWayMerger {
if (nonTree(modeO) && nonTree(modeT)) {
// Check worktree before modifying files
boolean worktreeDirty = isWorktreeDirty(work, ourDce);
- if (!attributes.canBeContentMerged() && worktreeDirty) {
+ if (!attributes[T_OURS].canBeContentMerged() && worktreeDirty) {
return false;
}
@@ -791,7 +803,7 @@ public class ResolveMerger extends ThreeWayMerger {
mergeResults.put(tw.getPathString(), result);
unmergedPaths.add(tw.getPathString());
return true;
- } else if (!attributes.canBeContentMerged()) {
+ } else if (!attributes[T_OURS].canBeContentMerged()) {
// File marked as binary
switch (getContentMergeStrategy()) {
case OURS:
@@ -842,13 +854,16 @@ public class ResolveMerger extends ThreeWayMerger {
if (ignoreConflicts) {
result.setContainsConflicts(false);
}
- updateIndex(base, ours, theirs, result, attributes);
+ updateIndex(base, ours, theirs, result, attributes[T_OURS]);
String currentPath = tw.getPathString();
if (result.containsConflicts() && !ignoreConflicts) {
unmergedPaths.add(currentPath);
}
modifiedFiles.add(currentPath);
- addCheckoutMetadata(currentPath, attributes);
+ addCheckoutMetadata(cleanupMetadata, currentPath,
+ attributes[T_OURS]);
+ addCheckoutMetadata(checkoutMetadata, currentPath,
+ attributes[T_THEIRS]);
} else if (modeO != modeT) {
// OURS or THEIRS has been deleted
if (((modeO != 0 && !tw.idEqual(T_BASE, T_OURS)) || (modeT != 0 && !tw
@@ -881,7 +896,8 @@ public class ResolveMerger extends ThreeWayMerger {
// markers). But also stage 0 of the index is filled
// with that content.
result.setContainsConflicts(false);
- updateIndex(base, ours, theirs, result, attributes);
+ updateIndex(base, ours, theirs, result,
+ attributes[T_OURS]);
} else {
add(tw.getRawPath(), base, DirCacheEntry.STAGE_1, EPOCH,
0);
@@ -896,11 +912,9 @@ public class ResolveMerger extends ThreeWayMerger {
if (isWorktreeDirty(work, ourDce)) {
return false;
}
- if (nonTree(modeT)) {
- if (e != null) {
- addToCheckout(tw.getPathString(), e,
- attributes);
- }
+ if (nonTree(modeT) && e != null) {
+ addToCheckout(tw.getPathString(), e,
+ attributes);
}
}
@@ -945,14 +959,16 @@ public class ResolveMerger extends ThreeWayMerger {
*/
private MergeResult<RawText> contentMerge(CanonicalTreeParser base,
CanonicalTreeParser ours, CanonicalTreeParser theirs,
- Attributes attributes, ContentMergeStrategy strategy)
+ Attributes[] attributes, ContentMergeStrategy strategy)
throws BinaryBlobException, IOException {
+ // TW: The attributes here are used to determine the LFS smudge filter.
+ // Is doing a content merge on LFS items really a good idea??
RawText baseText = base == null ? RawText.EMPTY_TEXT
- : getRawText(base.getEntryObjectId(), attributes);
+ : getRawText(base.getEntryObjectId(), attributes[T_BASE]);
RawText ourText = ours == null ? RawText.EMPTY_TEXT
- : getRawText(ours.getEntryObjectId(), attributes);
+ : getRawText(ours.getEntryObjectId(), attributes[T_OURS]);
RawText theirsText = theirs == null ? RawText.EMPTY_TEXT
- : getRawText(theirs.getEntryObjectId(), attributes);
+ : getRawText(theirs.getEntryObjectId(), attributes[T_THEIRS]);
mergeAlgorithm.setContentMergeStrategy(strategy);
return mergeAlgorithm.merge(RawTextComparator.DEFAULT, baseText,
ourText, theirsText);
@@ -1342,7 +1358,7 @@ public class ResolveMerger extends ThreeWayMerger {
tw = new NameConflictTreeWalk(db, reader);
tw.addTree(baseTree);
- tw.addTree(headTree);
+ tw.setHead(tw.addTree(headTree));
tw.addTree(mergeTree);
int dciPos = tw.addTree(buildIt);
if (workingTreeIterator != null) {
@@ -1403,6 +1419,13 @@ public class ResolveMerger extends ThreeWayMerger {
boolean hasAttributeNodeProvider = treeWalk
.getAttributesNodeProvider() != null;
while (treeWalk.next()) {
+ Attributes[] attributes = { NO_ATTRIBUTES, NO_ATTRIBUTES,
+ NO_ATTRIBUTES };
+ if (hasAttributeNodeProvider) {
+ attributes[T_BASE] = treeWalk.getAttributes(T_BASE);
+ attributes[T_OURS] = treeWalk.getAttributes(T_OURS);
+ attributes[T_THEIRS] = treeWalk.getAttributes(T_THEIRS);
+ }
if (!processEntry(
treeWalk.getTree(T_BASE, CanonicalTreeParser.class),
treeWalk.getTree(T_OURS, CanonicalTreeParser.class),
@@ -1410,9 +1433,7 @@ public class ResolveMerger extends ThreeWayMerger {
treeWalk.getTree(T_INDEX, DirCacheBuildIterator.class),
hasWorkingTreeIterator ? treeWalk.getTree(T_FILE,
WorkingTreeIterator.class) : null,
- ignoreConflicts, hasAttributeNodeProvider
- ? treeWalk.getAttributes()
- : NO_ATTRIBUTES)) {
+ ignoreConflicts, attributes)) {
cleanUp();
return false;
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushProcess.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushProcess.java
index a244c55a38..942dad46e0 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushProcess.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/PushProcess.java
@@ -18,11 +18,15 @@ import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.stream.Collectors;
+import org.eclipse.jgit.api.errors.AbortedByHookException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.errors.NotSupportedException;
import org.eclipse.jgit.errors.TransportException;
+import org.eclipse.jgit.hooks.PrePushHook;
import org.eclipse.jgit.internal.JGitText;
+import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.lib.Ref;
@@ -58,6 +62,8 @@ class PushProcess {
/** A list of option strings associated with this push */
private List<String> pushOptions;
+ private final PrePushHook prePush;
+
/**
* Create process for specified transport and refs updates specification.
*
@@ -66,12 +72,14 @@ class PushProcess {
* connection.
* @param toPush
* specification of refs updates (and local tracking branches).
- *
+ * @param prePush
+ * {@link PrePushHook} to run after the remote advertisement has
+ * been gotten
* @throws TransportException
*/
- PushProcess(final Transport transport,
- final Collection<RemoteRefUpdate> toPush) throws TransportException {
- this(transport, toPush, null);
+ PushProcess(Transport transport, Collection<RemoteRefUpdate> toPush,
+ PrePushHook prePush) throws TransportException {
+ this(transport, toPush, prePush, null);
}
/**
@@ -82,16 +90,19 @@ class PushProcess {
* connection.
* @param toPush
* specification of refs updates (and local tracking branches).
+ * @param prePush
+ * {@link PrePushHook} to run after the remote advertisement has
+ * been gotten
* @param out
* OutputStream to write messages to
* @throws TransportException
*/
- PushProcess(final Transport transport,
- final Collection<RemoteRefUpdate> toPush, OutputStream out)
- throws TransportException {
+ PushProcess(Transport transport, Collection<RemoteRefUpdate> toPush,
+ PrePushHook prePush, OutputStream out) throws TransportException {
this.walker = new RevWalk(transport.local);
this.transport = transport;
this.toPush = new LinkedHashMap<>();
+ this.prePush = prePush;
this.out = out;
this.pushOptions = transport.getPushOptions();
for (RemoteRefUpdate rru : toPush) {
@@ -129,10 +140,38 @@ class PushProcess {
res.setAdvertisedRefs(transport.getURI(), connection
.getRefsMap());
res.peerUserAgent = connection.getPeerUserAgent();
- res.setRemoteUpdates(toPush);
monitor.endTask();
+ Map<String, RemoteRefUpdate> expanded = expandMatching();
+ toPush.clear();
+ toPush.putAll(expanded);
+
+ res.setRemoteUpdates(toPush);
final Map<String, RemoteRefUpdate> preprocessed = prepareRemoteUpdates();
+ List<RemoteRefUpdate> willBeAttempted = preprocessed.values()
+ .stream().filter(u -> {
+ switch (u.getStatus()) {
+ case NON_EXISTING:
+ case REJECTED_NODELETE:
+ case REJECTED_NONFASTFORWARD:
+ case REJECTED_OTHER_REASON:
+ case REJECTED_REMOTE_CHANGED:
+ case UP_TO_DATE:
+ return false;
+ default:
+ return true;
+ }
+ }).collect(Collectors.toList());
+ if (!willBeAttempted.isEmpty()) {
+ if (prePush != null) {
+ try {
+ prePush.setRefs(willBeAttempted);
+ prePush.call();
+ } catch (AbortedByHookException | IOException e) {
+ throw new TransportException(e.getMessage(), e);
+ }
+ }
+ }
if (transport.isDryRun())
modifyUpdatesForDryRun();
else if (!preprocessed.isEmpty())
@@ -201,25 +240,8 @@ class PushProcess {
continue;
}
- // check for fast-forward:
- // - both old and new ref must point to commits, AND
- // - both of them must be known for us, exist in repository, AND
- // - old commit must be ancestor of new commit
- boolean fastForward = true;
- try {
- RevObject oldRev = walker.parseAny(advertisedOld);
- final RevObject newRev = walker.parseAny(rru.getNewObjectId());
- if (!(oldRev instanceof RevCommit)
- || !(newRev instanceof RevCommit)
- || !walker.isMergedInto((RevCommit) oldRev,
- (RevCommit) newRev))
- fastForward = false;
- } catch (MissingObjectException x) {
- fastForward = false;
- } catch (Exception x) {
- throw new TransportException(transport.getURI(), MessageFormat.format(
- JGitText.get().readingObjectsFromLocalRepositoryFailed, x.getMessage()), x);
- }
+ boolean fastForward = isFastForward(advertisedOld,
+ rru.getNewObjectId());
rru.setFastForward(fastForward);
if (!fastForward && !rru.isForceUpdate()) {
rru.setStatus(Status.REJECTED_NONFASTFORWARD);
@@ -233,6 +255,134 @@ class PushProcess {
return result;
}
+ /**
+ * Determines whether an update from {@code oldOid} to {@code newOid} is a
+ * fast-forward update:
+ * <ul>
+ * <li>both old and new must be commits, AND</li>
+ * <li>both of them must be known to us and exist in the repository,
+ * AND</li>
+ * <li>the old commit must be an ancestor of the new commit.</li>
+ * </ul>
+ *
+ * @param oldOid
+ * {@link ObjectId} of the old commit
+ * @param newOid
+ * {@link ObjectId} of the new commit
+ * @return {@code true} if the update fast-forwards, {@code false} otherwise
+ * @throws TransportException
+ */
+ private boolean isFastForward(ObjectId oldOid, ObjectId newOid)
+ throws TransportException {
+ try {
+ RevObject oldRev = walker.parseAny(oldOid);
+ RevObject newRev = walker.parseAny(newOid);
+ if (!(oldRev instanceof RevCommit) || !(newRev instanceof RevCommit)
+ || !walker.isMergedInto((RevCommit) oldRev,
+ (RevCommit) newRev)) {
+ return false;
+ }
+ } catch (MissingObjectException x) {
+ return false;
+ } catch (Exception x) {
+ throw new TransportException(transport.getURI(),
+ MessageFormat.format(JGitText
+ .get().readingObjectsFromLocalRepositoryFailed,
+ x.getMessage()),
+ x);
+ }
+ return true;
+ }
+
+ /**
+ * Expands all placeholder {@link RemoteRefUpdate}s for "matching"
+ * {@link RefSpec}s ":" in {@link #toPush} and returns the resulting map in
+ * which the placeholders have been replaced by their expansion.
+ *
+ * @return a new map of {@link RemoteRefUpdate}s keyed by remote name
+ * @throws TransportException
+ * if the expansion results in duplicate updates
+ */
+ private Map<String, RemoteRefUpdate> expandMatching()
+ throws TransportException {
+ Map<String, RemoteRefUpdate> result = new LinkedHashMap<>();
+ boolean hadMatch = false;
+ for (RemoteRefUpdate update : toPush.values()) {
+ if (update.isMatching()) {
+ if (hadMatch) {
+ throw new TransportException(MessageFormat.format(
+ JGitText.get().duplicateRemoteRefUpdateIsIllegal,
+ ":")); //$NON-NLS-1$
+ }
+ expandMatching(result, update);
+ hadMatch = true;
+ } else if (result.put(update.getRemoteName(), update) != null) {
+ throw new TransportException(MessageFormat.format(
+ JGitText.get().duplicateRemoteRefUpdateIsIllegal,
+ update.getRemoteName()));
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Expands the placeholder {@link RemoteRefUpdate} {@code match} for a
+ * "matching" {@link RefSpec} ":" or "+:" and puts the expansion into the
+ * given map {@code updates}.
+ *
+ * @param updates
+ * map to put the expansion in
+ * @param match
+ * the placeholder {@link RemoteRefUpdate} to expand
+ *
+ * @throws TransportException
+ * if the expansion results in duplicate updates, or the local
+ * branches cannot be determined
+ */
+ private void expandMatching(Map<String, RemoteRefUpdate> updates,
+ RemoteRefUpdate match) throws TransportException {
+ try {
+ Map<String, Ref> advertisement = connection.getRefsMap();
+ Collection<RefSpec> fetchSpecs = match.getFetchSpecs();
+ boolean forceUpdate = match.isForceUpdate();
+ for (Ref local : transport.local.getRefDatabase()
+ .getRefsByPrefix(Constants.R_HEADS)) {
+ if (local.isSymbolic()) {
+ continue;
+ }
+ String name = local.getName();
+ Ref advertised = advertisement.get(name);
+ if (advertised == null || advertised.isSymbolic()) {
+ continue;
+ }
+ ObjectId oldOid = advertised.getObjectId();
+ if (oldOid == null || ObjectId.zeroId().equals(oldOid)) {
+ continue;
+ }
+ ObjectId newOid = local.getObjectId();
+ if (newOid == null || ObjectId.zeroId().equals(newOid)) {
+ continue;
+ }
+
+ RemoteRefUpdate rru = new RemoteRefUpdate(transport.local, name,
+ newOid, name, forceUpdate,
+ Transport.findTrackingRefName(name, fetchSpecs),
+ oldOid);
+ if (updates.put(rru.getRemoteName(), rru) != null) {
+ throw new TransportException(MessageFormat.format(
+ JGitText.get().duplicateRemoteRefUpdateIsIllegal,
+ rru.getRemoteName()));
+ }
+ }
+ } catch (IOException x) {
+ throw new TransportException(transport.getURI(),
+ MessageFormat.format(JGitText
+ .get().readingObjectsFromLocalRepositoryFailed,
+ x.getMessage()),
+ x);
+ }
+ }
+
private Map<String, RemoteRefUpdate> rejectAll() {
for (RemoteRefUpdate rru : toPush.values()) {
if (rru.getStatus() == Status.NOT_ATTEMPTED) {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefSpec.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefSpec.java
index ac357afdae..56d0036a20 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefSpec.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RefSpec.java
@@ -12,11 +12,11 @@ package org.eclipse.jgit.transport;
import java.io.Serializable;
import java.text.MessageFormat;
+import java.util.Objects;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.Ref;
-import org.eclipse.jgit.util.References;
/**
* Describes how refs in one repository copy into another repository.
@@ -50,6 +50,9 @@ public class RefSpec implements Serializable {
/** Is this specification actually a wildcard match? */
private boolean wildcard;
+ /** Is this the special ":" RefSpec? */
+ private boolean matching;
+
/**
* How strict to be about wildcards.
*
@@ -71,6 +74,7 @@ public class RefSpec implements Serializable {
*/
ALLOW_MISMATCH
}
+
/** Whether a wildcard is allowed on one side but not the other. */
private WildcardMode allowMismatchedWildcards;
@@ -87,6 +91,7 @@ public class RefSpec implements Serializable {
* applications, as at least one field must be set to match a source name.
*/
public RefSpec() {
+ matching = false;
force = false;
wildcard = false;
srcName = Constants.HEAD;
@@ -133,17 +138,25 @@ public class RefSpec implements Serializable {
s = s.substring(1);
}
+ boolean matchPushSpec = false;
final int c = s.lastIndexOf(':');
if (c == 0) {
s = s.substring(1);
- if (isWildcard(s)) {
+ if (s.isEmpty()) {
+ matchPushSpec = true;
wildcard = true;
- if (mode == WildcardMode.REQUIRE_MATCH) {
- throw new IllegalArgumentException(MessageFormat
- .format(JGitText.get().invalidWildcards, spec));
+ srcName = Constants.R_HEADS + '*';
+ dstName = srcName;
+ } else {
+ if (isWildcard(s)) {
+ wildcard = true;
+ if (mode == WildcardMode.REQUIRE_MATCH) {
+ throw new IllegalArgumentException(MessageFormat
+ .format(JGitText.get().invalidWildcards, spec));
+ }
}
+ dstName = checkValid(s);
}
- dstName = checkValid(s);
} else if (c > 0) {
String src = s.substring(0, c);
String dst = s.substring(c + 1);
@@ -168,6 +181,7 @@ public class RefSpec implements Serializable {
}
srcName = checkValid(s);
}
+ matching = matchPushSpec;
}
/**
@@ -195,6 +209,7 @@ public class RefSpec implements Serializable {
}
private RefSpec(RefSpec p) {
+ matching = false;
force = p.isForceUpdate();
wildcard = p.isWildcard();
srcName = p.getSource();
@@ -203,6 +218,17 @@ public class RefSpec implements Serializable {
}
/**
+ * Tells whether this {@link RefSpec} is the special "matching" RefSpec ":"
+ * for pushing.
+ *
+ * @return whether this is a "matching" RefSpec
+ * @since 6.1
+ */
+ public boolean isMatching() {
+ return matching;
+ }
+
+ /**
* Check if this specification wants to forcefully update the destination.
*
* @return true if this specification asks for updates without merge tests.
@@ -220,6 +246,7 @@ public class RefSpec implements Serializable {
*/
public RefSpec setForceUpdate(boolean forceUpdate) {
final RefSpec r = new RefSpec(this);
+ r.matching = matching;
r.force = forceUpdate;
return r;
}
@@ -322,8 +349,7 @@ public class RefSpec implements Serializable {
* The wildcard status of the new source disagrees with the
* wildcard status of the new destination.
*/
- public RefSpec setSourceDestination(final String source,
- final String destination) {
+ public RefSpec setSourceDestination(String source, String destination) {
if (isWildcard(source) != isWildcard(destination))
throw new IllegalStateException(JGitText.get().sourceDestinationMustMatch);
final RefSpec r = new RefSpec(this);
@@ -541,37 +567,36 @@ public class RefSpec implements Serializable {
if (!(obj instanceof RefSpec))
return false;
final RefSpec b = (RefSpec) obj;
- if (isForceUpdate() != b.isForceUpdate())
- return false;
- if (isWildcard() != b.isWildcard())
+ if (isForceUpdate() != b.isForceUpdate()) {
return false;
- if (!eq(getSource(), b.getSource()))
- return false;
- if (!eq(getDestination(), b.getDestination()))
- return false;
- return true;
- }
-
- private static boolean eq(String a, String b) {
- if (References.isSameObject(a, b)) {
- return true;
}
- if (a == null || b == null)
+ if (isMatching()) {
+ return b.isMatching();
+ } else if (b.isMatching()) {
return false;
- return a.equals(b);
+ }
+ return isWildcard() == b.isWildcard()
+ && Objects.equals(getSource(), b.getSource())
+ && Objects.equals(getDestination(), b.getDestination());
}
/** {@inheritDoc} */
@Override
public String toString() {
final StringBuilder r = new StringBuilder();
- if (isForceUpdate())
+ if (isForceUpdate()) {
r.append('+');
- if (getSource() != null)
- r.append(getSource());
- if (getDestination() != null) {
+ }
+ if (isMatching()) {
r.append(':');
- r.append(getDestination());
+ } else {
+ if (getSource() != null) {
+ r.append(getSource());
+ }
+ if (getDestination() != null) {
+ r.append(':');
+ r.append(getDestination());
+ }
}
return r.toString();
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RemoteRefUpdate.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RemoteRefUpdate.java
index 43eaac7927..218e62c10a 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/RemoteRefUpdate.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/RemoteRefUpdate.java
@@ -12,7 +12,9 @@ package org.eclipse.jgit.transport;
import java.io.IOException;
import java.text.MessageFormat;
+import java.util.Collection;
+import org.eclipse.jgit.annotations.NonNull;
import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
@@ -116,6 +118,12 @@ public class RemoteRefUpdate {
private RefUpdate localUpdate;
/**
+ * If set, the RemoteRefUpdate is a placeholder for the "matching" RefSpec
+ * to be expanded after the advertisements have been received in a push.
+ */
+ private Collection<RefSpec> fetchSpecs;
+
+ /**
* Construct remote ref update request by providing an update specification.
* Object is created with default
* {@link org.eclipse.jgit.transport.RemoteRefUpdate.Status#NOT_ATTEMPTED}
@@ -157,9 +165,8 @@ public class RemoteRefUpdate {
* @throws java.lang.IllegalArgumentException
* if some required parameter was null
*/
- public RemoteRefUpdate(final Repository localDb, final String srcRef,
- final String remoteName, final boolean forceUpdate,
- final String localName, final ObjectId expectedOldObjectId)
+ public RemoteRefUpdate(Repository localDb, String srcRef, String remoteName,
+ boolean forceUpdate, String localName, ObjectId expectedOldObjectId)
throws IOException {
this(localDb, srcRef, srcRef != null ? localDb.resolve(srcRef)
: ObjectId.zeroId(), remoteName, forceUpdate, localName,
@@ -203,9 +210,8 @@ public class RemoteRefUpdate {
* @throws java.lang.IllegalArgumentException
* if some required parameter was null
*/
- public RemoteRefUpdate(final Repository localDb, final Ref srcRef,
- final String remoteName, final boolean forceUpdate,
- final String localName, final ObjectId expectedOldObjectId)
+ public RemoteRefUpdate(Repository localDb, Ref srcRef, String remoteName,
+ boolean forceUpdate, String localName, ObjectId expectedOldObjectId)
throws IOException {
this(localDb, srcRef != null ? srcRef.getName() : null,
srcRef != null ? srcRef.getObjectId() : null, remoteName,
@@ -255,28 +261,41 @@ public class RemoteRefUpdate {
* @throws java.lang.IllegalArgumentException
* if some required parameter was null
*/
- public RemoteRefUpdate(final Repository localDb, final String srcRef,
- final ObjectId srcId, final String remoteName,
- final boolean forceUpdate, final String localName,
- final ObjectId expectedOldObjectId) throws IOException {
- if (remoteName == null)
- throw new IllegalArgumentException(JGitText.get().remoteNameCannotBeNull);
- if (srcId == null && srcRef != null)
- throw new IOException(MessageFormat.format(
- JGitText.get().sourceRefDoesntResolveToAnyObject, srcRef));
-
- if (srcRef != null)
+ public RemoteRefUpdate(Repository localDb, String srcRef, ObjectId srcId,
+ String remoteName, boolean forceUpdate, String localName,
+ ObjectId expectedOldObjectId) throws IOException {
+ this(localDb, srcRef, srcId, remoteName, forceUpdate, localName, null,
+ expectedOldObjectId);
+ }
+
+ private RemoteRefUpdate(Repository localDb, String srcRef, ObjectId srcId,
+ String remoteName, boolean forceUpdate, String localName,
+ Collection<RefSpec> fetchSpecs, ObjectId expectedOldObjectId)
+ throws IOException {
+ if (fetchSpecs == null) {
+ if (remoteName == null) {
+ throw new IllegalArgumentException(
+ JGitText.get().remoteNameCannotBeNull);
+ }
+ if (srcId == null && srcRef != null) {
+ throw new IOException(MessageFormat.format(
+ JGitText.get().sourceRefDoesntResolveToAnyObject,
+ srcRef));
+ }
+ }
+ if (srcRef != null) {
this.srcRef = srcRef;
- else if (srcId != null && !srcId.equals(ObjectId.zeroId()))
+ } else if (srcId != null && !srcId.equals(ObjectId.zeroId())) {
this.srcRef = srcId.name();
- else
+ } else {
this.srcRef = null;
-
- if (srcId != null)
+ }
+ if (srcId != null) {
this.newObjectId = srcId;
- else
+ } else {
this.newObjectId = ObjectId.zeroId();
-
+ }
+ this.fetchSpecs = fetchSpecs;
this.remoteName = remoteName;
this.forceUpdate = forceUpdate;
if (localName != null && localDb != null) {
@@ -292,8 +311,9 @@ public class RemoteRefUpdate {
? localUpdate.getOldObjectId()
: ObjectId.zeroId(),
newObjectId);
- } else
+ } else {
trackingRefUpdate = null;
+ }
this.localDb = localDb;
this.expectedOldObjectId = expectedOldObjectId;
this.status = Status.NOT_ATTEMPTED;
@@ -316,11 +336,57 @@ public class RemoteRefUpdate {
* local tracking branch or srcRef of base object no longer can
* be resolved to any object.
*/
- public RemoteRefUpdate(final RemoteRefUpdate base,
- final ObjectId newExpectedOldObjectId) throws IOException {
- this(base.localDb, base.srcRef, base.remoteName, base.forceUpdate,
+ public RemoteRefUpdate(RemoteRefUpdate base,
+ ObjectId newExpectedOldObjectId) throws IOException {
+ this(base.localDb, base.srcRef, base.newObjectId, base.remoteName,
+ base.forceUpdate,
(base.trackingRefUpdate == null ? null : base.trackingRefUpdate
- .getLocalName()), newExpectedOldObjectId);
+ .getLocalName()),
+ base.fetchSpecs, newExpectedOldObjectId);
+ }
+
+ /**
+ * Creates a "placeholder" update for the "matching" RefSpec ":".
+ *
+ * @param localDb
+ * local repository to push from
+ * @param forceUpdate
+ * whether non-fast-forward updates shall be allowed
+ * @param fetchSpecs
+ * The fetch {@link RefSpec}s to use when this placeholder is
+ * expanded to determine remote tracking branch updates
+ */
+ RemoteRefUpdate(Repository localDb, boolean forceUpdate,
+ @NonNull Collection<RefSpec> fetchSpecs) {
+ this.localDb = localDb;
+ this.forceUpdate = forceUpdate;
+ this.fetchSpecs = fetchSpecs;
+ this.trackingRefUpdate = null;
+ this.srcRef = null;
+ this.remoteName = null;
+ this.newObjectId = null;
+ this.status = Status.NOT_ATTEMPTED;
+ }
+
+ /**
+ * Tells whether this {@link RemoteRefUpdate} is a placeholder for a
+ * "matching" {@link RefSpec}.
+ *
+ * @return {@code true} if this is a placeholder, {@code false} otherwise
+ * @since 6.1
+ */
+ public boolean isMatching() {
+ return fetchSpecs != null;
+ }
+
+ /**
+ * Retrieves the fetch {@link RefSpec}s of this {@link RemoteRefUpdate}.
+ *
+ * @return the fetch {@link RefSpec}s, or {@code null} if
+ * {@code this.}{@link #isMatching()} {@code == false}
+ */
+ Collection<RefSpec> getFetchSpecs() {
+ return fetchSpecs;
}
/**
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java
index bfe26d9808..0eab4434ed 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/Transport.java
@@ -40,7 +40,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
import org.eclipse.jgit.annotations.NonNull;
import org.eclipse.jgit.annotations.Nullable;
-import org.eclipse.jgit.api.errors.AbortedByHookException;
import org.eclipse.jgit.errors.NotSupportedException;
import org.eclipse.jgit.errors.TransportException;
import org.eclipse.jgit.hooks.Hooks;
@@ -590,6 +589,11 @@ public abstract class Transport implements AutoCloseable {
final Collection<RefSpec> procRefs = expandPushWildcardsFor(db, specs);
for (RefSpec spec : procRefs) {
+ if (spec.isMatching()) {
+ result.add(new RemoteRefUpdate(db, spec.isForceUpdate(),
+ fetchSpecs));
+ continue;
+ }
String srcSpec = spec.getSource();
final Ref srcRef = db.findRef(srcSpec);
if (srcRef != null)
@@ -660,7 +664,7 @@ public abstract class Transport implements AutoCloseable {
List<Ref> localRefs = null;
for (RefSpec spec : specs) {
- if (spec.isWildcard()) {
+ if (!spec.isMatching() && spec.isWildcard()) {
if (localRefs == null) {
localRefs = db.getRefDatabase().getRefs();
}
@@ -676,7 +680,7 @@ public abstract class Transport implements AutoCloseable {
return procRefs;
}
- private static String findTrackingRefName(final String remoteName,
+ static String findTrackingRefName(final String remoteName,
final Collection<RefSpec> fetchSpecs) {
// try to find matching tracking refs
for (RefSpec fetchSpec : fetchSpecs) {
@@ -1375,16 +1379,9 @@ public abstract class Transport implements AutoCloseable {
if (toPush.isEmpty())
throw new TransportException(JGitText.get().nothingToPush);
}
- if (prePush != null) {
- try {
- prePush.setRefs(toPush);
- prePush.call();
- } catch (AbortedByHookException | IOException e) {
- throw new TransportException(e.getMessage(), e);
- }
- }
- final PushProcess pushProcess = new PushProcess(this, toPush, out);
+ final PushProcess pushProcess = new PushProcess(this, toPush, prePush,
+ out);
return pushProcess.execute(monitor);
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java
index 1f614e31f6..8269666d26 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/TreeWalk.java
@@ -1,6 +1,6 @@
/*
- * Copyright (C) 2008-2009, Google Inc.
- * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> and others
+ * Copyright (C) 2008, 2009 Google Inc.
+ * Copyright (C) 2008, 2022 Shawn O. Pearce <spearce@spearce.org> and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
@@ -14,6 +14,7 @@ package org.eclipse.jgit.treewalk;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.IOException;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@@ -73,6 +74,7 @@ import org.eclipse.jgit.util.io.EolStreamTypeUtil;
* threads.
*/
public class TreeWalk implements AutoCloseable, AttributesProvider {
+
private static final AbstractTreeIterator[] NO_TREES = {};
/**
@@ -92,7 +94,7 @@ public class TreeWalk implements AutoCloseable, AttributesProvider {
}
/**
- * Type of operation you want to retrieve the git attributes for.
+ * Type of operation you want to retrieve the git attributes for.
*/
private OperationType operationType = OperationType.CHECKOUT_OP;
@@ -284,11 +286,20 @@ public class TreeWalk implements AutoCloseable, AttributesProvider {
AbstractTreeIterator currentHead;
- /** Cached attribute for the current entry */
- private Attributes attrs = null;
+ /**
+ * Cached attributes for the current entry; per tree. Index i+1 is for tree
+ * i; index 0 is for the deprecated legacy behavior.
+ */
+ private Attributes[] attrs;
+
+ /**
+ * Cached attributes handler; per tree. Index i+1 is for tree i; index 0 is
+ * for the deprecated legacy behavior.
+ */
+ private AttributesHandler[] attributesHandlers;
- /** Cached attributes handler */
- private AttributesHandler attributesHandler;
+ /** Can be set to identify the tree to use for {@link #getAttributes()}. */
+ private int headIndex = -1;
private Config config;
@@ -515,6 +526,24 @@ public class TreeWalk implements AutoCloseable, AttributesProvider {
}
/**
+ * Identifies the tree at the given index as the head tree. This is the tree
+ * use by default to determine attributes and EOL modes.
+ *
+ * @param index
+ * of the tree to use as head
+ * @throws IllegalArgumentException
+ * if the index is out of range
+ * @since 6.1
+ */
+ public void setHead(int index) {
+ if (index < 0 || index >= trees.length) {
+ throw new IllegalArgumentException("Head index " + index //$NON-NLS-1$
+ + " out of range [0," + trees.length + ')'); //$NON-NLS-1$
+ }
+ headIndex = index;
+ }
+
+ /**
* {@inheritDoc}
* <p>
* Retrieve the git attributes for the current entry.
@@ -556,25 +585,51 @@ public class TreeWalk implements AutoCloseable, AttributesProvider {
*/
@Override
public Attributes getAttributes() {
- if (attrs != null)
- return attrs;
+ return getAttributes(headIndex);
+ }
+ /**
+ * Retrieves the git attributes based on the given tree.
+ *
+ * @param index
+ * of the tree to use as base for the attributes
+ * @return the attributes
+ * @since 6.1
+ */
+ public Attributes getAttributes(int index) {
+ int attrIndex = index + 1;
+ Attributes result = attrs[attrIndex];
+ if (result != null) {
+ return result;
+ }
if (attributesNodeProvider == null) {
- // The work tree should have a AttributesNodeProvider to be able to
- // retrieve the info and global attributes node
throw new IllegalStateException(
"The tree walk should have one AttributesNodeProvider set in order to compute the git attributes."); //$NON-NLS-1$
}
try {
- // Lazy create the attributesHandler on the first access of
- // attributes. This requires the info, global and root
- // attributes nodes
- if (attributesHandler == null) {
- attributesHandler = new AttributesHandler(this);
+ AttributesHandler handler = attributesHandlers[attrIndex];
+ if (handler == null) {
+ if (index < 0) {
+ // Legacy behavior (headIndex not set, getAttributes() above
+ // called)
+ handler = new AttributesHandler(this, () -> {
+ return getTree(CanonicalTreeParser.class);
+ });
+ } else {
+ handler = new AttributesHandler(this, () -> {
+ AbstractTreeIterator tree = trees[index];
+ if (tree instanceof CanonicalTreeParser) {
+ return (CanonicalTreeParser) tree;
+ }
+ return null;
+ });
+ }
+ attributesHandlers[attrIndex] = handler;
}
- attrs = attributesHandler.getAttributes();
- return attrs;
+ result = handler.getAttributes();
+ attrs[attrIndex] = result;
+ return result;
} catch (IOException e) {
throw new JGitInternalException("Error while parsing attributes", //$NON-NLS-1$
e);
@@ -595,11 +650,34 @@ public class TreeWalk implements AutoCloseable, AttributesProvider {
*/
@Nullable
public EolStreamType getEolStreamType(OperationType opType) {
- if (attributesNodeProvider == null || config == null)
+ if (attributesNodeProvider == null || config == null) {
return null;
- return EolStreamTypeUtil.detectStreamType(
- opType != null ? opType : operationType,
- config.get(WorkingTreeOptions.KEY), getAttributes());
+ }
+ OperationType op = opType != null ? opType : operationType;
+ return EolStreamTypeUtil.detectStreamType(op,
+ config.get(WorkingTreeOptions.KEY), getAttributes());
+ }
+
+ /**
+ * Get the EOL stream type of the current entry for checking out using the
+ * config and {@link #getAttributes()}.
+ *
+ * @param tree
+ * index of the tree the check-out is to be from
+ * @return the EOL stream type of the current entry using the config and
+ * {@link #getAttributes()}. Note that this method may return null
+ * if the {@link org.eclipse.jgit.treewalk.TreeWalk} is not based on
+ * a working tree
+ * @since 6.1
+ */
+ @Nullable
+ public EolStreamType getCheckoutEolStreamType(int tree) {
+ if (attributesNodeProvider == null || config == null) {
+ return null;
+ }
+ Attributes attr = getAttributes(tree);
+ return EolStreamTypeUtil.detectStreamType(OperationType.CHECKOUT_OP,
+ config.get(WorkingTreeOptions.KEY), attr);
}
/**
@@ -607,7 +685,8 @@ public class TreeWalk implements AutoCloseable, AttributesProvider {
*/
public void reset() {
attrs = null;
- attributesHandler = null;
+ attributesHandlers = null;
+ headIndex = -1;
trees = NO_TREES;
advance = false;
depth = 0;
@@ -651,7 +730,9 @@ public class TreeWalk implements AutoCloseable, AttributesProvider {
advance = false;
depth = 0;
- attrs = null;
+ attrs = new Attributes[2];
+ attributesHandlers = new AttributesHandler[2];
+ headIndex = -1;
}
/**
@@ -701,7 +782,14 @@ public class TreeWalk implements AutoCloseable, AttributesProvider {
trees = r;
advance = false;
depth = 0;
- attrs = null;
+ if (oldLen == newLen) {
+ Arrays.fill(attrs, null);
+ Arrays.fill(attributesHandlers, null);
+ } else {
+ attrs = new Attributes[newLen + 1];
+ attributesHandlers = new AttributesHandler[newLen + 1];
+ }
+ headIndex = -1;
}
/**
@@ -758,6 +846,16 @@ public class TreeWalk implements AutoCloseable, AttributesProvider {
p.matchShift = 0;
trees = newTrees;
+ if (attrs == null) {
+ attrs = new Attributes[n + 2];
+ } else {
+ attrs = Arrays.copyOf(attrs, n + 2);
+ }
+ if (attributesHandlers == null) {
+ attributesHandlers = new AttributesHandler[n + 2];
+ } else {
+ attributesHandlers = Arrays.copyOf(attributesHandlers, n + 2);
+ }
return n;
}
@@ -800,7 +898,7 @@ public class TreeWalk implements AutoCloseable, AttributesProvider {
}
for (;;) {
- attrs = null;
+ Arrays.fill(attrs, null);
final AbstractTreeIterator t = min();
if (t.eof()) {
if (depth > 0) {
@@ -1255,7 +1353,7 @@ public class TreeWalk implements AutoCloseable, AttributesProvider {
*/
public void enterSubtree() throws MissingObjectException,
IncorrectObjectTypeException, CorruptObjectException, IOException {
- attrs = null;
+ Arrays.fill(attrs, null);
final AbstractTreeIterator ch = currentHead;
final AbstractTreeIterator[] tmp = new AbstractTreeIterator[trees.length];
for (int i = 0; i < trees.length; i++) {
@@ -1374,11 +1472,12 @@ public class TreeWalk implements AutoCloseable, AttributesProvider {
/**
* Inspect config and attributes to return a filtercommand applicable for
- * the current path, but without expanding %f occurences
+ * the current path.
*
* @param filterCommandType
* which type of filterCommand should be executed. E.g. "clean",
- * "smudge"
+ * "smudge". For "smudge" consider using
+ * {{@link #getSmudgeCommand(int)} instead.
* @return a filter command
* @throws java.io.IOException
* @since 4.2
@@ -1407,6 +1506,54 @@ public class TreeWalk implements AutoCloseable, AttributesProvider {
}
/**
+ * Inspect config and attributes to return a filtercommand applicable for
+ * the current path.
+ *
+ * @param index
+ * of the tree the item to be smudged is in
+ * @return a filter command
+ * @throws java.io.IOException
+ * @since 6.1
+ */
+ public String getSmudgeCommand(int index)
+ throws IOException {
+ return getSmudgeCommand(getAttributes(index));
+ }
+
+ /**
+ * Inspect config and attributes to return a filtercommand applicable for
+ * the current path.
+ *
+ * @param attributes
+ * to use
+ * @return a filter command
+ * @throws java.io.IOException
+ * @since 6.1
+ */
+ public String getSmudgeCommand(Attributes attributes) throws IOException {
+ if (attributes == null) {
+ return null;
+ }
+ Attribute f = attributes.get(Constants.ATTR_FILTER);
+ if (f == null) {
+ return null;
+ }
+ String filterValue = f.getValue();
+ if (filterValue == null) {
+ return null;
+ }
+
+ String filterCommand = getFilterCommandDefinition(filterValue,
+ Constants.ATTR_FILTER_TYPE_SMUDGE);
+ if (filterCommand == null) {
+ return null;
+ }
+ return filterCommand.replaceAll("%f", //$NON-NLS-1$
+ Matcher.quoteReplacement(
+ QuotedString.BOURNE.quote((getPathString()))));
+ }
+
+ /**
* Get the filter command how it is defined in gitconfig. The returned
* string may contain "%f" which needs to be replaced by the current path
* before executing the filter command. These filter definitions are cached