alloc_objects(object_entry_alloc);
e = blocks->next_free++;
- memcpy(e->sha1, sha1, sizeof(e->sha1));
+ hashcpy(e->sha1, sha1);
return e;
}
unsigned int h = sha1[0] << 8 | sha1[1];
struct object_entry *e;
for (e = object_table[h]; e; e = e->next)
- if (!memcmp(sha1, e->sha1, sizeof(e->sha1)))
+ if (!hashcmp(sha1, e->sha1))
return e;
return NULL;
}
struct object_entry *p = NULL;
while (e) {
- if (!memcmp(sha1, e->sha1, sizeof(e->sha1)))
+ if (!hashcmp(sha1, e->sha1))
return e;
p = e;
e = e->next;
SHA1_Update(&c, dat, datlen);
SHA1_Final(sha1, &c);
if (sha1out)
- memcpy(sha1out, sha1, sizeof(sha1));
+ hashcpy(sha1out, sha1);
e = insert_object(sha1);
if (mark)
free(last->data);
last->data = dat;
last->len = datlen;
- memcpy(last->sha1, sha1, sizeof(sha1));
+ hashcpy(last->sha1, sha1);
}
return 0;
}
const char *c;
root->tree = t = new_tree_content(8);
- if (!memcmp(root->sha1, null_sha1, 20))
+ if (is_null_sha1(root->sha1))
return;
myoe = find_object(root->sha1);
die("Corrupt mode in %s", sha1_to_hex(root->sha1));
e->name = to_atom(c, strlen(c));
c += e->name->str_len + 1;
- memcpy(e->sha1, c, sizeof(e->sha1));
+ hashcpy(e->sha1, c);
c += 20;
}
free(buf);
size_t maxlen;
char *buf, *c;
- if (memcmp(root->sha1, null_sha1, 20))
+ if (!is_null_sha1(root->sha1))
return;
maxlen = 0;
*c++ = ' ';
strcpy(c, e->name->str_dat);
c += e->name->str_len + 1;
- memcpy(c, e->sha1, 20);
+ hashcpy(c, e->sha1);
c += 20;
}
store_object(OBJ_TREE, buf, c - buf, NULL, root->sha1, 0);
e = t->entries[i];
if (e->name->str_len == n && !strncmp(p, e->name->str_dat, n)) {
if (!slash1) {
- if (e->mode == mode && !memcmp(e->sha1, sha1, 20))
+ if (e->mode == mode && !hashcmp(e->sha1, sha1))
return 0;
e->mode = mode;
- memcpy(e->sha1, sha1, 20);
+ hashcpy(e->sha1, sha1);
if (e->tree) {
release_tree_content_recursive(e->tree);
e->tree = NULL;
}
- memcpy(root->sha1, null_sha1, 20);
+ hashclr(root->sha1);
return 1;
}
if (!S_ISDIR(e->mode)) {
if (!e->tree)
load_tree(e);
if (tree_content_set(e, slash1 + 1, sha1, mode)) {
- memcpy(root->sha1, null_sha1, 20);
+ hashclr(root->sha1);
return 1;
}
return 0;
} else {
e->tree = NULL;
e->mode = mode;
- memcpy(e->sha1, sha1, 20);
+ hashcpy(e->sha1, sha1);
}
- memcpy(root->sha1, null_sha1, 20);
+ hashclr(root->sha1);
return 1;
}
if (tree_content_remove(e, slash1 + 1)) {
if (!e->tree->entry_count)
goto del_entry;
- memcpy(root->sha1, null_sha1, 20);
+ hashclr(root->sha1);
return 1;
}
return 0;
t->entries[i-1] = t->entries[i];
t->entry_count--;
release_tree_entry(e);
- memcpy(root->sha1, null_sha1, 20);
+ hashclr(root->sha1);
return 1;
}
{
struct object_entry *a = *((struct object_entry**)_a);
struct object_entry *b = *((struct object_entry**)_b);
- return memcmp(a->sha1, b->sha1, sizeof(a->sha1));
+ return hashcmp(a->sha1, b->sha1);
}
static void write_index(const char *idx_name)
if (b == s)
die("Can't create a branch from itself: %s", b->name);
else if (s) {
- memcpy(b->sha1, s->sha1, 20);
- memcpy(b->branch_tree.sha1, s->branch_tree.sha1, 20);
+ hashcpy(b->sha1, s->sha1);
+ hashcpy(b->branch_tree.sha1, s->branch_tree.sha1);
} else if (*from == ':') {
unsigned long idnum = strtoul(from + 1, NULL, 10);
struct object_entry *oe = find_mark(idnum);
char *buf;
if (oe->type != OBJ_COMMIT)
die("Mark :%lu not a commit", idnum);
- memcpy(b->sha1, oe->sha1, 20);
+ hashcpy(b->sha1, oe->sha1);
buf = unpack_entry(oe->offset, &size);
if (!buf || size < 46)
die("Not a valid commit: %s", from);
die("The commit %s is corrupt", sha1_to_hex(b->sha1));
free(buf);
} else if (!get_sha1(from, b->sha1)) {
- if (!memcmp(b->sha1, null_sha1, 20))
- memcpy(b->branch_tree.sha1, null_sha1, 20);
+ if (is_null_sha1(b->sha1))
+ hashclr(b->branch_tree.sha1);
else {
unsigned long size;
char *buf;
: 2 * strlen(committer)));
sp = body;
sp += sprintf(sp, "tree %s\n", sha1_to_hex(b->branch_tree.sha1));
- if (memcmp(b->sha1, null_sha1, 20))
+ if (!is_null_sha1(b->sha1))
sp += sprintf(sp, "parent %s\n", sha1_to_hex(b->sha1));
if (author)
sp += sprintf(sp, "%s\n", author);
s = lookup_branch(from);
if (s) {
- memcpy(sha1, s->sha1, 20);
+ hashcpy(sha1, s->sha1);
} else if (*from == ':') {
from_mark = strtoul(from + 1, NULL, 10);
struct object_entry *oe = find_mark(from_mark);
if (oe->type != OBJ_COMMIT)
die("Mark :%lu not a commit", from_mark);
- memcpy(sha1, oe->sha1, 20);
+ hashcpy(sha1, oe->sha1);
} else if (!get_sha1(from, sha1)) {
unsigned long size;
char *buf;