Converted hash memcpy/memcmp to new hashcpy/hashcmp/hashclr.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Aug 28, 2006 at 10:46 UTC
445b85999a309c8e5c7f928484c57325c280152e
1 file changed
+26
-26
fast-import.c
+26
-26
@@ -277,7 +277,7 @@ static struct object_entry* new_object(unsigned char *sha1)
277
alloc_objects(object_entry_alloc);
278
279
e = blocks->next_free++;
280
- memcpy(e->sha1, sha1, sizeof(e->sha1));
280
+ hashcpy(e->sha1, sha1);
281
return e;
282
}
283
@@ -286,7 +286,7 @@ static struct object_entry* find_object(unsigned char *sha1)
286
unsigned int h = sha1[0] << 8 | sha1[1];
287
struct object_entry *e;
288
for (e = object_table[h]; e; e = e->next)
289
- if (!memcmp(sha1, e->sha1, sizeof(e->sha1)))
289
+ if (!hashcmp(sha1, e->sha1))
290
return e;
291
return NULL;
292
}
@@ -298,7 +298,7 @@ static struct object_entry* insert_object(unsigned char *sha1)
298
struct object_entry *p = NULL;
299
300
while (e) {
301
- if (!memcmp(sha1, e->sha1, sizeof(e->sha1)))
301
+ if (!hashcmp(sha1, e->sha1))
302
return e;
303
p = e;
304
e = e->next;
@@ -616,7 +616,7 @@ static int store_object(
616
SHA1_Update(&c, dat, datlen);
617
SHA1_Final(sha1, &c);
618
if (sha1out)
619
- memcpy(sha1out, sha1, sizeof(sha1));
619
+ hashcpy(sha1out, sha1);
620
621
e = insert_object(sha1);
622
if (mark)
@@ -676,7 +676,7 @@ static int store_object(
676
free(last->data);
677
last->data = dat;
678
last->len = datlen;
679
- memcpy(last->sha1, sha1, sizeof(sha1));
679
+ hashcpy(last->sha1, sha1);
680
}
681
return 0;
682
}
@@ -826,7 +826,7 @@ static void load_tree(struct tree_entry *root)
826
const char *c;
827
828
root->tree = t = new_tree_content(8);
829
- if (!memcmp(root->sha1, null_sha1, 20))
829
+ if (is_null_sha1(root->sha1))
830
return;
831
832
myoe = find_object(root->sha1);
@@ -855,7 +855,7 @@ static void load_tree(struct tree_entry *root)
855
die("Corrupt mode in %s", sha1_to_hex(root->sha1));
856
e->name = to_atom(c, strlen(c));
857
c += e->name->str_len + 1;
858
- memcpy(e->sha1, c, sizeof(e->sha1));
858
+ hashcpy(e->sha1, c);
859
c += 20;
860
}
861
free(buf);
@@ -877,7 +877,7 @@ static void store_tree(struct tree_entry *root)
877
size_t maxlen;
878
char *buf, *c;
879
880
- if (memcmp(root->sha1, null_sha1, 20))
880
+ if (!is_null_sha1(root->sha1))
881
return;
882
883
maxlen = 0;
@@ -895,7 +895,7 @@ static void store_tree(struct tree_entry *root)
895
*c++ = ' ';
896
strcpy(c, e->name->str_dat);
897
c += e->name->str_len + 1;
898
- memcpy(c, e->sha1, 20);
898
+ hashcpy(c, e->sha1);
899
c += 20;
900
}
901
store_object(OBJ_TREE, buf, c - buf, NULL, root->sha1, 0);
@@ -923,15 +923,15 @@ static int tree_content_set(
923
e = t->entries[i];
924
if (e->name->str_len == n && !strncmp(p, e->name->str_dat, n)) {
925
if (!slash1) {
926
- if (e->mode == mode && !memcmp(e->sha1, sha1, 20))
926
+ if (e->mode == mode && !hashcmp(e->sha1, sha1))
927
return 0;
928
e->mode = mode;
929
- memcpy(e->sha1, sha1, 20);
929
+ hashcpy(e->sha1, sha1);
930
if (e->tree) {
931
release_tree_content_recursive(e->tree);
932
e->tree = NULL;
933
}
934
- memcpy(root->sha1, null_sha1, 20);
934
+ hashclr(root->sha1);
935
return 1;
936
}
937
if (!S_ISDIR(e->mode)) {
@@ -941,7 +941,7 @@ static int tree_content_set(
941
if (!e->tree)
942
load_tree(e);
943
if (tree_content_set(e, slash1 + 1, sha1, mode)) {
944
- memcpy(root->sha1, null_sha1, 20);
944
+ hashclr(root->sha1);
945
return 1;
946
}
947
return 0;
@@ -960,9 +960,9 @@ static int tree_content_set(
960
} else {
961
e->tree = NULL;
962
e->mode = mode;
963
- memcpy(e->sha1, sha1, 20);
963
+ hashcpy(e->sha1, sha1);
964
}
965
- memcpy(root->sha1, null_sha1, 20);
965
+ hashclr(root->sha1);
966
return 1;
967
}
968
@@ -989,7 +989,7 @@ static int tree_content_remove(struct tree_entry *root, const char *p)
989
if (tree_content_remove(e, slash1 + 1)) {
990
if (!e->tree->entry_count)
991
goto del_entry;
992
- memcpy(root->sha1, null_sha1, 20);
992
+ hashclr(root->sha1);
993
return 1;
994
}
995
return 0;
@@ -1002,7 +1002,7 @@ del_entry:
1002
t->entries[i-1] = t->entries[i];
1003
t->entry_count--;
1004
release_tree_entry(e);
1005
- memcpy(root->sha1, null_sha1, 20);
1005
+ hashclr(root->sha1);
1006
return 1;
1007
}
1008
@@ -1054,7 +1054,7 @@ static int oecmp (const void *_a, const void *_b)
1054
{
1055
struct object_entry *a = *((struct object_entry**)_a);
1056
struct object_entry *b = *((struct object_entry**)_b);
1057
- return memcmp(a->sha1, b->sha1, sizeof(a->sha1));
1057
+ return hashcmp(a->sha1, b->sha1);
1058
}
1059
1060
static void write_index(const char *idx_name)
@@ -1359,8 +1359,8 @@ static void cmd_from(struct branch *b)
1359
if (b == s)
1360
die("Can't create a branch from itself: %s", b->name);
1361
else if (s) {
1362
- memcpy(b->sha1, s->sha1, 20);
1363
- memcpy(b->branch_tree.sha1, s->branch_tree.sha1, 20);
1362
+ hashcpy(b->sha1, s->sha1);
1363
+ hashcpy(b->branch_tree.sha1, s->branch_tree.sha1);
1364
} else if (*from == ':') {
1365
unsigned long idnum = strtoul(from + 1, NULL, 10);
1366
struct object_entry *oe = find_mark(idnum);
@@ -1368,7 +1368,7 @@ static void cmd_from(struct branch *b)
1368
char *buf;
1369
if (oe->type != OBJ_COMMIT)
1370
die("Mark :%lu not a commit", idnum);
1371
- memcpy(b->sha1, oe->sha1, 20);
1371
+ hashcpy(b->sha1, oe->sha1);
1372
buf = unpack_entry(oe->offset, &size);
1373
if (!buf || size < 46)
1374
die("Not a valid commit: %s", from);
@@ -1377,8 +1377,8 @@ static void cmd_from(struct branch *b)
1377
die("The commit %s is corrupt", sha1_to_hex(b->sha1));
1378
free(buf);
1379
} else if (!get_sha1(from, b->sha1)) {
1380
- if (!memcmp(b->sha1, null_sha1, 20))
1381
- memcpy(b->branch_tree.sha1, null_sha1, 20);
1380
+ if (is_null_sha1(b->sha1))
1381
+ hashclr(b->branch_tree.sha1);
1382
else {
1383
unsigned long size;
1384
char *buf;
@@ -1467,7 +1467,7 @@ static void cmd_new_commit()
1467
: 2 * strlen(committer)));
1468
sp = body;
1469
sp += sprintf(sp, "tree %s\n", sha1_to_hex(b->branch_tree.sha1));
1470
- if (memcmp(b->sha1, null_sha1, 20))
1470
+ if (!is_null_sha1(b->sha1))
1471
sp += sprintf(sp, "parent %s\n", sha1_to_hex(b->sha1));
1472
if (author)
1473
sp += sprintf(sp, "%s\n", author);
@@ -1547,13 +1547,13 @@ static void cmd_new_tag()
1547
1548
s = lookup_branch(from);
1549
if (s) {
1550
- memcpy(sha1, s->sha1, 20);
1550
+ hashcpy(sha1, s->sha1);
1551
} else if (*from == ':') {
1552
from_mark = strtoul(from + 1, NULL, 10);
1553
struct object_entry *oe = find_mark(from_mark);
1554
if (oe->type != OBJ_COMMIT)
1555
die("Mark :%lu not a commit", from_mark);
1556
- memcpy(sha1, oe->sha1, 20);
1556
+ hashcpy(sha1, oe->sha1);
1557
} else if (!get_sha1(from, sha1)) {
1558
unsigned long size;
1559
char *buf;