forked from git/git
-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add -p: a couple of hunk splitting fixes #1863
Open
phillipwood
wants to merge
1
commit into
gitgitgadget:master
Choose a base branch
from
phillipwood:add-p-split-hunks-are-undecided
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1181,19 +1181,29 @@ static ssize_t recount_edited_hunk(struct add_p_state *s, struct hunk *hunk, | |
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this): "Phillip Wood via GitGitGadget" <[email protected]> writes:
> From: Phillip Wood <[email protected]>
>
> When the users edits a hunk if they change deletion lines to context
> lines or vice versa then the number of hunks that the edited hunk can be
> split into may differ from the unedited hunk and so we need to update
> hunk->splittable_into. In practice users are unlikely to hit this bug as
> it is doubtful that a user who has edited a hunk will split it
> afterwards.
Heh, when I did the original "add -i/-p", I said "it is doubtful
that a user who has selected a hunk will split it afterwards" ;-)
> Signed-off-by: Phillip Wood <[email protected]>
> ---
> add-patch.c | 12 +++++++++++-
> t/t3701-add-interactive.sh | 21 +++++++++++++++++++++
> 2 files changed, 32 insertions(+), 1 deletion(-)
>
> diff --git a/add-patch.c b/add-patch.c
> index f44f98275cc..982745373df 100644
> --- a/add-patch.c
> +++ b/add-patch.c
> @@ -1182,19 +1182,29 @@ static ssize_t recount_edited_hunk(struct add_p_state *s, struct hunk *hunk,
> {
> struct hunk_header *header = &hunk->header;
> size_t i;
> + char ch, marker = ' ';
>
> + hunk->splittable_into = 0;
> header->old_count = header->new_count = 0;
> for (i = hunk->start; i < hunk->end; ) {
> - switch(normalize_marker(&s->plain.buf[i])) {
> + ch = normalize_marker(&s->plain.buf[i]);
> + switch (ch) {
> case '-':
> header->old_count++;
> + if (marker == ' ')
> + hunk->splittable_into++;
> + marker = ch;
> break;
> case '+':
> header->new_count++;
> + if (marker == ' ')
> + hunk->splittable_into++;
> + marker = ch;
> break;
> case ' ':
> header->old_count++;
> header->new_count++;
> + marker = ch;
> break;
> }
OK.
> diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh
> index 760f3d0d30f..cb81bfe64c8 100755
> --- a/t/t3701-add-interactive.sh
> +++ b/t/t3701-add-interactive.sh
> @@ -1240,4 +1240,25 @@ test_expect_success 'splitting previous hunk marks split hunks as undecided' '
> test_cmp expect actual
> '
>
> +test_expect_success 'splitting edited hunk' '
> + # Before the first hunk is edited it can be split into two
> + # hunks, after editing it can be split into three hunks.
> +
> + write_script fake-editor.sh <<-\EOF &&
> + sed "s/^ c/-c/" "$1" >"$1.tmp" &&
> + mv "$1.tmp" "$1"
> + EOF
> +
> + test_write_lines a b c d e f g h i j k l m n>file &&
> + git add file &&
> + test_write_lines A b c d E f g h i j k l M n >file &&
Missing SP before ">file" on the earlier line.
> + (
> + test_set_editor "$(pwd)/fake-editor.sh" &&
> + test_write_lines e K s j y n y q | git add -p file
> + ) &&
> + git cat-file blob :file >actual &&
> + test_write_lines a b d e f g h i j k l M n >expect &&
> + test_cmp expect actual
> +'
> +
> test_done |
||
struct hunk_header *header = &hunk->header; | ||
size_t i; | ||
char ch, marker = ' '; | ||
|
||
hunk->splittable_into = 0; | ||
header->old_count = header->new_count = 0; | ||
for (i = hunk->start; i < hunk->end; ) { | ||
switch(normalize_marker(&s->plain.buf[i])) { | ||
ch = normalize_marker(&s->plain.buf[i]); | ||
switch (ch) { | ||
case '-': | ||
header->old_count++; | ||
if (marker == ' ') | ||
hunk->splittable_into++; | ||
marker = ch; | ||
break; | ||
case '+': | ||
header->new_count++; | ||
if (marker == ' ') | ||
hunk->splittable_into++; | ||
marker = ch; | ||
break; | ||
case ' ': | ||
header->old_count++; | ||
header->new_count++; | ||
marker = ch; | ||
break; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the Git mailing list, Justin Tobler wrote (reply to this):