]> source.dussan.org Git - jgit.git/commitdiff
ResolveMerger: Allow setting the TreeWalk AttributesNodeProvider 78/1203278/4
authorNasser Grainawi <quic_nasserg@quicinc.com>
Tue, 29 Oct 2024 23:22:15 +0000 (17:22 -0600)
committerMatthias Sohn <matthias.sohn@sap.com>
Mon, 4 Nov 2024 23:16:39 +0000 (00:16 +0100)
When a merger is created without a Repository, no
AttributesNodeProvider is created in the TreeWalk. Since mergers are
often created with a custom ObjectInserter and no repo, they skip any
lookups of attributes from any of the gitattributes files (within a
tree, in the repo info/ dir, or user/global). Since there are
potentially merge-affecting attributes in those files, callers might
want to use both a custom ObjectInserter and an AttributesNodeProvider.

Change-Id: I7997309003bbb598e1002261b3be7f2cc52066c8

org.eclipse.jgit/.settings/.api_filters
org.eclipse.jgit/src/org/eclipse/jgit/merge/ResolveMerger.java

index 28b20ab01f5051a51c4db9c94c9c1e979c9513c1..2c22f0231c419efdeb8c7d9185cfd3fc7b7d9747 100644 (file)
             </message_arguments>
         </filter>
     </resource>
+    <resource path="src/org/eclipse/jgit/merge/ResolveMerger.java" type="org.eclipse.jgit.merge.ResolveMerger">
+        <filter id="336658481">
+            <message_arguments>
+                <message_argument value="org.eclipse.jgit.merge.ResolveMerger"/>
+                <message_argument value="attributesNodeProvider"/>
+            </message_arguments>
+        </filter>
+        <filter id="1142947843">
+            <message_arguments>
+                <message_argument value="6.10.1"/>
+                <message_argument value="attributesNodeProvider"/>
+            </message_arguments>
+        </filter>
+        <filter id="1142947843">
+            <message_arguments>
+                <message_argument value="6.10.1"/>
+                <message_argument value="setAttributesNodeProvider(AttributesNodeProvider)"/>
+            </message_arguments>
+        </filter>
+    </resource>
 </component>
index 85b85cf855cbaebed1cb08bc123e712447978cb9..a6a287bcf47953af6eecd3261b492d41cc21df01 100644 (file)
@@ -41,6 +41,7 @@ import org.eclipse.jgit.annotations.NonNull;
 import org.eclipse.jgit.annotations.Nullable;
 import org.eclipse.jgit.attributes.Attribute;
 import org.eclipse.jgit.attributes.Attributes;
+import org.eclipse.jgit.attributes.AttributesNodeProvider;
 import org.eclipse.jgit.diff.DiffAlgorithm;
 import org.eclipse.jgit.diff.DiffAlgorithm.SupportedAlgorithm;
 import org.eclipse.jgit.diff.RawText;
@@ -837,6 +838,13 @@ public class ResolveMerger extends ThreeWayMerger {
        @NonNull
        private ContentMergeStrategy contentStrategy = ContentMergeStrategy.CONFLICT;
 
+       /**
+        * The {@link AttributesNodeProvider} to use while merging trees.
+        *
+        * @since 6.10.1
+        */
+       protected AttributesNodeProvider attributesNodeProvider;
+
        private static MergeAlgorithm getMergeAlgorithm(Config config) {
                SupportedAlgorithm diffAlg = config.getEnum(
                                CONFIG_DIFF_SECTION, null, CONFIG_KEY_ALGORITHM,
@@ -1836,6 +1844,18 @@ public class ResolveMerger extends ThreeWayMerger {
                this.workingTreeIterator = workingTreeIterator;
        }
 
+       /**
+        * Sets the {@link AttributesNodeProvider} to be used by this merger.
+        *
+        * @param attributesNodeProvider
+        *            the attributeNodeProvider to set
+        * @since 6.10.1
+        */
+       public void setAttributesNodeProvider(
+                       AttributesNodeProvider attributesNodeProvider) {
+               this.attributesNodeProvider = attributesNodeProvider;
+       }
+
 
        /**
         * The resolve conflict way of three way merging
@@ -1880,6 +1900,9 @@ public class ResolveMerger extends ThreeWayMerger {
                                        WorkTreeUpdater.createWorkTreeUpdater(db, dircache);
                        dircache = workTreeUpdater.getLockedDirCache();
                        tw = new NameConflictTreeWalk(db, reader);
+                       if (attributesNodeProvider != null) {
+                               tw.setAttributesNodeProvider(attributesNodeProvider);
+                       }
 
                        tw.addTree(baseTree);
                        tw.setHead(tw.addTree(headTree));