mirror of
https://github.com/git/git.git
synced 2024-06-15 06:08:14 +02:00
Merge branch 'maint'
* maint: Trailing whitespace and no newline fix diff --cc: a lost line at the beginning of the file is shown incorrectly combine-diff.c: fix performance problem when folding common deleted lines
This commit is contained in:
commit
248b6c0609
|
@ -80,6 +80,7 @@ struct lline {
|
||||||
/* Lines surviving in the merge result */
|
/* Lines surviving in the merge result */
|
||||||
struct sline {
|
struct sline {
|
||||||
struct lline *lost_head, **lost_tail;
|
struct lline *lost_head, **lost_tail;
|
||||||
|
struct lline *next_lost;
|
||||||
char *bol;
|
char *bol;
|
||||||
int len;
|
int len;
|
||||||
/* bit 0 up to (N-1) are on if the parent has this line (i.e.
|
/* bit 0 up to (N-1) are on if the parent has this line (i.e.
|
||||||
|
@ -121,18 +122,12 @@ static void append_lost(struct sline *sline, int n, const char *line, int len)
|
||||||
|
|
||||||
/* Check to see if we can squash things */
|
/* Check to see if we can squash things */
|
||||||
if (sline->lost_head) {
|
if (sline->lost_head) {
|
||||||
struct lline *last_one = NULL;
|
lline = sline->next_lost;
|
||||||
/* We cannot squash it with earlier one */
|
|
||||||
for (lline = sline->lost_head;
|
|
||||||
lline;
|
|
||||||
lline = lline->next)
|
|
||||||
if (lline->parent_map & this_mask)
|
|
||||||
last_one = lline;
|
|
||||||
lline = last_one ? last_one->next : sline->lost_head;
|
|
||||||
while (lline) {
|
while (lline) {
|
||||||
if (lline->len == len &&
|
if (lline->len == len &&
|
||||||
!memcmp(lline->line, line, len)) {
|
!memcmp(lline->line, line, len)) {
|
||||||
lline->parent_map |= this_mask;
|
lline->parent_map |= this_mask;
|
||||||
|
sline->next_lost = lline->next;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
lline = lline->next;
|
lline = lline->next;
|
||||||
|
@ -147,6 +142,7 @@ static void append_lost(struct sline *sline, int n, const char *line, int len)
|
||||||
lline->line[len] = 0;
|
lline->line[len] = 0;
|
||||||
*sline->lost_tail = lline;
|
*sline->lost_tail = lline;
|
||||||
sline->lost_tail = &lline->next;
|
sline->lost_tail = &lline->next;
|
||||||
|
sline->next_lost = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct combine_diff_state {
|
struct combine_diff_state {
|
||||||
|
@ -168,25 +164,28 @@ static void consume_line(void *state_, char *line, unsigned long len)
|
||||||
&state->nb, &state->nn))
|
&state->nb, &state->nn))
|
||||||
return;
|
return;
|
||||||
state->lno = state->nb;
|
state->lno = state->nb;
|
||||||
if (!state->nb)
|
if (state->nn == 0) {
|
||||||
/* @@ -1,2 +0,0 @@ to remove the
|
|
||||||
* first two lines...
|
|
||||||
*/
|
|
||||||
state->nb = 1;
|
|
||||||
if (state->nn == 0)
|
|
||||||
/* @@ -X,Y +N,0 @@ removed Y lines
|
/* @@ -X,Y +N,0 @@ removed Y lines
|
||||||
* that would have come *after* line N
|
* that would have come *after* line N
|
||||||
* in the result. Our lost buckets hang
|
* in the result. Our lost buckets hang
|
||||||
* to the line after the removed lines,
|
* to the line after the removed lines,
|
||||||
|
*
|
||||||
|
* Note that this is correct even when N == 0,
|
||||||
|
* in which case the hunk removes the first
|
||||||
|
* line in the file.
|
||||||
*/
|
*/
|
||||||
state->lost_bucket = &state->sline[state->nb];
|
state->lost_bucket = &state->sline[state->nb];
|
||||||
else
|
if (!state->nb)
|
||||||
|
state->nb = 1;
|
||||||
|
} else {
|
||||||
state->lost_bucket = &state->sline[state->nb-1];
|
state->lost_bucket = &state->sline[state->nb-1];
|
||||||
|
}
|
||||||
if (!state->sline[state->nb-1].p_lno)
|
if (!state->sline[state->nb-1].p_lno)
|
||||||
state->sline[state->nb-1].p_lno =
|
state->sline[state->nb-1].p_lno =
|
||||||
xcalloc(state->num_parent,
|
xcalloc(state->num_parent,
|
||||||
sizeof(unsigned long));
|
sizeof(unsigned long));
|
||||||
state->sline[state->nb-1].p_lno[state->n] = state->ob;
|
state->sline[state->nb-1].p_lno[state->n] = state->ob;
|
||||||
|
state->lost_bucket->next_lost = state->lost_bucket->lost_head;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!state->lost_bucket)
|
if (!state->lost_bucket)
|
||||||
|
|
|
@ -0,0 +1,84 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
test_description='combined diff'
|
||||||
|
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
setup_helper () {
|
||||||
|
one=$1 branch=$2 side=$3 &&
|
||||||
|
|
||||||
|
git branch $side $branch &&
|
||||||
|
for l in $one two three fyra
|
||||||
|
do
|
||||||
|
echo $l
|
||||||
|
done >file &&
|
||||||
|
git add file &&
|
||||||
|
test_tick &&
|
||||||
|
git commit -m $branch &&
|
||||||
|
git checkout $side &&
|
||||||
|
for l in $one two three quatro
|
||||||
|
do
|
||||||
|
echo $l
|
||||||
|
done >file &&
|
||||||
|
git add file &&
|
||||||
|
test_tick &&
|
||||||
|
git commit -m $side &&
|
||||||
|
test_must_fail git merge $branch &&
|
||||||
|
for l in $one three four
|
||||||
|
do
|
||||||
|
echo $l
|
||||||
|
done >file &&
|
||||||
|
git add file &&
|
||||||
|
test_tick &&
|
||||||
|
git commit -m "merge $branch into $side"
|
||||||
|
}
|
||||||
|
|
||||||
|
verify_helper () {
|
||||||
|
it=$1 &&
|
||||||
|
|
||||||
|
# Ignore lines that were removed only from the other parent
|
||||||
|
sed -e '
|
||||||
|
1,/^@@@/d
|
||||||
|
/^ -/d
|
||||||
|
s/^\(.\)./\1/
|
||||||
|
' "$it" >"$it.actual.1" &&
|
||||||
|
sed -e '
|
||||||
|
1,/^@@@/d
|
||||||
|
/^- /d
|
||||||
|
s/^.\(.\)/\1/
|
||||||
|
' "$it" >"$it.actual.2" &&
|
||||||
|
|
||||||
|
git diff "$it^" "$it" -- | sed -e '1,/^@@/d' >"$it.expect.1" &&
|
||||||
|
test_cmp "$it.expect.1" "$it.actual.1" &&
|
||||||
|
|
||||||
|
git diff "$it^2" "$it" -- | sed -e '1,/^@@/d' >"$it.expect.2" &&
|
||||||
|
test_cmp "$it.expect.2" "$it.actual.2"
|
||||||
|
}
|
||||||
|
|
||||||
|
test_expect_success setup '
|
||||||
|
>file &&
|
||||||
|
git add file &&
|
||||||
|
test_tick &&
|
||||||
|
git commit -m initial &&
|
||||||
|
|
||||||
|
git branch withone &&
|
||||||
|
git branch sansone &&
|
||||||
|
|
||||||
|
git checkout withone &&
|
||||||
|
setup_helper one withone sidewithone &&
|
||||||
|
|
||||||
|
git checkout sansone &&
|
||||||
|
setup_helper "" sansone sidesansone
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'check combined output (1)' '
|
||||||
|
git show sidewithone -- >sidewithone &&
|
||||||
|
verify_helper sidewithone
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_failure 'check combined output (2)' '
|
||||||
|
git show sidesansone -- >sidesansone &&
|
||||||
|
verify_helper sidesansone
|
||||||
|
'
|
||||||
|
|
||||||
|
test_done
|
|
@ -148,4 +148,22 @@ do
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
|
create_patch () {
|
||||||
|
sed -e "s/_/ /" <<-\EOF
|
||||||
|
diff --git a/target b/target
|
||||||
|
index e69de29..8bd6648 100644
|
||||||
|
--- a/target
|
||||||
|
+++ b/target
|
||||||
|
@@ -0,0 +1 @@
|
||||||
|
+A line with trailing whitespace and no newline_
|
||||||
|
\ No newline at end of file
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
test_expect_success 'trailing whitespace & no newline at the end of file' '
|
||||||
|
>target &&
|
||||||
|
create_patch | git apply --whitespace=fix - &&
|
||||||
|
grep "newline$" target
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
5
ws.c
5
ws.c
|
@ -261,9 +261,8 @@ int ws_fix_copy(char *dst, const char *src, int len, unsigned ws_rule, int *erro
|
||||||
/*
|
/*
|
||||||
* Strip trailing whitespace
|
* Strip trailing whitespace
|
||||||
*/
|
*/
|
||||||
if ((ws_rule & WS_TRAILING_SPACE) &&
|
if (ws_rule & WS_TRAILING_SPACE) {
|
||||||
(2 <= len && isspace(src[len-2]))) {
|
if (1 < len && src[len - 1] == '\n') {
|
||||||
if (src[len - 1] == '\n') {
|
|
||||||
add_nl_to_tail = 1;
|
add_nl_to_tail = 1;
|
||||||
len--;
|
len--;
|
||||||
if (1 < len && src[len - 1] == '\r') {
|
if (1 < len && src[len - 1] == '\r') {
|
||||||
|
|
Loading…
Reference in New Issue