Skip to content

Commit e9c8409

Browse files
author
Junio C Hamano
committed
diff-index --cached --raw: show tree entry on the LHS for unmerged entries.
This updates the way diffcore represents an unmerged pair somewhat. It used to be that entries with mode=0 on both sides were used to represent an unmerged pair, but now it has an explicit flag. This is to allow diff-index --cached to report the entry from the tree when the path is unmerged in the index. This is used in updating "git reset <tree> -- <path>" to restore absense of the path in the index from the tree. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 13e86ef commit e9c8409

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

diff-lib.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ int run_diff_files(struct rev_info *revs, int silent_on_removed)
9797
* Show the diff for the 'ce' if we found the one
9898
* from the desired stage.
9999
*/
100-
diff_unmerge(&revs->diffopt, ce->name);
100+
diff_unmerge(&revs->diffopt, ce->name, 0, null_sha1);
101101
if (ce_stage(ce) != diff_unmerged_stage)
102102
continue;
103103
}
@@ -297,9 +297,12 @@ static int diff_cache(struct rev_info *revs,
297297
!show_modified(revs, ce, ac[1], 0,
298298
cached, match_missing))
299299
break;
300-
/* fallthru */
300+
diff_unmerge(&revs->diffopt, ce->name,
301+
ntohl(ce->ce_mode), ce->sha1);
302+
break;
301303
case 3:
302-
diff_unmerge(&revs->diffopt, ce->name);
304+
diff_unmerge(&revs->diffopt, ce->name,
305+
0, null_sha1);
303306
break;
304307

305308
default:

diff.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2875,10 +2875,12 @@ void diff_change(struct diff_options *options,
28752875
}
28762876

28772877
void diff_unmerge(struct diff_options *options,
2878-
const char *path)
2878+
const char *path,
2879+
unsigned mode, const unsigned char *sha1)
28792880
{
28802881
struct diff_filespec *one, *two;
28812882
one = alloc_filespec(path);
28822883
two = alloc_filespec(path);
2883-
diff_queue(&diff_queued_diff, one, two);
2884+
fill_filespec(one, sha1, mode);
2885+
diff_queue(&diff_queued_diff, one, two)->is_unmerged = 1;
28842886
}

diff.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ extern void diff_change(struct diff_options *,
144144
const char *base, const char *path);
145145

146146
extern void diff_unmerge(struct diff_options *,
147-
const char *path);
147+
const char *path,
148+
unsigned mode,
149+
const unsigned char *sha1);
148150

149151
extern int diff_scoreopt_parse(const char *opt);
150152

diffcore.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ struct diff_filepair {
5454
unsigned source_stays : 1; /* all of R/C are copies */
5555
unsigned broken_pair : 1;
5656
unsigned renamed_pair : 1;
57+
unsigned is_unmerged : 1;
5758
};
58-
#define DIFF_PAIR_UNMERGED(p) \
59-
(!DIFF_FILE_VALID((p)->one) && !DIFF_FILE_VALID((p)->two))
59+
#define DIFF_PAIR_UNMERGED(p) ((p)->is_unmerged)
6060

6161
#define DIFF_PAIR_RENAME(p) ((p)->renamed_pair)
6262

0 commit comments

Comments
 (0)