sha1_name.c: prepare to make get_tree_entry() reusable from others.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Apr 19, 2006 at 11:56 UTC
041a7308de3e6af36c5a6cc3412b542f42314f3f
1 file changed
+10
-9
sha1_name.c
+10
-9
@@ -450,18 +450,17 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1)
450
return get_short_sha1(name, len, sha1, 0);
451
}
452
453
-static int get_tree_entry(const unsigned char *, const char *, unsigned char *);
453
+static int get_tree_entry(const unsigned char *, const char *, unsigned char *, unsigned *);
454
455
-static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char *result)
455
+static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char *result, unsigned *mode)
456
{
457
int namelen = strlen(name);
458
while (t->size) {
459
const char *entry;
460
const unsigned char *sha1;
461
int entrylen, cmp;
462
- unsigned mode;
462
464
- sha1 = tree_entry_extract(t, &entry, &mode);
463
+ sha1 = tree_entry_extract(t, &entry, mode);
464
update_tree_entry(t);
465
entrylen = strlen(entry);
466
if (entrylen > namelen)
@@ -477,18 +476,18 @@ static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char
476
}
477
if (name[entrylen] != '/')
478
continue;
480
- if (!S_ISDIR(mode))
479
+ if (!S_ISDIR(*mode))
480
break;
481
if (++entrylen == namelen) {
482
memcpy(result, sha1, 20);
483
return 0;
484
}
486
- return get_tree_entry(sha1, name + entrylen, result);
485
+ return get_tree_entry(sha1, name + entrylen, result, mode);
486
}
487
return -1;
488
}
489
491
-static int get_tree_entry(const unsigned char *tree_sha1, const char *name, unsigned char *sha1)
490
+static int get_tree_entry(const unsigned char *tree_sha1, const char *name, unsigned char *sha1, unsigned *mode)
491
{
492
int retval;
493
void *tree;
@@ -498,7 +497,7 @@ static int get_tree_entry(const unsigned char *tree_sha1, const char *name, unsi
497
if (!tree)
498
return -1;
499
t.buf = tree;
501
- retval = find_tree_entry(&t, name, sha1);
500
+ retval = find_tree_entry(&t, name, sha1, mode);
501
free(tree);
502
return retval;
503
}
@@ -510,6 +509,7 @@ static int get_tree_entry(const unsigned char *tree_sha1, const char *name, unsi
509
int get_sha1(const char *name, unsigned char *sha1)
510
{
511
int ret;
512
+ unsigned unused;
513
514
prepare_alt_odb();
515
ret = get_sha1_1(name, strlen(name), sha1);
@@ -518,7 +518,8 @@ int get_sha1(const char *name, unsigned char *sha1)
518
if (cp) {
519
unsigned char tree_sha1[20];
520
if (!get_sha1_1(name, cp-name, tree_sha1))
521
- return get_tree_entry(tree_sha1, cp+1, sha1);
521
+ return get_tree_entry(tree_sha1, cp+1, sha1,
522
+ &unused);
523
}
524
}
525
return ret;