理解使用git diff -w创建Patch的原因 - 不适用

时间:2018-01-01 08:16:32

标签: git diff patch

我正在尝试清理我在管理的项目中收到的拉取请求。

贡献者添加了许多不必要的空白变化以及功能贡献。他重新缩进了大部分文件。它需要完成,但它应该是一个单独的提交。我不接受更改,这些更改几乎完全重写了大约80行添加功能的文件。

我通过将git diff -w --patience重定向到文件来生成补丁,这似乎是我想要的:添加或删除相对较少的特定行,并且在阅读上下文时,更改是有意义的。我很好,暂时从文件的其余部分缩小了一些更改的行。

git apply声称该补丁不适用。 patch -p1 -v基本上列出了所有的帅哥,并指出每个帅哥都不适用。它创建一个.rej文件,它只是补丁的重述。 patch -p1 --merge设法获取第一个大块的 part ,并使文件中包含奇怪的合并标记。

对我来说真正令人沮丧的部分是我试图应用修补程序的修订与我用来生成差异的完全相同的父版本!

补丁:(抱歉,很久)

diff --git a/ArtOfIllusion/src/artofillusion/ScrollViewTool.java b/ArtOfIllusion/src/artofillusion/ScrollViewTool.java
index e0f9af35..91fcb863 100644
--- a/ArtOfIllusion/src/artofillusion/ScrollViewTool.java
+++ b/ArtOfIllusion/src/artofillusion/ScrollViewTool.java
@@ -20,15 +20,17 @@ import java.awt.*;
 import java.awt.event.*;
 import javax.swing.Timer;

+/** ScrollViewTool is a tool to handle mouse scroll wheel events in scene and object views. 
+    It moves the viewpoint in view z-directi and/or in some cases changes view orientation. */
+
 public class ScrollViewTool
 {
     private EditingWindow window;
-   private MouseScrolledEvent event;
     private ViewerCanvas view;
     private Camera camera;
     private double distToPlane;
     private double scrollRadius, scrollBlend, scrollBlendX, scrollBlendY; // for graphics
-   private int navigationMode;
+    private int navigationMode, scrollSteps;
     private Rectangle bounds;
     private Point mousePoint;
     private CoordinateSystem startCoords;
@@ -42,7 +44,9 @@ public class ScrollViewTool

     protected void mouseScrolled(MouseScrolledEvent e, ViewerCanvas v)
     {
-       event = e;
+       scrollSteps = v.scrollBuffer;
+        v.scrollBuffer = 0;
+        v.mouseMoving = false;
         view = v;
         view.scrolling = true;
         distToPlane = view.getDistToPlane();
@@ -50,13 +54,13 @@ public class ScrollViewTool
         bounds = view.getBounds();
         camera = view.getCamera();
         boundCamera = view.getBoundCamera();
-       if (boundCamera != null)
-           startCoords = boundCamera.getCoords().duplicate();
+        if (!scrollTimer.isRunning())
+            startCoords = camera.getCameraCoordinates().duplicate();

         // Make sure that the rotation Center is on Camera Z-axis.
         // After a SceneCamera is read from a file, that may not be the case.
-       // A SceneCamera should have a 'distToPlane' that should be saved with the camera.
-       // Makin it saveable will cause version incompatibility.
+        // Any bound should have a 'distToPlane' that should be saved with the object.
+
         CoordinateSystem coords = camera.getCameraCoordinates();
         view.setRotationCenter(coords.getOrigin().plus(coords.getZDirection().times(view.getDistToPlane())));

@@ -77,15 +81,9 @@ public class ScrollViewTool
                 break;
         }

-       if (boundCamera != null && window != null) // wonder why the window is here...
-       {
-           boundCamera.setCoords(camera.getCameraCoordinates().duplicate());
-           ((SceneCamera)boundCamera.getObject()).setDistToPlane(distToPlane);
-           moveCameraChildren(boundCamera, boundCamera.getCoords().fromLocal().times(startCoords.toLocal()));
-
-       }
         setAuxGraphs(view);
         repaintAllViews(view);
+       //view.repaint
         view.viewChanged(false);
     }

@@ -100,7 +98,7 @@ public class ScrollViewTool
         {
             CoordinateSystem coords = camera.getCameraCoordinates();
             double oldDist = distToPlane;
-           //double newDist = oldDist*Math.pow(1.0/1.01, amount); // This woud reverse the action
+            //double newDist = oldDist*Math.pow(1.0/1.01, amount); // This would reverse the action
             double newDist = oldDist*Math.pow(1.01, amount);
             Vec3 oldPos = new Vec3(coords.getOrigin());
             Vec3 newPos = view.getRotationCenter().plus(coords.getZDirection().times(-newDist));
@@ -224,8 +222,17 @@ public class ScrollViewTool

     public void mouseStoppedScrolling()
     {
-       // This should set an undorecord if a camera moved
+       if (window != null && boundCamera != null)
+        {
+            boundCamera.getCoords().copyCoords(camera.getCameraCoordinates());
+            if (boundCamera.getObject() instanceof SceneCamera) ((SceneCamera)boundCamera.getObject()).setDistToPlane(distToPlane);
+
+            UndoRecord undo = new UndoRecord(window, false, UndoRecord.COPY_COORDS, new Object [] {boundCamera.getCoords(), startCoords});
+            moveCameraChildren(boundCamera, boundCamera.getCoords().fromLocal().times(startCoords.toLocal()), undo);
+            window.setUndoRecord(undo);
+        }
         wipeAuxGraphs();
+        window.updateImage();
     }

     private Timer scrollTimer = new Timer(500, new ActionListener() 
@@ -250,15 +257,16 @@ public class ScrollViewTool

     /** 
         This is called recursively to move any children of a bound camera. 
-       This does not set an undo record.
     */
-   private void moveCameraChildren(ObjectInfo parent, Mat4 transform)
+    private void moveCameraChildren(ObjectInfo parent, Mat4 transform, UndoRecord undo)
     {    
         for (int i = 0; i < parent.getChildren().length; i++)
         {
             CoordinateSystem coords = parent.getChildren()[i].getCoords();
+            CoordinateSystem previousCoords = coords.duplicate();
             coords.transformCoordinates(transform);
-           moveCameraChildren(parent.getChildren()[i], transform);
+            undo.addCommand(UndoRecord.COPY_COORDS, new Object [] {coords, previousCoords});
+            moveCameraChildren(parent.getChildren()[i], transform, undo);
         }  
     }

@@ -273,7 +281,6 @@ public class ScrollViewTool

     private void setAuxGraphs(ViewerCanvas view)
     {
-
         if (window != null)
             for (ViewerCanvas v : window.getAllViews())
                 if (v != view)
@@ -287,7 +294,8 @@ public class ScrollViewTool
                v.auxGraphs.wipe();
     }       

-   /** Maybe some day? */
     public void drawOverlay()
-   {}
+    {
+        // This could draw a "ghost" of the bound camera and it's children during scroll
+    }
 }

我已将此补丁截断到某个程度:我已删除第二个文件的差异,该文件正确应用。

我正在尝试应用修补程序on github - permalink

的文件

The (messy) commit that I started from注意:此PR中还有其他提交。现在,我正在尝试使用第一个。请注意,它的直接父级与我上面链接的版本相同。

任何关于为什么这个补丁如此不满或如何解决它的想法,将不胜感激。

1 个答案:

答案 0 :(得分:0)

当@torek向我推动时,补丁并不像我预期的那样:

-w的{​​{1}}和-b选项生成的上下文行与父文件不匹配,相反,所涉及的空格与“杂乱”提交相匹配。 git diffgit apply都不喜欢这个。

当他们从补丁中查看预期的上下文时,他们认为上下文不匹配,因此无法应用补丁。 Varous'忽略空格',&amp; tc。选项似乎不会影响这一点。

解决方法:

摆脱背景线。使用patch(U表示统一差异格式,0表示上下文行数)生成补丁,只留下行号和替换行数据。因为这是一个干净的补丁(应用于作为原始提交的父级的修订版),行号是git diff -w -U0唯一需要的东西。注意:patch由于某种原因仍然不喜欢这些补丁,但git apply似乎认为它们只是 mahvelous

如果您尝试:

这仅适用于您要应用的文件是等效于用作diff基础的行的行。实际上,如果你在一个干净的基础patch之上有一系列凌乱的提交{1, 2, 3},你需要:

  • 0开始创建一个新分支。
  • 针对0
  • 生成针对1的修补程序
  • 0
  • 的形式将修补程序应用于新分支
  • 针对新的,干净的提交1a
  • 生成2的补丁
  • &amp; tc,根据需要