Skip to content

Commit e41b208

Browse files
committed
diffcore-rename.c: add locate_rename_src()
Just like rename destination table can be queried without adding a new entry, add locate_rename_src() that can be used for querying by splitting register_rename_src() into two (i.e. find existing one and optionally add new, and then adding information on the new entry). Signed-off-by: Junio C Hamano <[email protected]>
1 parent 24a9d25 commit e41b208

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

diffcore-rename.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,10 @@ static struct diff_rename_src {
6060
} *rename_src;
6161
static int rename_src_nr, rename_src_alloc;
6262

63-
static struct diff_rename_src *register_rename_src(struct diff_filepair *p)
63+
static struct diff_rename_src *locate_rename_src(struct diff_filespec *one,
64+
int insert_ok)
6465
{
6566
int first, last;
66-
struct diff_filespec *one = p->one;
67-
unsigned short score = p->score;
6867

6968
first = 0;
7069
last = rename_src_nr;
@@ -81,6 +80,9 @@ static struct diff_rename_src *register_rename_src(struct diff_filepair *p)
8180
first = next+1;
8281
}
8382

83+
if (!insert_ok)
84+
return NULL;
85+
8486
/* insert to make it at "first" */
8587
if (rename_src_alloc <= rename_src_nr) {
8688
rename_src_alloc = alloc_nr(rename_src_alloc);
@@ -91,11 +93,21 @@ static struct diff_rename_src *register_rename_src(struct diff_filepair *p)
9193
if (first < rename_src_nr)
9294
memmove(rename_src + first + 1, rename_src + first,
9395
(rename_src_nr - first - 1) * sizeof(*rename_src));
94-
rename_src[first].p = p;
95-
rename_src[first].score = score;
9696
return &(rename_src[first]);
9797
}
9898

99+
static struct diff_rename_src *register_rename_src(struct diff_filepair *p)
100+
{
101+
struct diff_filespec *one = p->one;
102+
struct diff_rename_src *src;
103+
104+
src = locate_rename_src(one, 1);
105+
106+
src->p = p;
107+
src->score = p->score;
108+
return src;
109+
}
110+
99111
static int basename_same(struct diff_filespec *src, struct diff_filespec *dst)
100112
{
101113
int src_len = strlen(src->path), dst_len = strlen(dst->path);

0 commit comments

Comments
 (0)