Merge branch 'jc/fix-diff-files-unmerged' into maint
* jc/fix-diff-files-unmerged: diff-files: show unmerged entries correctly diff: remove often unused parameters from diff_unmerge() diff.c: return filepair from diff_unmerge() test: use $_z40 from test-lib
This commit is contained in:
commit
a613b534bc
15
diff-lib.c
15
diff-lib.c
@ -112,6 +112,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
|
|||||||
|
|
||||||
if (ce_stage(ce)) {
|
if (ce_stage(ce)) {
|
||||||
struct combine_diff_path *dpath;
|
struct combine_diff_path *dpath;
|
||||||
|
struct diff_filepair *pair;
|
||||||
|
unsigned int wt_mode = 0;
|
||||||
int num_compare_stages = 0;
|
int num_compare_stages = 0;
|
||||||
size_t path_len;
|
size_t path_len;
|
||||||
|
|
||||||
@ -130,7 +132,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
|
|||||||
|
|
||||||
changed = check_removed(ce, &st);
|
changed = check_removed(ce, &st);
|
||||||
if (!changed)
|
if (!changed)
|
||||||
dpath->mode = ce_mode_from_stat(ce, st.st_mode);
|
wt_mode = ce_mode_from_stat(ce, st.st_mode);
|
||||||
else {
|
else {
|
||||||
if (changed < 0) {
|
if (changed < 0) {
|
||||||
perror(ce->name);
|
perror(ce->name);
|
||||||
@ -138,7 +140,9 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
|
|||||||
}
|
}
|
||||||
if (silent_on_removed)
|
if (silent_on_removed)
|
||||||
continue;
|
continue;
|
||||||
|
wt_mode = 0;
|
||||||
}
|
}
|
||||||
|
dpath->mode = wt_mode;
|
||||||
|
|
||||||
while (i < entries) {
|
while (i < entries) {
|
||||||
struct cache_entry *nce = active_cache[i];
|
struct cache_entry *nce = active_cache[i];
|
||||||
@ -184,7 +188,9 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
|
|||||||
* Show the diff for the 'ce' if we found the one
|
* Show the diff for the 'ce' if we found the one
|
||||||
* from the desired stage.
|
* from the desired stage.
|
||||||
*/
|
*/
|
||||||
diff_unmerge(&revs->diffopt, ce->name, 0, null_sha1);
|
pair = diff_unmerge(&revs->diffopt, ce->name);
|
||||||
|
if (wt_mode)
|
||||||
|
pair->two->mode = wt_mode;
|
||||||
if (ce_stage(ce) != diff_unmerged_stage)
|
if (ce_stage(ce) != diff_unmerged_stage)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -373,8 +379,9 @@ static void do_oneway_diff(struct unpack_trees_options *o,
|
|||||||
match_missing = !revs->ignore_merges;
|
match_missing = !revs->ignore_merges;
|
||||||
|
|
||||||
if (cached && idx && ce_stage(idx)) {
|
if (cached && idx && ce_stage(idx)) {
|
||||||
diff_unmerge(&revs->diffopt, idx->name, idx->ce_mode,
|
struct diff_filepair *pair;
|
||||||
idx->sha1);
|
pair = diff_unmerge(&revs->diffopt, idx->name);
|
||||||
|
fill_filespec(pair->one, idx->sha1, idx->ce_mode);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
diff.c
12
diff.c
@ -4381,20 +4381,20 @@ void diff_change(struct diff_options *options,
|
|||||||
DIFF_OPT_SET(options, HAS_CHANGES);
|
DIFF_OPT_SET(options, HAS_CHANGES);
|
||||||
}
|
}
|
||||||
|
|
||||||
void diff_unmerge(struct diff_options *options,
|
struct diff_filepair *diff_unmerge(struct diff_options *options, const char *path)
|
||||||
const char *path,
|
|
||||||
unsigned mode, const unsigned char *sha1)
|
|
||||||
{
|
{
|
||||||
|
struct diff_filepair *pair;
|
||||||
struct diff_filespec *one, *two;
|
struct diff_filespec *one, *two;
|
||||||
|
|
||||||
if (options->prefix &&
|
if (options->prefix &&
|
||||||
strncmp(path, options->prefix, options->prefix_length))
|
strncmp(path, options->prefix, options->prefix_length))
|
||||||
return;
|
return NULL;
|
||||||
|
|
||||||
one = alloc_filespec(path);
|
one = alloc_filespec(path);
|
||||||
two = alloc_filespec(path);
|
two = alloc_filespec(path);
|
||||||
fill_filespec(one, sha1, mode);
|
pair = diff_queue(&diff_queued_diff, one, two);
|
||||||
diff_queue(&diff_queued_diff, one, two)->is_unmerged = 1;
|
pair->is_unmerged = 1;
|
||||||
|
return pair;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *run_textconv(const char *pgm, struct diff_filespec *spec,
|
static char *run_textconv(const char *pgm, struct diff_filespec *spec,
|
||||||
|
5
diff.h
5
diff.h
@ -208,10 +208,7 @@ extern void diff_change(struct diff_options *,
|
|||||||
const char *fullpath,
|
const char *fullpath,
|
||||||
unsigned dirty_submodule1, unsigned dirty_submodule2);
|
unsigned dirty_submodule1, unsigned dirty_submodule2);
|
||||||
|
|
||||||
extern void diff_unmerge(struct diff_options *,
|
extern struct diff_filepair *diff_unmerge(struct diff_options *, const char *path);
|
||||||
const char *path,
|
|
||||||
unsigned mode,
|
|
||||||
const unsigned char *sha1);
|
|
||||||
|
|
||||||
#define DIFF_SETUP_REVERSE 1
|
#define DIFF_SETUP_REVERSE 1
|
||||||
#define DIFF_SETUP_USE_CACHE 2
|
#define DIFF_SETUP_USE_CACHE 2
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
test_description='Test git update-ref and basic ref logging'
|
test_description='Test git update-ref and basic ref logging'
|
||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
|
|
||||||
Z=0000000000000000000000000000000000000000
|
Z=$_z40
|
||||||
|
|
||||||
test_expect_success setup '
|
test_expect_success setup '
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@ test_expect_success 'setup' '
|
|||||||
EMPTY_TREE=$(git write-tree) &&
|
EMPTY_TREE=$(git write-tree) &&
|
||||||
EMPTY_BLOB=$(git hash-object -t blob --stdin </dev/null) &&
|
EMPTY_BLOB=$(git hash-object -t blob --stdin </dev/null) &&
|
||||||
CHANGED_BLOB=$(echo changed | git hash-object -t blob --stdin) &&
|
CHANGED_BLOB=$(echo changed | git hash-object -t blob --stdin) &&
|
||||||
ZEROES=0000000000000000000000000000000000000000 &&
|
|
||||||
EMPTY_BLOB7=$(echo $EMPTY_BLOB | sed "s/\(.......\).*/\1/") &&
|
EMPTY_BLOB7=$(echo $EMPTY_BLOB | sed "s/\(.......\).*/\1/") &&
|
||||||
CHANGED_BLOB7=$(echo $CHANGED_BLOB | sed "s/\(.......\).*/\1/") &&
|
CHANGED_BLOB7=$(echo $CHANGED_BLOB | sed "s/\(.......\).*/\1/") &&
|
||||||
|
|
||||||
@ -239,10 +238,10 @@ test_expect_success '_gently() groks relative GIT_DIR & GIT_WORK_TREE' '
|
|||||||
|
|
||||||
test_expect_success 'diff-index respects work tree under .git dir' '
|
test_expect_success 'diff-index respects work tree under .git dir' '
|
||||||
cat >diff-index-cached.expected <<-EOF &&
|
cat >diff-index-cached.expected <<-EOF &&
|
||||||
:000000 100644 $ZEROES $EMPTY_BLOB A sub/dir/tracked
|
:000000 100644 $_z40 $EMPTY_BLOB A sub/dir/tracked
|
||||||
EOF
|
EOF
|
||||||
cat >diff-index.expected <<-EOF &&
|
cat >diff-index.expected <<-EOF &&
|
||||||
:000000 100644 $ZEROES $ZEROES A sub/dir/tracked
|
:000000 100644 $_z40 $_z40 A sub/dir/tracked
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
(
|
(
|
||||||
@ -258,7 +257,7 @@ test_expect_success 'diff-index respects work tree under .git dir' '
|
|||||||
|
|
||||||
test_expect_success 'diff-files respects work tree under .git dir' '
|
test_expect_success 'diff-files respects work tree under .git dir' '
|
||||||
cat >diff-files.expected <<-EOF &&
|
cat >diff-files.expected <<-EOF &&
|
||||||
:100644 100644 $EMPTY_BLOB $ZEROES M sub/dir/tracked
|
:100644 100644 $EMPTY_BLOB $_z40 M sub/dir/tracked
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
(
|
(
|
||||||
|
@ -15,7 +15,7 @@ test_expect_success 'checkout should not start branch from a tree' '
|
|||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'checkout master from invalid HEAD' '
|
test_expect_success 'checkout master from invalid HEAD' '
|
||||||
echo 0000000000000000000000000000000000000000 >.git/HEAD &&
|
echo $_z40 >.git/HEAD &&
|
||||||
git checkout master --
|
git checkout master --
|
||||||
'
|
'
|
||||||
|
|
||||||
|
@ -4,8 +4,6 @@ test_description='more git add -u'
|
|||||||
|
|
||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
|
|
||||||
_z40=0000000000000000000000000000000000000000
|
|
||||||
|
|
||||||
test_expect_success setup '
|
test_expect_success setup '
|
||||||
>xyzzy &&
|
>xyzzy &&
|
||||||
_empty=$(git hash-object --stdin <xyzzy) &&
|
_empty=$(git hash-object --stdin <xyzzy) &&
|
||||||
|
@ -46,7 +46,7 @@ test_expect_success \
|
|||||||
'git branch a/b/c && test -f .git/refs/heads/a/b/c'
|
'git branch a/b/c && test -f .git/refs/heads/a/b/c'
|
||||||
|
|
||||||
cat >expect <<EOF
|
cat >expect <<EOF
|
||||||
0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
|
$_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
|
||||||
EOF
|
EOF
|
||||||
test_expect_success \
|
test_expect_success \
|
||||||
'git branch -l d/e/f should create a branch and a log' \
|
'git branch -l d/e/f should create a branch and a log' \
|
||||||
@ -230,7 +230,7 @@ test_expect_success \
|
|||||||
|
|
||||||
# Keep this test last, as it changes the current branch
|
# Keep this test last, as it changes the current branch
|
||||||
cat >expect <<EOF
|
cat >expect <<EOF
|
||||||
0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
|
$_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
|
||||||
EOF
|
EOF
|
||||||
test_expect_success \
|
test_expect_success \
|
||||||
'git checkout -b g/h/i -l should create a branch and a log' \
|
'git checkout -b g/h/i -l should create a branch and a log' \
|
||||||
|
@ -240,11 +240,10 @@ test_expect_success 'refresh index before checking if it is up-to-date' '
|
|||||||
|
|
||||||
test_expect_success 'choking "git rm" should not let it die with cruft' '
|
test_expect_success 'choking "git rm" should not let it die with cruft' '
|
||||||
git reset -q --hard &&
|
git reset -q --hard &&
|
||||||
H=0000000000000000000000000000000000000000 &&
|
|
||||||
i=0 &&
|
i=0 &&
|
||||||
while test $i -lt 12000
|
while test $i -lt 12000
|
||||||
do
|
do
|
||||||
echo "100644 $H 0 some-file-$i"
|
echo "100644 $_z40 0 some-file-$i"
|
||||||
i=$(( $i + 1 ))
|
i=$(( $i + 1 ))
|
||||||
done | git update-index --index-info &&
|
done | git update-index --index-info &&
|
||||||
git rm -n "some-file-*" | :;
|
git rm -n "some-file-*" | :;
|
||||||
|
@ -126,15 +126,12 @@ cat >.test-recursive-AB <<\EOF
|
|||||||
:100644 100644 3fdbe17fd013303a2e981e1ca1c6cd6e72789087 7e09d6a3a14bd630913e8c75693cea32157b606d M Z/NM
|
:100644 100644 3fdbe17fd013303a2e981e1ca1c6cd6e72789087 7e09d6a3a14bd630913e8c75693cea32157b606d M Z/NM
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
|
|
||||||
x40="$x40$x40$x40$x40$x40$x40$x40$x40"
|
|
||||||
z40='0000000000000000000000000000000000000000'
|
|
||||||
cmp_diff_files_output () {
|
cmp_diff_files_output () {
|
||||||
# diff-files never reports additions. Also it does not fill in the
|
# diff-files never reports additions. Also it does not fill in the
|
||||||
# object ID for the changed files because it wants you to look at the
|
# object ID for the changed files because it wants you to look at the
|
||||||
# filesystem.
|
# filesystem.
|
||||||
sed <"$2" >.test-tmp \
|
sed <"$2" >.test-tmp \
|
||||||
-e '/^:000000 /d;s/'$x40'\( [MCRNDU][0-9]*\) /'$z40'\1 /' &&
|
-e '/^:000000 /d;s/'$_x40'\( [MCRNDU][0-9]*\) /'$_z40'\1 /' &&
|
||||||
test_cmp "$1" .test-tmp
|
test_cmp "$1" .test-tmp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,8 +4,6 @@ test_description='external diff interface test'
|
|||||||
|
|
||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
|
|
||||||
_z40=0000000000000000000000000000000000000000
|
|
||||||
|
|
||||||
test_expect_success setup '
|
test_expect_success setup '
|
||||||
|
|
||||||
test_tick &&
|
test_tick &&
|
||||||
|
@ -5,7 +5,6 @@ test_description='difference in submodules'
|
|||||||
. ./test-lib.sh
|
. ./test-lib.sh
|
||||||
. "$TEST_DIRECTORY"/diff-lib.sh
|
. "$TEST_DIRECTORY"/diff-lib.sh
|
||||||
|
|
||||||
_z40=0000000000000000000000000000000000000000
|
|
||||||
test_expect_success setup '
|
test_expect_success setup '
|
||||||
test_tick &&
|
test_tick &&
|
||||||
test_create_repo sub &&
|
test_create_repo sub &&
|
||||||
|
87
t/t4046-diff-unmerged.sh
Executable file
87
t/t4046-diff-unmerged.sh
Executable file
@ -0,0 +1,87 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
test_description='diff with unmerged index entries'
|
||||||
|
. ./test-lib.sh
|
||||||
|
|
||||||
|
test_expect_success setup '
|
||||||
|
for i in 0 1 2 3
|
||||||
|
do
|
||||||
|
blob=$(echo $i | git hash-object --stdin) &&
|
||||||
|
eval "blob$i=$blob" &&
|
||||||
|
eval "m$i=\"100644 \$blob$i $i\"" || break
|
||||||
|
done &&
|
||||||
|
paths= &&
|
||||||
|
for b in o x
|
||||||
|
do
|
||||||
|
for o in o x
|
||||||
|
do
|
||||||
|
for t in o x
|
||||||
|
do
|
||||||
|
path="$b$o$t" &&
|
||||||
|
case "$path" in ooo) continue ;; esac
|
||||||
|
paths="$paths$path " &&
|
||||||
|
p=" $path" &&
|
||||||
|
case "$b" in x) echo "$m1$p" ;; esac &&
|
||||||
|
case "$o" in x) echo "$m2$p" ;; esac &&
|
||||||
|
case "$t" in x) echo "$m3$p" ;; esac ||
|
||||||
|
break
|
||||||
|
done || break
|
||||||
|
done || break
|
||||||
|
done >ls-files-s.expect &&
|
||||||
|
git update-index --index-info <ls-files-s.expect &&
|
||||||
|
git ls-files -s >ls-files-s.actual &&
|
||||||
|
test_cmp ls-files-s.expect ls-files-s.actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'diff-files -0' '
|
||||||
|
for path in $paths
|
||||||
|
do
|
||||||
|
>"$path" &&
|
||||||
|
echo ":000000 100644 $_z40 $_z40 U $path"
|
||||||
|
done >diff-files-0.expect &&
|
||||||
|
git diff-files -0 >diff-files-0.actual &&
|
||||||
|
test_cmp diff-files-0.expect diff-files-0.actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'diff-files -1' '
|
||||||
|
for path in $paths
|
||||||
|
do
|
||||||
|
>"$path" &&
|
||||||
|
echo ":000000 100644 $_z40 $_z40 U $path" &&
|
||||||
|
case "$path" in
|
||||||
|
x??) echo ":100644 100644 $blob1 $_z40 M $path"
|
||||||
|
esac
|
||||||
|
done >diff-files-1.expect &&
|
||||||
|
git diff-files -1 >diff-files-1.actual &&
|
||||||
|
test_cmp diff-files-1.expect diff-files-1.actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'diff-files -2' '
|
||||||
|
for path in $paths
|
||||||
|
do
|
||||||
|
>"$path" &&
|
||||||
|
echo ":000000 100644 $_z40 $_z40 U $path" &&
|
||||||
|
case "$path" in
|
||||||
|
?x?) echo ":100644 100644 $blob2 $_z40 M $path"
|
||||||
|
esac
|
||||||
|
done >diff-files-2.expect &&
|
||||||
|
git diff-files -2 >diff-files-2.actual &&
|
||||||
|
test_cmp diff-files-2.expect diff-files-2.actual &&
|
||||||
|
git diff-files >diff-files-default-2.actual &&
|
||||||
|
test_cmp diff-files-2.expect diff-files-default-2.actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'diff-files -3' '
|
||||||
|
for path in $paths
|
||||||
|
do
|
||||||
|
>"$path" &&
|
||||||
|
echo ":000000 100644 $_z40 $_z40 U $path" &&
|
||||||
|
case "$path" in
|
||||||
|
??x) echo ":100644 100644 $blob3 $_z40 M $path"
|
||||||
|
esac
|
||||||
|
done >diff-files-3.expect &&
|
||||||
|
git diff-files -3 >diff-files-3.actual &&
|
||||||
|
test_cmp diff-files-3.expect diff-files-3.actual
|
||||||
|
'
|
||||||
|
|
||||||
|
test_done
|
@ -24,7 +24,7 @@ H sub/2
|
|||||||
EOF
|
EOF
|
||||||
|
|
||||||
NULL_SHA1=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
|
NULL_SHA1=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
|
||||||
ZERO_SHA0=0000000000000000000000000000000000000000
|
|
||||||
setup_absent() {
|
setup_absent() {
|
||||||
test -f 1 && rm 1
|
test -f 1 && rm 1
|
||||||
git update-index --remove 1 &&
|
git update-index --remove 1 &&
|
||||||
@ -120,7 +120,7 @@ test_expect_success 'grep with skip-worktree file' '
|
|||||||
test "$(git grep --no-ext-grep test)" = "1:test"
|
test "$(git grep --no-ext-grep test)" = "1:test"
|
||||||
'
|
'
|
||||||
|
|
||||||
echo ":000000 100644 $ZERO_SHA0 $NULL_SHA1 A 1" > expected
|
echo ":000000 100644 $_z40 $NULL_SHA1 A 1" > expected
|
||||||
test_expect_success 'diff-index does not examine skip-worktree absent entries' '
|
test_expect_success 'diff-index does not examine skip-worktree absent entries' '
|
||||||
setup_absent &&
|
setup_absent &&
|
||||||
git diff-index HEAD -- 1 > result &&
|
git diff-index HEAD -- 1 > result &&
|
||||||
|
@ -54,7 +54,7 @@ test_expect_success 'read-tree removes worktree, dirty case' '
|
|||||||
'
|
'
|
||||||
|
|
||||||
NULL_SHA1=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
|
NULL_SHA1=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
|
||||||
ZERO_SHA0=0000000000000000000000000000000000000000
|
|
||||||
setup_absent() {
|
setup_absent() {
|
||||||
test -f 1 && rm 1
|
test -f 1 && rm 1
|
||||||
git update-index --remove 1 &&
|
git update-index --remove 1 &&
|
||||||
|
@ -89,6 +89,9 @@ esac
|
|||||||
_x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
|
_x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
|
||||||
_x40="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
|
_x40="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05"
|
||||||
|
|
||||||
|
# Zero SHA-1
|
||||||
|
_z40=0000000000000000000000000000000000000000
|
||||||
|
|
||||||
# Each test should start with something like this, after copyright notices:
|
# Each test should start with something like this, after copyright notices:
|
||||||
#
|
#
|
||||||
# test_description='Description of this test...
|
# test_description='Description of this test...
|
||||||
|
Loading…
Reference in New Issue
Block a user