@matheusbsbs / matheus-bagliano / commits / 0d981c67d8
Fork 0

git-pickaxe: cache one already found path per commit.

Depending on how bushy the commit DAG is, this saves calls to the internal diff-tree for fork-point commits. For example, annotating Makefile in the kernel repository saves about a third of such diff-tree calls. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Oct 31, 2006 at 01:00 UTC 0d981c67d8bcf4610e165744059c1e9e14609baa
1 file changed +20 -4
builtin-pickaxe.c
+20 -4
@@ -141,6 +141,8 @@ static int cmp_suspect(struct origin *a, struct origin *b)
141 return strcmp(a->path, b->path);
142 }
143
144 +#define cmp_suspect(a, b) ( ((a)==(b)) ? 0 : cmp_suspect(a,b) )
145 +
146 static void sanity_check_refcnt(struct scoreboard *);
147
148 static void coalesce(struct scoreboard *sb)
@@ -213,6 +215,12 @@ static struct origin *find_origin(struct scoreboard *sb,
215 struct diff_options diff_opts;
216 const char *paths[2];
217
218 + if (parent->util) {
219 + struct origin *cached = parent->util;
220 + if (!strcmp(cached->path, origin->path))
221 + return origin_incref(cached);
222 + }
223 +
224 /* See if the origin->path is different between parent
225 * and origin first. Most of the time they are the
226 * same and diff-tree is fairly efficient about this.
@@ -259,6 +267,12 @@ static struct origin *find_origin(struct scoreboard *sb,
267 }
268 }
269 diff_flush(&diff_opts);
270 + if (porigin) {
271 + origin_incref(porigin);
272 + if (parent->util)
273 + origin_decref(parent->util);
274 + parent->util = porigin;
275 + }
276 return porigin;
277 }
278
@@ -905,7 +919,7 @@ static void pass_blame(struct scoreboard *sb, struct origin *origin, int opt)
919 continue;
920 if (parse_commit(p))
921 continue;
908 - porigin = find(sb, parent->item, origin);
922 + porigin = find(sb, p, origin);
923 if (!porigin)
924 continue;
925 if (!hashcmp(porigin->blob_sha1, origin->blob_sha1)) {
@@ -1371,8 +1385,10 @@ static void sanity_check_refcnt(struct scoreboard *sb)
1385 ent->suspect->refcnt = -ent->suspect->refcnt;
1386 }
1387 for (ent = sb->ent; ent; ent = ent->next) {
1374 - /* then pick each and see if they have the the
1375 - * correct refcnt
1388 + /* then pick each and see if they have the the correct
1389 + * refcnt; note that ->util caching means origin's refcnt
1390 + * may well be greater than the number of blame entries
1391 + * that use it.
1392 */
1393 int found;
1394 struct blame_entry *e;
@@ -1386,7 +1402,7 @@ static void sanity_check_refcnt(struct scoreboard *sb)
1402 continue;
1403 found++;
1404 }
1389 - if (suspect->refcnt != found)
1405 + if (suspect->refcnt < found)
1406 baa = 1;
1407 }
1408 if (baa) {