pack-objects: hash basename and direname a bit differently.
...so that "Makefile"s from different revs are sorted together, separate from "t/Makefile"s, but close enough. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Feb 23, 2006 at 23:27 UTC
eeef7135fed9b8784627c4c96e125241c06c65e1
1 file changed
+32
-1
pack-objects.c
+32
-1
@@ -445,18 +445,29 @@ struct name_path {
445
int len;
446
};
447
448
+#define DIRBITS 12
449
+
450
static unsigned name_hash(struct name_path *path, const char *name)
451
{
452
struct name_path *p = path;
453
const char *n = name + strlen(name);
452
- unsigned hash = 0;
454
+ unsigned hash = 0, name_hash = 0, name_done = 0;
455
456
if (n != name && n[-1] == '\n')
457
n--;
458
while (name <= --n) {
459
unsigned char c = *n;
460
+ if (c == '/' && !name_done) {
461
+ name_hash = hash;
462
+ name_done = 1;
463
+ hash = 0;
464
+ }
465
hash = hash * 11 + c;
466
}
467
+ if (!name_done) {
468
+ name_hash = hash;
469
+ hash = 0;
470
+ }
471
for (p = path; p; p = p->up) {
472
hash = hash * 11 + '/';
473
n = p->elem + p->len;
@@ -465,6 +476,26 @@ static unsigned name_hash(struct name_path *path, const char *name)
476
hash = hash * 11 + c;
477
}
478
}
479
+ /*
480
+ * Make sure "Makefile" and "t/Makefile" are hashed separately
481
+ * but close enough.
482
+ */
483
+ hash = (name_hash<<DIRBITS) | (hash & ((1U<<DIRBITS )-1));
484
+
485
+ if (0) { /* debug */
486
+ n = name + strlen(name);
487
+ if (n != name && n[-1] == '\n')
488
+ n--;
489
+ while (name <= --n)
490
+ fputc(*n, stderr);
491
+ for (p = path; p; p = p->up) {
492
+ fputc('/', stderr);
493
+ n = p->elem + p->len;
494
+ while (p->elem <= --n)
495
+ fputc(*n, stderr);
496
+ }
497
+ fprintf(stderr, "\t%08x\n", hash);
498
+ }
499
return hash;
500
}
501