簡體   English   中英

了解為什么使用git diff -w --patience創建的補丁不適用

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

我正在嘗試清理在我管理的項目中收到的請求請求。

貢獻者在功能貢獻中添加了許多不必要的空白更改。 他重新縮進了幾個文件中的大多數文件。 它需要完成,但是應該是單獨的提交。 我不接受將大約80行附加功能讀為幾乎完全重寫文件的更改。

我通過將git diff -w --patience重定向到文件生成了一個補丁,這似乎是我想要的:添加或刪除了相對較少的幾行,並且在讀取上下文時,這些更改才有意義。 我可以暫時將少數更改的行與文件的其余部分不一致地縮進。

git apply聲稱該補丁不適用。 patch -p1 -v基本上列出了所有的塊,並指出每個塊都不適用。 它會創建一個.rej文件,該文件只是補丁的重述。 patch -p1 --merge設法獲得第一個塊的一部分 ,並使文件充滿了...奇怪的合並標記。

對我來說,真的令人沮喪的是,我想應用補丁的版本是我用來生成DIFF完全相同的父!

補丁:(對不起,很長)

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

我已將該補丁截斷到一定程度:我已經刪除了第二個文件的差異,該差異正確應用。

我想在github上應用補丁的文件-permalink

我從開始的(混亂)提交注意:此PR中還有其他提交。 現在,我正在嘗試使用第一個。 請注意,它的直接父級是我上面鏈接的相同修訂版。

關於此修補程序為何如此煩躁或如何對其進行故障排除的任何構想,將不勝感激。

正如@torek向我推動的那樣,該補丁與我所期望的不完全相同:

git diff-w-b選項生成的上下文行與父文件不匹配,而是所涉及的空格與“ messy”提交匹配。 git applypatch都不喜歡這樣。

當他們從補丁查看預期的上下文時,他們認為上下文不匹配,因此無法應用補丁。 各種“忽略空白”,&tc。 選項似乎並不影響此。


解決方法:

擺脫上下文線。 使用git diff -w -U0 (U用於統一diff格式,0用於上下文行數)生成補丁,僅保留行號和替換行數據。 由於這是一個干凈的補丁程序(應用於原始提交的父版本),所以行號是patch唯一需要的內容。 注意:由於某些原因, git apply仍然不喜歡這些補丁,盡管patch似乎認為它們只是不可思議的

如果您嘗試:

僅當您要應用的文件的行與用作差異基礎的行等效時才行。 實際上,如果在干凈的基礎0之上有一系列混亂的提交{1, 2, 3} ,則需要:

  • 創建一個新分支,從0開始。
  • 0生成1的補丁
  • 將修補程序以1a應用於新分支
  • 針對新的干凈提交1a2生成補丁
  • &tc,根據需要

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM