Skip to content

Commit e7baa4f

Browse files
author
Junio C Hamano
committed
Use symbolic constants for diff-raw status indicators.
Both Cogito and StGIT prefer to see 'A' for new files. The current 'N' is visually harder to distinguish from 'M', which is used for modified files. Prepare the internals to use symbolic constants to make the change easier. Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 30b0535 commit e7baa4f

File tree

3 files changed

+51
-26
lines changed

3 files changed

+51
-26
lines changed

diff-helper.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ int main(int ac, const char **av) {
9494
if (!strchr("MCRNDU", status))
9595
break;
9696
two_paths = score = 0;
97-
if (status == 'R' || status == 'C')
97+
if (status == DIFF_STATUS_RENAMED ||
98+
status == DIFF_STATUS_COPIED)
9899
two_paths = 1;
99100

100101
/* pick up score if exists */

diff.c

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ static void run_diff(struct diff_filepair *p)
617617
other = (strcmp(name, p->two->path) ? p->two->path : NULL);
618618
one = p->one; two = p->two;
619619
switch (p->status) {
620-
case 'C':
620+
case DIFF_STATUS_COPIED:
621621
sprintf(msg_,
622622
"similarity index %d%%\n"
623623
"copy from %s\n"
@@ -626,7 +626,7 @@ static void run_diff(struct diff_filepair *p)
626626
name, other);
627627
xfrm_msg = msg_;
628628
break;
629-
case 'R':
629+
case DIFF_STATUS_RENAMED:
630630
sprintf(msg_,
631631
"similarity index %d%%\n"
632632
"rename from %s\n"
@@ -635,7 +635,7 @@ static void run_diff(struct diff_filepair *p)
635635
name, other);
636636
xfrm_msg = msg_;
637637
break;
638-
case 'M':
638+
case DIFF_STATUS_MODIFIED:
639639
if (p->score) {
640640
sprintf(msg_,
641641
"dissimilarity index %d%%",
@@ -796,10 +796,12 @@ static void diff_flush_raw(struct diff_filepair *p,
796796
status[1] = 0;
797797
}
798798
switch (p->status) {
799-
case 'C': case 'R':
799+
case DIFF_STATUS_COPIED:
800+
case DIFF_STATUS_RENAMED:
800801
two_paths = 1;
801802
break;
802-
case 'N': case 'D':
803+
case DIFF_STATUS_ADDED:
804+
case DIFF_STATUS_DELETED:
803805
two_paths = 0;
804806
break;
805807
default:
@@ -928,21 +930,21 @@ static void diff_resolve_rename_copy(void)
928930
p = q->queue[i];
929931
p->status = 0; /* undecided */
930932
if (DIFF_PAIR_UNMERGED(p))
931-
p->status = 'U';
933+
p->status = DIFF_STATUS_UNMERGED;
932934
else if (!DIFF_FILE_VALID(p->one))
933-
p->status = 'N';
935+
p->status = DIFF_STATUS_ADDED;
934936
else if (!DIFF_FILE_VALID(p->two))
935-
p->status = 'D';
937+
p->status = DIFF_STATUS_DELETED;
936938
else if (DIFF_PAIR_TYPE_CHANGED(p))
937-
p->status = 'T';
939+
p->status = DIFF_STATUS_TYPE_CHANGED;
938940

939941
/* from this point on, we are dealing with a pair
940942
* whose both sides are valid and of the same type, i.e.
941943
* either in-place edit or rename/copy edit.
942944
*/
943945
else if (DIFF_PAIR_RENAME(p)) {
944946
if (p->source_stays) {
945-
p->status = 'C';
947+
p->status = DIFF_STATUS_COPIED;
946948
continue;
947949
}
948950
/* See if there is some other filepair that
@@ -956,22 +958,22 @@ static void diff_resolve_rename_copy(void)
956958
if (!DIFF_PAIR_RENAME(pp))
957959
continue; /* not a rename/copy */
958960
/* pp is a rename/copy from the same source */
959-
p->status = 'C';
961+
p->status = DIFF_STATUS_COPIED;
960962
break;
961963
}
962964
if (!p->status)
963-
p->status = 'R';
965+
p->status = DIFF_STATUS_RENAMED;
964966
}
965967
else if (memcmp(p->one->sha1, p->two->sha1, 20) ||
966968
p->one->mode != p->two->mode)
967-
p->status = 'M';
969+
p->status = DIFF_STATUS_MODIFIED;
968970
else {
969971
/* This is a "no-change" entry and should not
970972
* happen anymore, but prepare for broken callers.
971973
*/
972974
error("feeding unmodified %s to diffcore",
973975
p->one->path);
974-
p->status = 'X';
976+
p->status = DIFF_STATUS_UNKNOWN;
975977
}
976978
}
977979
diff_debug_queue("resolve-rename-copy done", q);
@@ -989,7 +991,7 @@ void diff_flush(int diff_output_style, int line_termination)
989991
for (i = 0; i < q->nr; i++) {
990992
struct diff_filepair *p = q->queue[i];
991993
if ((diff_output_style == DIFF_FORMAT_NO_OUTPUT) ||
992-
(p->status == 'X'))
994+
(p->status == DIFF_STATUS_UNKNOWN))
993995
continue;
994996
if (p->status == 0)
995997
die("internal error in diff-resolve-rename-copy");
@@ -1024,15 +1026,17 @@ static void diffcore_apply_filter(const char *filter)
10241026
if (!filter)
10251027
return;
10261028

1027-
if (strchr(filter, 'A')) {
1028-
/* All-or-none */
1029+
if (strchr(filter, DIFF_STATUS_FILTER_AON)) {
10291030
int found;
10301031
for (i = found = 0; !found && i < q->nr; i++) {
10311032
struct diff_filepair *p = q->queue[i];
1032-
if (((p->status == 'M') &&
1033-
((p->score && strchr(filter, 'B')) ||
1034-
(!p->score && strchr(filter, 'M')))) ||
1035-
((p->status != 'M') && strchr(filter, p->status)))
1033+
if (((p->status == DIFF_STATUS_MODIFIED) &&
1034+
((p->score &&
1035+
strchr(filter, DIFF_STATUS_FILTER_BROKEN)) ||
1036+
(!p->score &&
1037+
strchr(filter, DIFF_STATUS_MODIFIED)))) ||
1038+
((p->status != DIFF_STATUS_MODIFIED) &&
1039+
strchr(filter, p->status)))
10361040
found++;
10371041
}
10381042
if (found)
@@ -1050,10 +1054,14 @@ static void diffcore_apply_filter(const char *filter)
10501054
/* Only the matching ones */
10511055
for (i = 0; i < q->nr; i++) {
10521056
struct diff_filepair *p = q->queue[i];
1053-
if (((p->status == 'M') &&
1054-
((p->score && strchr(filter, 'B')) ||
1055-
(!p->score && strchr(filter, 'M')))) ||
1056-
((p->status != 'M') && strchr(filter, p->status)))
1057+
1058+
if (((p->status == DIFF_STATUS_MODIFIED) &&
1059+
((p->score &&
1060+
strchr(filter, DIFF_STATUS_FILTER_BROKEN)) ||
1061+
(!p->score &&
1062+
strchr(filter, DIFF_STATUS_MODIFIED)))) ||
1063+
((p->status != DIFF_STATUS_MODIFIED) &&
1064+
strchr(filter, p->status)))
10571065
diff_q(&outq, p);
10581066
else
10591067
diff_free_filepair(p);

diff.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,20 @@ extern int diff_queue_is_empty(void);
8282

8383
extern void diff_flush(int output_style, int line_terminator);
8484

85+
/* diff-raw status letters */
86+
#define DIFF_STATUS_ADDED 'N'
87+
#define DIFF_STATUS_COPIED 'C'
88+
#define DIFF_STATUS_DELETED 'D'
89+
#define DIFF_STATUS_MODIFIED 'M'
90+
#define DIFF_STATUS_RENAMED 'R'
91+
#define DIFF_STATUS_TYPE_CHANGED 'T'
92+
#define DIFF_STATUS_UNKNOWN 'X'
93+
#define DIFF_STATUS_UNMERGED 'U'
94+
95+
/* these are not diff-raw status letters proper, but used by
96+
* diffcore-filter insn to specify additional restrictions.
97+
*/
98+
#define DIFF_STATUS_FILTER_AON 'A'
99+
#define DIFF_STATUS_FILTER_BROKEN 'B'
100+
85101
#endif /* DIFF_H */

0 commit comments

Comments
 (0)