summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2015-02-15 12:28:12 -0800
committerJunio C Hamano <gitster@pobox.com>2015-02-23 14:55:55 -0800
commite41b208a87c75360d339fa094c0fbf01aa58a498 (patch)
treecf8ed9631f20eb5d775a03730a0e18be88484670
parent24a9d25fc45dbd76a8ef0c871179c5fc4dd4b373 (diff)
downloadgit-e41b208a87c75360d339fa094c0fbf01aa58a498.tar.gz
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 <gitster@pobox.com>
-rw-r--r--diffcore-rename.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 6c7a72fbe7..1d4f69e537 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -60,11 +60,10 @@ static struct diff_rename_src {
} *rename_src;
static int rename_src_nr, rename_src_alloc;
-static struct diff_rename_src *register_rename_src(struct diff_filepair *p)
+static struct diff_rename_src *locate_rename_src(struct diff_filespec *one,
+ int insert_ok)
{
int first, last;
- struct diff_filespec *one = p->one;
- unsigned short score = p->score;
first = 0;
last = rename_src_nr;
@@ -81,6 +80,9 @@ static struct diff_rename_src *register_rename_src(struct diff_filepair *p)
first = next+1;
}
+ if (!insert_ok)
+ return NULL;
+
/* insert to make it at "first" */
if (rename_src_alloc <= rename_src_nr) {
rename_src_alloc = alloc_nr(rename_src_alloc);
@@ -91,11 +93,21 @@ static struct diff_rename_src *register_rename_src(struct diff_filepair *p)
if (first < rename_src_nr)
memmove(rename_src + first + 1, rename_src + first,
(rename_src_nr - first - 1) * sizeof(*rename_src));
- rename_src[first].p = p;
- rename_src[first].score = score;
return &(rename_src[first]);
}
+static struct diff_rename_src *register_rename_src(struct diff_filepair *p)
+{
+ struct diff_filespec *one = p->one;
+ struct diff_rename_src *src;
+
+ src = locate_rename_src(one, 1);
+
+ src->p = p;
+ src->score = p->score;
+ return src;
+}
+
static int basename_same(struct diff_filespec *src, struct diff_filespec *dst)
{
int src_len = strlen(src->path), dst_len = strlen(dst->path);