From: Johannes Schindelin <hidden> Date: 2016-06-15 22:44:41
Sometimes, the easiest way to fix up a patch is to edit it directly, even
adding or deleting lines. Now, many people are not as divine as certain
benevolent dictators as to update the hunk headers correctly at the first
try.
So teach the tool to do it for us.
Signed-off-by: Johannes Schindelin <redacted>
---
Documentation/git-apply.txt | 6 ++++-
builtin-apply.c | 55 +++++++++++++++++++++++++++++++++++++++---
2 files changed, 56 insertions(+), 5 deletions(-)
@@ -169,6 +169,10 @@ behavior: correctly. This option adds support for applying such patches by working around this bug.+--fixup-line-counts::+ Fix up the line counts (e.g. after editing the patch without+ adjusting the hunk headers appropriately).+ -v, --verbose:: Report progress to stderr. By default, only a message about the current patch being applied will be printed. This option will cause
From: Johannes Schindelin <hidden> Date: 2016-06-15 22:44:41
With "git add -e [<files>]", Git will fire up an editor with the current
diff relative to the index (i.e. what you would get with "git diff
[<files>]").
Now you can edit the patch as much as you like, including adding/removing
lines, editing the text, whatever. Make sure, though, that the first
character of the hunk lines is still a space, a plus or a minus.
After you closed the editor, Git will adjust the line counts of the
hunks if necessary, thanks to the --fixup-line-counts option of apply,
and commit the patch. Except if you deleted everything, in which case
nothing happens (for obvious reasons).
Signed-off-by: Johannes Schindelin <redacted>
---
This was too useful to let slip by. I even committed it using
"git add -e <files>" several times!
Anyway, bed time.
Documentation/git-add.txt | 9 ++++++-
builtin-add.c | 49 ++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 55 insertions(+), 3 deletions(-)
@@ -70,6 +70,11 @@ OPTIONS bypassed and the 'patch' subcommand is invoked using each of the specified filepatterns before exiting.+-e, \--edit::+ Open the diff vs. the index in an editor and let the user+ edit it. After the editor was closed, adjust the hunk headers+ and apply the patch to the index.+ -u:: Update only files that git already knows about, staging modified content for commit and marking deleted files for removal. This
From: Johannes Sixt <hidden> Date: 2016-06-15 22:44:41
Johannes Schindelin schrieb:
+--fixup-line-counts::
+ Fix up the line counts (e.g. after editing the patch without
+ adjusting the hunk headers appropriately).
This sort of implies that there is some kind of output that tells the
correct line counts. But that isn't the case (if I read the patch
correctly). So I suggest to name the option --ignore-line-counts.
-- Hannes
From: Johannes Schindelin <hidden> Date: 2016-06-15 22:44:41
Hi,
On Thu, 5 Jun 2008, Johannes Sixt wrote:
Johannes Schindelin schrieb:
quoted
+--fixup-line-counts::
+ Fix up the line counts (e.g. after editing the patch without
+ adjusting the hunk headers appropriately).
This sort of implies that there is some kind of output that tells the
correct line counts. But that isn't the case (if I read the patch
correctly). So I suggest to name the option --ignore-line-counts.
But there is some kind of output: the hunks themselves. And the line
counts are not ignored, but they are actively rewritten. But if you have
a suggestion which keeps the spirit, I am very interested...
Ciao,
Dscho
From: Johannes Sixt <hidden> Date: 2016-06-15 22:44:41
Johannes Schindelin schrieb:
Hi,
On Thu, 5 Jun 2008, Johannes Sixt wrote:
quoted
Johannes Schindelin schrieb:
quoted
+--fixup-line-counts::
+ Fix up the line counts (e.g. after editing the patch without
+ adjusting the hunk headers appropriately).
This sort of implies that there is some kind of output that tells the
correct line counts. But that isn't the case (if I read the patch
correctly). So I suggest to name the option --ignore-line-counts.
But there is some kind of output: the hunks themselves.
Is there? I did this (it rewrites all line counts to 1):
$ git diff ..HEAD~1 |
sed -e '/^@@/s/,[0-9]+ /,1 /g' |
./git-apply --fixup-line-counts
and there was no output. Instead, the patch was applied.
And the line
counts are not ignored, but they are actively rewritten.
Of course, internally there is some sort of "output" from the fixup
routine, and the line counts are rewritten and then are not ignored. But
the user doesn't care about this internal procedure. From the user's
perspective, the line counts of the input patch are ignored.
Apart from this color of the bikeshed I like your patch.
-- Hannes
From: Johannes Schindelin <hidden> Date: 2016-06-15 22:44:41
Hi,
On Thu, 5 Jun 2008, Johannes Sixt wrote:
Johannes Schindelin schrieb:
quoted
On Thu, 5 Jun 2008, Johannes Sixt wrote:
quoted
Johannes Schindelin schrieb:
quoted
+--fixup-line-counts::
+ Fix up the line counts (e.g. after editing the patch without
+ adjusting the hunk headers appropriately).
This sort of implies that there is some kind of output that tells the
correct line counts. But that isn't the case (if I read the patch
correctly). So I suggest to name the option --ignore-line-counts.
But there is some kind of output: the hunks themselves.
Is there?
Yes!
I did this (it rewrites all line counts to 1):
$ git diff ..HEAD~1 |
sed -e '/^@@/s/,[0-9]+ /,1 /g' |
./git-apply --fixup-line-counts
and there was no output. Instead, the patch was applied.
As I said, the data is in the _hunks_, but I maybe should have added _not
in the hunk headers_.
So in a very real sense, you edit the hunks, and the hunk headers are
adjusted to that. You did not adjust the hunks, so they got applied.
It seems that you think the hunk header's line counts are heeded, and the
hunk adjusted, with --fixup-line-counts? Sorry, I find that rather
counterintuitive.
quoted
And the line counts are not ignored, but they are actively rewritten.
Of course, internally there is some sort of "output" from the fixup
routine, and the line counts are rewritten and then are not ignored. But
the user doesn't care about this internal procedure. From the user's
perspective, the line counts of the input patch are ignored.
But they are not!
There are _two_ things that are the line counts. Those numbers in the
hunk header, and the real line counts of the hunks.
Now, if you say they are _ignored_, would that not imply in plain English
that they are left unchanged (in limbo, because those two types of numbers
contradict each other)?
Okay, how about shikebedding this to --adjust-line-counts?
Ciao,
Dscho
From: Johannes Sixt <hidden> Date: 2016-06-15 22:44:41
Johannes Schindelin schrieb:
Hi,
On Thu, 5 Jun 2008, Johannes Sixt wrote:
quoted
Johannes Schindelin schrieb:
quoted
On Thu, 5 Jun 2008, Johannes Sixt wrote:
quoted
Johannes Schindelin schrieb:
quoted
+--fixup-line-counts::
+ Fix up the line counts (e.g. after editing the patch without
+ adjusting the hunk headers appropriately).
This sort of implies that there is some kind of output that tells the
correct line counts. But that isn't the case (if I read the patch
correctly). So I suggest to name the option --ignore-line-counts.
But there is some kind of output: the hunks themselves.
Is there?
Yes!
quoted
I did this (it rewrites all line counts to 1):
$ git diff ..HEAD~1 |
sed -e '/^@@/s/,[0-9]+ /,1 /g' |
./git-apply --fixup-line-counts
and there was no output. Instead, the patch was applied.
As I said, the data is in the _hunks_, but I maybe should have added _not
in the hunk headers_.
Yes, of course.
So in a very real sense, you edit the hunks, and the hunk headers are
adjusted to that. You did not adjust the hunks, so they got applied.
Yes, of course.
But the example pretends that the hunks have been edited so heavily that
they in no way match the line counts in the hunk headers.
It seems that you think the hunk header's line counts are heeded, and the
hunk adjusted, with --fixup-line-counts?
NO, of course *NOT*.
Sorry, I find that rather
counterintuitive.
So would I.
quoted
quoted
And the line counts are not ignored, but they are actively rewritten.
Of course, internally there is some sort of "output" from the fixup
routine, and the line counts are rewritten and then are not ignored. But
the user doesn't care about this internal procedure. From the user's
perspective, the line counts of the input patch are ignored.
But they are not!
There are _two_ things that are the line counts. Those numbers in the
hunk header, and the real line counts of the hunks.
And I was always talking about the numbers in the hunk headers.
Now, if you say they are _ignored_, would that not imply in plain English
that they are left unchanged (in limbo, because those two types of numbers
contradict each other)?
That you *internally* rewrite those numbers and then do *not* ignore them
is totally pointless for the user. It's an implementation detail. The user
doesn't see what is going on nor should he care. From the user's
perspective, the hunk header line counts are _ignored_ (because if they
were not ignored, then there would be an error message in the
contradicting case).
Okay, how about shikebedding this to --adjust-line-counts?
From the user's perspective, nothing is "adjusted"; the hunk header line
counts are ... you guess it ... *ignored*.
-- Hannes
From: Johannes Schindelin <hidden> Date: 2016-06-15 22:44:41
Hi,
On Thu, 5 Jun 2008, Johannes Sixt wrote:
quoted
Now, if you say they are _ignored_, would that not imply in plain
English that they are left unchanged (in limbo, because those two
types of numbers contradict each other)?
That you *internally* rewrite those numbers and then do *not* ignore
them is totally pointless for the user. It's an implementation detail.
The user doesn't see what is going on nor should he care. From the
user's perspective, the hunk header line counts are _ignored_ (because
if they were not ignored, then there would be an error message in the
contradicting case).
quoted
Okay, how about shikebedding this to --adjust-line-counts?
From the user's perspective, nothing is "adjusted"; the hunk header line
counts are ... you guess it ... *ignored*.
Oh... I start to see what you mean. It's just that for me, the line
counts are the actual line counts, not what is recorded in the hunk
header.
In any case, I really do not feel strongly about it, since I do not want
to use it, except with git add -e. Which I really grew fond of in these
last hours ;-)
So how about --ignore-hunk-headers? I think this is much more
descriptive, and catches your complaint, IMHO.
Ciao,
Dscho
From: Johannes Schindelin <hidden> Date: 2016-06-15 22:44:41
With "git add -e [<files>]", Git will fire up an editor with the current
diff relative to the index (i.e. what you would get with "git diff
[<files>]").
Now you can edit the patch as much as you like, including adding/removing
lines, editing the text, whatever. Make sure, though, that the first
character of the hunk lines is still a space, a plus or a minus.
After you closed the editor, Git will adjust the line counts of the
hunks if necessary, thanks to the --fixup-line-counts option of apply,
and commit the patch. Except if you deleted everything, in which case
nothing happens (for obvious reasons).
Signed-off-by: Johannes Schindelin <redacted>
---
Documentation/git-add.txt | 9 ++++-
builtin-add.c | 47 ++++++++++++++++++++++++-
t/t3702-add-edit.sh | 86 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 139 insertions(+), 3 deletions(-)
create mode 100755 t/t3702-add-edit.sh
@@ -70,6 +70,11 @@ OPTIONS bypassed and the 'patch' subcommand is invoked using each of the specified filepatterns before exiting.+-e, \--edit::+ Open the diff vs. the index in an editor and let the user+ edit it. After the editor was closed, adjust the hunk headers+ and apply the patch to the index.+ -u:: Update only files that git already knows about, staging modified content for commit and marking deleted files for removal. This
From: Johannes Schindelin <hidden> Date: 2016-06-15 22:44:41
Sometimes, the easiest way to fix up a patch is to edit it directly, even
adding or deleting lines. Now, many people are not as divine as certain
benevolent dictators as to update the hunk headers correctly at the first
try.
So teach the tool to do it for us.
Signed-off-by: Johannes Schindelin <redacted>
---
Documentation/git-apply.txt | 7 ++++-
builtin-apply.c | 57 ++++++++++++++++++++++++++++++++++++++++---
2 files changed, 59 insertions(+), 5 deletions(-)
@@ -169,6 +169,11 @@ behavior: correctly. This option adds support for applying such patches by working around this bug.+--ignore-hunk-headers::+ Do not trust the line counts in the hunk headers, but infer them+ by inspecting the patch (e.g. after editing the patch without+ adjusting the hunk headers appropriately).+ -v, --verbose:: Report progress to stderr. By default, only a message about the current patch being applied will be printed. This option will cause
From: Pieter de Bie <hidden> Date: 2016-06-15 22:44:41
On 5 jun 2008, at 18:20, Johannes Schindelin wrote:
With "git add -e [<files>]", Git will fire up an editor with the
current
diff relative to the index (i.e. what you would get with "git diff
[<files>]").
Now you can edit the patch as much as you like, including adding/
removing
lines, editing the text, whatever. Make sure, though, that the first
character of the hunk lines is still a space, a plus or a minus.
Nice feature! However, the lockfile isn't deleted on my system (OS X),
perhaps because the atexit() isn't called after an exec(). How about
this
patch?