Skip to content

Commit 01c4e70

Browse files
Junio C HamanoLinus Torvalds
authored andcommitted
[PATCH] diff: code clean-up and removal of rename hack.
A new macro, DIFF_PAIR_RENAME(), is introduced to distinguish a filepair that is a rename/copy (the definition of which is src and dst are different paths, of course). This removes the hack used in the record_rename_pair() to always put a non-zero value in the score field. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent befe863 commit 01c4e70

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

diff.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ static void diff_resolve_rename_copy(void)
796796
for (j = 0; j < q->nr; j++) {
797797
pp = q->queue[j];
798798
if (!strcmp(p->one->path, pp->one->path) &&
799-
pp->score) {
799+
DIFF_PAIR_RENAME(pp)) {
800800
/* rename/copy are always valid
801801
* so we do not say DIFF_FILE_VALID()
802802
* on pp->one and pp->two.
@@ -815,7 +815,7 @@ static void diff_resolve_rename_copy(void)
815815
* whose both sides are valid and of the same type, i.e.
816816
* either in-place edit or rename/copy edit.
817817
*/
818-
else if (p->score) {
818+
else if (DIFF_PAIR_RENAME(p)) {
819819
if (p->source_stays) {
820820
p->status = 'C';
821821
continue;
@@ -828,7 +828,7 @@ static void diff_resolve_rename_copy(void)
828828
pp = q->queue[j];
829829
if (strcmp(pp->one->path, p->one->path))
830830
continue; /* not us */
831-
if (!pp->score)
831+
if (!DIFF_PAIR_RENAME(pp))
832832
continue; /* not a rename/copy */
833833
/* pp is a rename/copy from the same source */
834834
p->status = 'C';

diffcore-rename.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static void record_rename_pair(struct diff_queue_struct *renq,
207207
fill_filespec(two, dst->sha1, dst->mode);
208208

209209
dp = diff_queue(renq, one, two);
210-
dp->score = score ? : 1; /* make sure it is at least 1 */
210+
dp->score = score;
211211
dp->source_stays = rename_src[src_index].src_stays;
212212
rename_dst[dst_index].pair = dp;
213213
}

diffcore.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ extern void diff_free_filespec_data(struct diff_filespec *);
3939
struct diff_filepair {
4040
struct diff_filespec *one;
4141
struct diff_filespec *two;
42-
unsigned short int score; /* only valid when one and two are
43-
* different paths
44-
*/
42+
unsigned short int score;
4543
char source_stays; /* all of R/C are copies */
4644
char status; /* M C R N D U (see Documentation/diff-format.txt) */
4745
};
4846
#define DIFF_PAIR_UNMERGED(p) \
4947
(!DIFF_FILE_VALID((p)->one) && !DIFF_FILE_VALID((p)->two))
5048

49+
#define DIFF_PAIR_RENAME(p) (strcmp((p)->one->path, (p)->two->path))
50+
5151
#define DIFF_PAIR_TYPE_CHANGED(p) \
5252
((S_IFMT & (p)->one->mode) != (S_IFMT & (p)->two->mode))
5353

0 commit comments

Comments
 (0)