了解为什么使用 git diff -w --patience 创建的补丁不适用
Understanding why Patch created with git diff -w --patience does not apply
我正在尝试清理我们在我管理的项目中收到的拉取请求。
贡献者添加了许多不必要的白色-space 更改以及功能贡献。他重新缩进了几个文件中的大部分。它需要完成,但它应该是一个单独的提交。我不接受读取为 ~80 行附加功能的文件几乎完全重写的更改。
我通过将 git diff -w --patience
重定向到一个文件生成了一个补丁,这似乎是我想要的:添加或删除的特定行相对较少,并且在阅读上下文时,更改是有意义的.我同意暂时与文件其余部分缩进不一致的几行更改。
git apply
声称补丁不适用。 patch -p1 -v
基本上列出了所有的帅哥,并声明每一个都不适用。它会创建一个 .rej
文件,该文件只是对补丁的重述。 patch -p1 --merge
设法获得了第一个大块的 部分 ,并使文件充满了...奇怪的合并标记。
对我来说真正令人沮丧的是,我尝试应用补丁 的修订 与我用来生成差异的父版本完全相同!
补丁:(抱歉,太长了)
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 中还有其他的提交。现在,我正在尝试使用第一个。请注意,它的直接父级与我上面链接的版本相同。
任何关于为什么这个补丁如此不愉快,或者如何解决它的想法,将不胜感激。
在@torek 的推动下,补丁与我预期的不太一样:
-w
和 -b
选项为 git diff
生成的上下文行与父文件不匹配,相反,涉及的空格与 'messy' 提交匹配。 git apply
和 patch
都不喜欢这样。
当他们查看补丁的预期上下文时,他们认为上下文不匹配,因此无法应用补丁。各种 'ignore whitespace', &tc.选项似乎对此没有影响。
解决方法:
删除上下文行。使用 git diff -w -U0
生成补丁(U 表示统一差异格式,0 表示上下文行数),只留下行号和替换行数据。因为这是一个干净的补丁(应用于原始提交的父版本)行号是 patch
唯一需要的。注意:git apply
出于某种原因仍然不喜欢这些补丁,尽管 patch
似乎认为它们只是 mahvelous.
如果你尝试一下:
仅当您要应用的文件是与用作差异基础的文件等效的行时,这才有效。实际上,如果您在干净的基础 0
之上有一系列混乱的提交 {1, 2, 3}
,您需要:
- 创建一个新分支,从
0
开始。
- 针对
0
为 1
生成补丁
- 将补丁应用到您的新分支
1a
- 针对新的干净提交
1a
为 2
生成补丁
- &tc,根据需要
我正在尝试清理我们在我管理的项目中收到的拉取请求。
贡献者添加了许多不必要的白色-space 更改以及功能贡献。他重新缩进了几个文件中的大部分。它需要完成,但它应该是一个单独的提交。我不接受读取为 ~80 行附加功能的文件几乎完全重写的更改。
我通过将 git diff -w --patience
重定向到一个文件生成了一个补丁,这似乎是我想要的:添加或删除的特定行相对较少,并且在阅读上下文时,更改是有意义的.我同意暂时与文件其余部分缩进不一致的几行更改。
git apply
声称补丁不适用。 patch -p1 -v
基本上列出了所有的帅哥,并声明每一个都不适用。它会创建一个 .rej
文件,该文件只是对补丁的重述。 patch -p1 --merge
设法获得了第一个大块的 部分 ,并使文件充满了...奇怪的合并标记。
对我来说真正令人沮丧的是,我尝试应用补丁 的修订 与我用来生成差异的父版本完全相同!
补丁:(抱歉,太长了)
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 中还有其他的提交。现在,我正在尝试使用第一个。请注意,它的直接父级与我上面链接的版本相同。
任何关于为什么这个补丁如此不愉快,或者如何解决它的想法,将不胜感激。
在@torek 的推动下,补丁与我预期的不太一样:
-w
和 -b
选项为 git diff
生成的上下文行与父文件不匹配,相反,涉及的空格与 'messy' 提交匹配。 git apply
和 patch
都不喜欢这样。
当他们查看补丁的预期上下文时,他们认为上下文不匹配,因此无法应用补丁。各种 'ignore whitespace', &tc.选项似乎对此没有影响。
解决方法:
删除上下文行。使用 git diff -w -U0
生成补丁(U 表示统一差异格式,0 表示上下文行数),只留下行号和替换行数据。因为这是一个干净的补丁(应用于原始提交的父版本)行号是 patch
唯一需要的。注意:git apply
出于某种原因仍然不喜欢这些补丁,尽管 patch
似乎认为它们只是 mahvelous.
如果你尝试一下:
仅当您要应用的文件是与用作差异基础的文件等效的行时,这才有效。实际上,如果您在干净的基础 0
之上有一系列混乱的提交 {1, 2, 3}
,您需要:
- 创建一个新分支,从
0
开始。 - 针对
0
为 - 将补丁应用到您的新分支
1a
- 针对新的干净提交
1a
为 - &tc,根据需要
1
生成补丁
2
生成补丁