简体   繁体   English

了解为什么使用git diff -w --patience创建的补丁不适用

[英]Understanding why Patch created with git diff -w --patience does not apply

I'm trying to clean up a pull request that we received at a project that I admin for. 我正在尝试清理在我管理的项目中收到的请求请求。

The contributor added a lot of unnecessary white-space changes in along with the functional contribution. 贡献者在功能贡献中添加了许多不必要的空白更改。 He re-indented most of several files. 他重新缩进了几个文件中的大多数文件。 It needs to be done, but it should be a separate commit. 它需要完成,但是应该是单独的提交。 I'm not accepting changes that read as an almost total re-write of a file for ~80 lines of added feature. 我不接受将大约80行附加功能读为几乎完全重写文件的更改。

I've generated a patch by redirecting git diff -w --patience to a file, and it seems to be what I want: A relatively few specific lines added or deleted, and when reading the context, the changes make sense. 我通过将git diff -w --patience重定向到文件生成了一个补丁,这似乎是我想要的:添加或删除了相对较少的几行,并且在读取上下文时,这些更改才有意义。 I'm okay with the few changed lines being indented inconsistently from the rest of the file for the time being. 我可以暂时将少数更改的行与文件的其余部分不一致地缩进。

git apply claims that the patch does not apply. git apply声称该补丁不适用。 patch -p1 -v basically lists all of the hunks, and states that each one does not apply. patch -p1 -v基本上列出了所有的块,并指出每个块都不适用。 It creates a .rej file that is simply a restatement of the patch. 它会创建一个.rej文件,该文件只是补丁的重述。 patch -p1 --merge manages to get part of the first hunk, and leaves the file filled with merge markers that are... odd. patch -p1 --merge设法获得第一个块的一部分 ,并使文件充满了...奇怪的合并标记。

The really frustrating part for me is that the revision that I am trying to apply the patch too is the exact same parent that I used to generate the diff! 对我来说,真的令人沮丧的是,我想应用补丁的版本是我用来生成DIFF完全相同的父!

Patch: (Sorry, its long) 补丁:(对不起,很长)

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
+    }
 }

I have truncated this patch to an extent: I've removed a diff for a second file, which is applying correctly. 我已将该补丁截断到一定程度:我已经删除了第二个文件的差异,该差异正确应用。

The file to which I'm trying to apply the patch on github - permalink 我想在github上应用补丁的文件-permalink

The (messy) commit that I started from Note: there are other commits in this PR. 我从开始的(混乱)提交注意:此PR中还有其他提交。 Right now, I'm trying to work with the first one. 现在,我正在尝试使用第一个。 Note that its direct parent is the same revision that I linked above. 请注意,它的直接父级是我上面链接的相同修订版。

Any Ideas on why this patch is being so grouchy, or how to troubleshoot it, would be appreciated. 关于此修补程序为何如此烦躁或如何对其进行故障排除的任何构想,将不胜感激。

As @torek nudged me towards, the patch is not quite what I had expected: 正如@torek向我推动的那样,该补丁与我所期望的不完全相同:

The context lines generated by -w and -b options for git diff do not match the parent file, instead, the whitespace involved matches the 'messy' commit. git diff-w-b选项生成的上下文行与父文件不匹配,而是所涉及的空格与“ messy”提交匹配。 Both git apply and patch do not like this. git applypatch都不喜欢这样。

When they look at the expected context from the patch, they think that the context does not match, and that the patch therefore cannot be applied. 当他们从补丁查看预期的上下文时,他们认为上下文不匹配,因此无法应用补丁。 Varous 'ignore whitespace', &tc. 各种“忽略空白”,&tc。 options do not seem to affect this. 选项似乎并不影响此。


The Workaround: 解决方法:

Get rid of the context lines. 摆脱上下文线。 Generate the patches with git diff -w -U0 (U for unified diff format, 0 for number of context lines), which leaves only the line numbers and replacement line data. 使用git diff -w -U0 (U用于统一diff格式,0用于上下文行数)生成补丁,仅保留行号和替换行数据。 Since this is a clean patch (Applied to the revision that was the parent of the original commit) The line numbers are the only thing that patch needs. 由于这是一个干净的补丁程序(应用于原始提交的父版本),所以行号是patch唯一需要的内容。 NOTE: git apply still did not like these patches for some reason, though patch seems to think they are just mahvelous . 注意:由于某些原因, git apply仍然不喜欢这些补丁,尽管patch似乎认为它们只是不可思议的

If you try it: 如果您尝试:

This only works if the file that you are applying to is the line for line equivalent of the one used as a base for the diff. 仅当您要应用的文件的行与用作差异基础的行等效时才行。 In practice, if you have a series of messy commits {1, 2, 3} on top of a clean base, 0 , you need to: 实际上,如果在干净的基础0之上有一系列混乱的提交{1, 2, 3} ,则需要:

  • Create a new branch, starting at 0 . 创建一个新分支,从0开始。
  • Generate your patch for 1 against 0 0生成1的补丁
  • Apply the patch to your new branch as 1a 将修补程序以1a应用于新分支
  • Generate your patch for 2 against the new, clean commit 1a 针对新的干净提交1a2生成补丁
  • &tc, as needed &tc,根据需要

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM