Skip to content

Commit 22dbeee

Browse files
committed
Merge branch 'jc/fix-diff-files-unmerged'
* 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
2 parents 6c252ef + 095ce95 commit 22dbeee

16 files changed

+120
-36
lines changed

diff-lib.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
112112

113113
if (ce_stage(ce)) {
114114
struct combine_diff_path *dpath;
115+
struct diff_filepair *pair;
116+
unsigned int wt_mode = 0;
115117
int num_compare_stages = 0;
116118
size_t path_len;
117119

@@ -130,15 +132,17 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
130132

131133
changed = check_removed(ce, &st);
132134
if (!changed)
133-
dpath->mode = ce_mode_from_stat(ce, st.st_mode);
135+
wt_mode = ce_mode_from_stat(ce, st.st_mode);
134136
else {
135137
if (changed < 0) {
136138
perror(ce->name);
137139
continue;
138140
}
139141
if (silent_on_removed)
140142
continue;
143+
wt_mode = 0;
141144
}
145+
dpath->mode = wt_mode;
142146

143147
while (i < entries) {
144148
struct cache_entry *nce = active_cache[i];
@@ -184,7 +188,9 @@ int run_diff_files(struct rev_info *revs, unsigned int option)
184188
* Show the diff for the 'ce' if we found the one
185189
* from the desired stage.
186190
*/
187-
diff_unmerge(&revs->diffopt, ce->name, 0, null_sha1);
191+
pair = diff_unmerge(&revs->diffopt, ce->name);
192+
if (wt_mode)
193+
pair->two->mode = wt_mode;
188194
if (ce_stage(ce) != diff_unmerged_stage)
189195
continue;
190196
}
@@ -373,8 +379,9 @@ static void do_oneway_diff(struct unpack_trees_options *o,
373379
match_missing = !revs->ignore_merges;
374380

375381
if (cached && idx && ce_stage(idx)) {
376-
diff_unmerge(&revs->diffopt, idx->name, idx->ce_mode,
377-
idx->sha1);
382+
struct diff_filepair *pair;
383+
pair = diff_unmerge(&revs->diffopt, idx->name);
384+
fill_filespec(pair->one, idx->sha1, idx->ce_mode);
378385
return;
379386
}
380387

diff.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4416,20 +4416,20 @@ void diff_change(struct diff_options *options,
44164416
DIFF_OPT_SET(options, HAS_CHANGES);
44174417
}
44184418

4419-
void diff_unmerge(struct diff_options *options,
4420-
const char *path,
4421-
unsigned mode, const unsigned char *sha1)
4419+
struct diff_filepair *diff_unmerge(struct diff_options *options, const char *path)
44224420
{
4421+
struct diff_filepair *pair;
44234422
struct diff_filespec *one, *two;
44244423

44254424
if (options->prefix &&
44264425
strncmp(path, options->prefix, options->prefix_length))
4427-
return;
4426+
return NULL;
44284427

44294428
one = alloc_filespec(path);
44304429
two = alloc_filespec(path);
4431-
fill_filespec(one, sha1, mode);
4432-
diff_queue(&diff_queued_diff, one, two)->is_unmerged = 1;
4430+
pair = diff_queue(&diff_queued_diff, one, two);
4431+
pair->is_unmerged = 1;
4432+
return pair;
44334433
}
44344434

44354435
static char *run_textconv(const char *pgm, struct diff_filespec *spec,

diff.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,7 @@ extern void diff_change(struct diff_options *,
210210
const char *fullpath,
211211
unsigned dirty_submodule1, unsigned dirty_submodule2);
212212

213-
extern void diff_unmerge(struct diff_options *,
214-
const char *path,
215-
unsigned mode,
216-
const unsigned char *sha1);
213+
extern struct diff_filepair *diff_unmerge(struct diff_options *, const char *path);
217214

218215
#define DIFF_SETUP_REVERSE 1
219216
#define DIFF_SETUP_USE_CACHE 2

t/t1400-update-ref.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
test_description='Test git update-ref and basic ref logging'
77
. ./test-lib.sh
88

9-
Z=0000000000000000000000000000000000000000
9+
Z=$_z40
1010

1111
test_expect_success setup '
1212

t/t1501-worktree.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ test_expect_success 'setup' '
77
EMPTY_TREE=$(git write-tree) &&
88
EMPTY_BLOB=$(git hash-object -t blob --stdin </dev/null) &&
99
CHANGED_BLOB=$(echo changed | git hash-object -t blob --stdin) &&
10-
ZEROES=0000000000000000000000000000000000000000 &&
1110
EMPTY_BLOB7=$(echo $EMPTY_BLOB | sed "s/\(.......\).*/\1/") &&
1211
CHANGED_BLOB7=$(echo $CHANGED_BLOB | sed "s/\(.......\).*/\1/") &&
1312
@@ -239,10 +238,10 @@ test_expect_success '_gently() groks relative GIT_DIR & GIT_WORK_TREE' '
239238

240239
test_expect_success 'diff-index respects work tree under .git dir' '
241240
cat >diff-index-cached.expected <<-EOF &&
242-
:000000 100644 $ZEROES $EMPTY_BLOB A sub/dir/tracked
241+
:000000 100644 $_z40 $EMPTY_BLOB A sub/dir/tracked
243242
EOF
244243
cat >diff-index.expected <<-EOF &&
245-
:000000 100644 $ZEROES $ZEROES A sub/dir/tracked
244+
:000000 100644 $_z40 $_z40 A sub/dir/tracked
246245
EOF
247246
248247
(
@@ -258,7 +257,7 @@ test_expect_success 'diff-index respects work tree under .git dir' '
258257

259258
test_expect_success 'diff-files respects work tree under .git dir' '
260259
cat >diff-files.expected <<-EOF &&
261-
:100644 100644 $EMPTY_BLOB $ZEROES M sub/dir/tracked
260+
:100644 100644 $EMPTY_BLOB $_z40 M sub/dir/tracked
262261
EOF
263262
264263
(

t/t2011-checkout-invalid-head.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ test_expect_success 'checkout should not start branch from a tree' '
1515
'
1616

1717
test_expect_success 'checkout master from invalid HEAD' '
18-
echo 0000000000000000000000000000000000000000 >.git/HEAD &&
18+
echo $_z40 >.git/HEAD &&
1919
git checkout master --
2020
'
2121

t/t2201-add-update-typechange.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ test_description='more git add -u'
44

55
. ./test-lib.sh
66

7-
_z40=0000000000000000000000000000000000000000
8-
97
test_expect_success setup '
108
>xyzzy &&
119
_empty=$(git hash-object --stdin <xyzzy) &&

t/t3200-branch.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ test_expect_success \
4646
'git branch a/b/c && test -f .git/refs/heads/a/b/c'
4747

4848
cat >expect <<EOF
49-
0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
49+
$_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
5050
EOF
5151
test_expect_success \
5252
'git branch -l d/e/f should create a branch and a log' \
@@ -232,7 +232,7 @@ test_expect_success \
232232

233233
# Keep this test last, as it changes the current branch
234234
cat >expect <<EOF
235-
0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
235+
$_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master
236236
EOF
237237
test_expect_success \
238238
'git checkout -b g/h/i -l should create a branch and a log' \

t/t3600-rm.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,11 +240,10 @@ test_expect_success 'refresh index before checking if it is up-to-date' '
240240

241241
test_expect_success 'choking "git rm" should not let it die with cruft' '
242242
git reset -q --hard &&
243-
H=0000000000000000000000000000000000000000 &&
244243
i=0 &&
245244
while test $i -lt 12000
246245
do
247-
echo "100644 $H 0 some-file-$i"
246+
echo "100644 $_z40 0 some-file-$i"
248247
i=$(( $i + 1 ))
249248
done | git update-index --index-info &&
250249
git rm -n "some-file-*" | :;

t/t4002-diff-basic.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,15 +126,12 @@ cat >.test-recursive-AB <<\EOF
126126
:100644 100644 3fdbe17fd013303a2e981e1ca1c6cd6e72789087 7e09d6a3a14bd630913e8c75693cea32157b606d M Z/NM
127127
EOF
128128

129-
x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
130-
x40="$x40$x40$x40$x40$x40$x40$x40$x40"
131-
z40='0000000000000000000000000000000000000000'
132129
cmp_diff_files_output () {
133130
# diff-files never reports additions. Also it does not fill in the
134131
# object ID for the changed files because it wants you to look at the
135132
# filesystem.
136133
sed <"$2" >.test-tmp \
137-
-e '/^:000000 /d;s/'$x40'\( [MCRNDU][0-9]*\) /'$z40'\1 /' &&
134+
-e '/^:000000 /d;s/'$_x40'\( [MCRNDU][0-9]*\) /'$_z40'\1 /' &&
138135
test_cmp "$1" .test-tmp
139136
}
140137

0 commit comments

Comments
 (0)