From: Yann Dirson <ydirson@altern.org>
To: git@vger.kernel.org
Cc: Yann Dirson <ydirson@altern.org>
Subject: [PATCH 2/6] Convert diffcore-rename's rename_dst to the new sorted-array API.
Date: Wed, 8 Dec 2010 23:51:31 +0100 [thread overview]
Message-ID: <1291848695-24601-3-git-send-email-ydirson@altern.org> (raw)
In-Reply-To: <1291848695-24601-1-git-send-email-ydirson@altern.org>
The sorted-array API splits search and insert into two separated
functions, which makes the caller code more clear.
Signed-off-by: Yann Dirson <ydirson@altern.org>
---
diffcore-rename.c | 62 ++++++++++++++++++-----------------------------------
1 files changed, 21 insertions(+), 41 deletions(-)
diff --git a/diffcore-rename.c b/diffcore-rename.c
index df41be5..ca3f54c 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -5,52 +5,32 @@
#include "diff.h"
#include "diffcore.h"
#include "hash.h"
+#include "sorted-array.h"
/* Table of rename/copy destinations */
-static struct diff_rename_dst {
+struct diff_rename_dst {
struct diff_filespec *two;
struct diff_filepair *pair;
-} *rename_dst;
-static int rename_dst_nr, rename_dst_alloc;
+};
-static struct diff_rename_dst *locate_rename_dst(struct diff_filespec *two,
- int insert_ok)
+static int rename_dst_cmp(struct diff_filespec *ref_spec, struct diff_rename_dst *elem)
{
- int first, last;
-
- first = 0;
- last = rename_dst_nr;
- while (last > first) {
- int next = (last + first) >> 1;
- struct diff_rename_dst *dst = &(rename_dst[next]);
- int cmp = strcmp(two->path, dst->two->path);
- if (!cmp)
- return dst;
- if (cmp < 0) {
- last = next;
- continue;
- }
- first = next+1;
- }
- /* not found */
- if (!insert_ok)
- return NULL;
- /* insert to make it at "first" */
- if (rename_dst_alloc <= rename_dst_nr) {
- rename_dst_alloc = alloc_nr(rename_dst_alloc);
- rename_dst = xrealloc(rename_dst,
- rename_dst_alloc * sizeof(*rename_dst));
- }
- rename_dst_nr++;
- if (first < rename_dst_nr)
- memmove(rename_dst + first + 1, rename_dst + first,
- (rename_dst_nr - first - 1) * sizeof(*rename_dst));
- rename_dst[first].two = alloc_filespec(two->path);
- fill_filespec(rename_dst[first].two, two->sha1, two->mode);
- rename_dst[first].pair = NULL;
- return &(rename_dst[first]);
+ return strcmp(ref_spec->path, elem->two->path);
+}
+static void rename_dst_init(struct diff_rename_dst *elem, struct diff_filespec *ref_spec)
+{
+ elem->two = alloc_filespec(ref_spec->path);
+ fill_filespec(elem->two, ref_spec->sha1, ref_spec->mode);
+ elem->pair = NULL;
}
+declare_sorted_array(static, struct diff_rename_dst, rename_dst);
+declare_sorted_array_search_elem(static, struct diff_rename_dst, locate_rename_dst,
+ struct diff_filespec *,
+ rename_dst, rename_dst_cmp);
+declare_sorted_array_insert_checkbool(static, struct diff_rename_dst, register_rename_dst,
+ struct diff_filespec *, _gen_locate_rename_dst,
+ rename_dst, rename_dst_cmp, rename_dst_init);
/* Table of rename/copy src files */
static struct diff_rename_src {
@@ -437,7 +417,7 @@ void diffcore_rename(struct diff_options *options)
strcmp(options->single_follow, p->two->path))
continue; /* not interested */
else
- locate_rename_dst(p->two, 1);
+ register_rename_dst(p->two);
}
else if (!DIFF_FILE_VALID(p->two)) {
/*
@@ -582,7 +562,7 @@ void diffcore_rename(struct diff_options *options)
* not been turned into a rename/copy already.
*/
struct diff_rename_dst *dst =
- locate_rename_dst(p->two, 0);
+ locate_rename_dst(p->two);
if (dst && dst->pair) {
diff_q(&outq, dst->pair);
pair_to_free = p;
@@ -613,7 +593,7 @@ void diffcore_rename(struct diff_options *options)
if (DIFF_PAIR_BROKEN(p)) {
/* broken delete */
struct diff_rename_dst *dst =
- locate_rename_dst(p->one, 0);
+ locate_rename_dst(p->one);
if (dst && dst->pair)
/* counterpart is now rename/copy */
pair_to_free = p;
--
1.7.2.3
next prev parent reply other threads:[~2010-12-08 22:52 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-08 22:51 [PATCH v6] generalizing sorted-array handling Yann Dirson
2010-12-08 22:51 ` [PATCH 1/6] Introduce sorted-array binary-search function Yann Dirson
2010-12-10 22:29 ` Junio C Hamano
2010-12-30 0:40 ` Yann Dirson
2010-12-30 1:06 ` Erik Faye-Lund
2010-12-30 10:49 ` Yann Dirson
2010-12-08 22:51 ` Yann Dirson [this message]
2010-12-10 22:32 ` [PATCH 2/6] Convert diffcore-rename's rename_dst to the new sorted-array API Junio C Hamano
2010-12-08 22:51 ` [PATCH 3/6] Convert diffcore-rename's rename_src " Yann Dirson
2010-12-08 22:51 ` [PATCH 4/6] Convert pack-objects.c " Yann Dirson
2010-12-08 22:51 ` [PATCH 5/6] Use sorted-array API for commit.c's commit_graft Yann Dirson
2010-12-08 22:51 ` [PATCH 6/6] [RFC] subvert sorted-array to replace binary-search in unpack-objects Yann Dirson
2010-12-10 23:00 ` Junio C Hamano
2010-12-10 23:22 ` [PATCH v6] generalizing sorted-array handling Junio C Hamano
2010-12-30 0:01 ` Yann Dirson
-- strict thread matches above, loose matches on Subject: below --
2010-12-05 10:34 [PATCH v5] " Yann Dirson
2010-12-05 10:34 ` [PATCH 2/6] Convert diffcore-rename's rename_dst to the new sorted-array API Yann Dirson
2010-11-29 22:57 [PATCH v4] generalizing sorted-array handling Yann Dirson
2010-11-29 22:57 ` [PATCH 2/6] Convert diffcore-rename's rename_dst to the new sorted-array API Yann Dirson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1291848695-24601-3-git-send-email-ydirson@altern.org \
--to=ydirson@altern.org \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).