summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b05faa2)
raw | patch | inline | side by side (parent: b05faa2)
author | Shawn Pearce <spearce@spearce.org> | |
Wed, 23 Aug 2006 06:49:00 +0000 (02:49 -0400) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Wed, 23 Aug 2006 20:53:10 +0000 (13:53 -0700) |
This abstracts away the size of the hash values when copying them
from memory location to memory location, much as the introduction
of hashcmp abstracted away hash value comparsion.
A few call sites were using char* rather than unsigned char* so
I added the cast rather than open hashcpy to be void*. This is a
reasonable tradeoff as most call sites already use unsigned char*
and the existing hashcmp is also declared to be unsigned char*.
[jc: Splitted the patch to "master" part, to be followed by a
patch for merge-recursive.c which is not in "master" yet.
Fixed the cast in the latter hunk to combine-diff.c which was
wrong in the original.
Also converted ones left-over in combine-diff.c, diff-lib.c and
upload-pack.c ]
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
from memory location to memory location, much as the introduction
of hashcmp abstracted away hash value comparsion.
A few call sites were using char* rather than unsigned char* so
I added the cast rather than open hashcpy to be void*. This is a
reasonable tradeoff as most call sites already use unsigned char*
and the existing hashcmp is also declared to be unsigned char*.
[jc: Splitted the patch to "master" part, to be followed by a
patch for merge-recursive.c which is not in "master" yet.
Fixed the cast in the latter hunk to combine-diff.c which was
wrong in the original.
Also converted ones left-over in combine-diff.c, diff-lib.c and
upload-pack.c ]
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
34 files changed:
index c253b9ca45cf7d860052ddae95bc1ed34974ffb8..5a8af726230611ff72de545bd013224895093a4b 100644 (file)
--- a/blame.c
+++ b/blame.c
if (i == 20)
return -1;
- memcpy(sha1, blob_sha1, 20);
+ hashcpy(sha1, blob_sha1);
return 0;
}
strcmp(blame_file + baselen, pathname))
return -1;
- memcpy(blob_sha1, sha1, 20);
+ hashcpy(blob_sha1, sha1);
return -1;
}
diff --git a/builtin-diff.c b/builtin-diff.c
index 874f773421620642425e67f650de2a34396f1c0f..a6590205e8f746304f3d06d3e328a05bf2bf954e 100644 (file)
--- a/builtin-diff.c
+++ b/builtin-diff.c
parent = xmalloc(ents * sizeof(*parent));
/* Again, the revs are all reverse */
for (i = 0; i < ents; i++)
- memcpy(parent + i, ent[ents - 1 - i].item->sha1, 20);
+ hashcpy((unsigned char*)parent + i, ent[ents - 1 - i].item->sha1);
diff_tree_combined(parent[0], parent + 1, ents - 1,
revs->dense_combined_merges, revs);
return 0;
if (obj->type == OBJ_BLOB) {
if (2 <= blobs)
die("more than two blobs given: '%s'", name);
- memcpy(blob[blobs].sha1, obj->sha1, 20);
+ hashcpy(blob[blobs].sha1, obj->sha1);
blob[blobs].name = name;
blobs++;
continue;
diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c
index f19f0d60460a721dafcd232d4896231f765a979f..46f524dfc32a5eaea06df6e3502c83710a1c09bb 100644 (file)
--- a/builtin-pack-objects.c
+++ b/builtin-pack-objects.c
@@ -534,7 +534,7 @@ static int add_object_entry(const unsigned char *sha1, unsigned hash, int exclud
entry = objects + idx;
nr_objects = idx + 1;
memset(entry, 0, sizeof(*entry));
- memcpy(entry->sha1, sha1, 20);
+ hashcpy(entry->sha1, sha1);
entry->hash = hash;
if (object_ix_hashsz * 3 <= nr_objects * 4)
free(ent->tree_data);
nent = ent;
}
- memcpy(nent->sha1, sha1, 20);
+ hashcpy(nent->sha1, sha1);
nent->tree_data = data;
nent->tree_size = size;
nent->ref = 1;
it->next = pbase_tree;
pbase_tree = it;
- memcpy(it->pcache.sha1, tree_sha1, 20);
+ hashcpy(it->pcache.sha1, tree_sha1);
it->pcache.tree_data = data;
it->pcache.tree_size = size;
}
diff --git a/builtin-read-tree.c b/builtin-read-tree.c
index 53087faf7a63e6268ffff5239142a00c120dcf8f..c1867d2a0052ad797481f3d5f9aa544952ff251b 100644 (file)
--- a/builtin-read-tree.c
+++ b/builtin-read-tree.c
struct name_entry entry;
int cnt;
- memcpy(it->sha1, tree->object.sha1, 20);
+ hashcpy(it->sha1, tree->object.sha1);
desc.buf = tree->buffer;
desc.size = tree->size;
cnt = 0;
index f0ae5c987af79bc5254df7cd3587ed1852e63209..ca0ebc258563f2ea2aec94eed2de31799f3f16cc 100644 (file)
--- a/builtin-unpack-objects.c
+++ b/builtin-unpack-objects.c
{
struct delta_info *info = xmalloc(sizeof(*info));
- memcpy(info->base_sha1, base_sha1, 20);
+ hashcpy(info->base_sha1, base_sha1);
info->size = size;
info->delta = delta;
info->next = delta_list;
unsigned char base_sha1[20];
int result;
- memcpy(base_sha1, fill(20), 20);
+ hashcpy(base_sha1, fill(20));
use(20);
delta_data = get_data(delta_size);
diff --git a/builtin-update-index.c b/builtin-update-index.c
index 5dd91af180df0f832ecc747050ad5306efe9c8b6..867512647195073860f017340ac1ebd0c27fce67 100644 (file)
--- a/builtin-update-index.c
+++ b/builtin-update-index.c
size = cache_entry_size(len);
ce = xcalloc(1, size);
- memcpy(ce->sha1, sha1, 20);
+ hashcpy(ce->sha1, sha1);
memcpy(ce->name, path, len);
ce->ce_flags = create_ce_flags(len, stage);
ce->ce_mode = create_ce_mode(mode);
size = cache_entry_size(namelen);
ce = xcalloc(1, size);
- memcpy(ce->sha1, sha1, 20);
+ hashcpy(ce->sha1, sha1);
memcpy(ce->name, path, namelen);
ce->ce_flags = create_ce_flags(namelen, stage);
ce->ce_mode = create_ce_mode(mode);
diff --git a/builtin-write-tree.c b/builtin-write-tree.c
index ca06149f186449407c6536fcc3caa37cd4101ce3..50670dc7bf46c74e95b2e204d05afc077350a19f 100644 (file)
--- a/builtin-write-tree.c
+++ b/builtin-write-tree.c
if (prefix) {
struct cache_tree *subtree =
cache_tree_find(active_cache_tree, prefix);
- memcpy(sha1, subtree->sha1, 20);
+ hashcpy(sha1, subtree->sha1);
}
else
- memcpy(sha1, active_cache_tree->sha1, 20);
+ hashcpy(sha1, active_cache_tree->sha1);
rollback_lock_file(lock_file);
diff --git a/cache-tree.c b/cache-tree.c
index d9f7e1e3dd598d34e08d6370544b562daf4640d2..323c68a6709f30312e0dfb0fd60fcd7e69cd710b 100644 (file)
--- a/cache-tree.c
+++ b/cache-tree.c
offset += sprintf(buffer + offset,
"%o %.*s", mode, entlen, path + baselen);
buffer[offset++] = 0;
- memcpy(buffer + offset, sha1, 20);
+ hashcpy((unsigned char*)buffer + offset, sha1);
offset += 20;
#if DEBUG
#endif
if (0 <= it->entry_count) {
- memcpy(buffer + *offset, it->sha1, 20);
+ hashcpy((unsigned char*)buffer + *offset, it->sha1);
*offset += 20;
}
for (i = 0; i < it->subtree_nr; i++) {
if (0 <= it->entry_count) {
if (size < 20)
goto free_return;
- memcpy(it->sha1, buf, 20);
+ hashcpy(it->sha1, (unsigned char*)buf);
buf += 20;
size -= 20;
}
index 08d6a91279c87ad1e4d7ce1be1ac927b52a6113e..cc3f00c2b8dd868bf9069140b8ed081f1c3e5220 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -218,6 +218,10 @@ static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
{
return memcmp(sha1, sha2, 20);
}
+static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)
+{
+ memcpy(sha_dst, sha_src, 20);
+}
int git_mkstemp(char *path, size_t n, const char *template);
diff --git a/combine-diff.c b/combine-diff.c
index 0682acd50d618e4ba8319372c46c72b3e479b8e6..46d9121baf2ebb024f6b19993a9b75fa3b67951a 100644 (file)
--- a/combine-diff.c
+++ b/combine-diff.c
memset(p->parent, 0,
sizeof(p->parent[0]) * num_parent);
- memcpy(p->sha1, q->queue[i]->two->sha1, 20);
+ hashcpy(p->sha1, q->queue[i]->two->sha1);
p->mode = q->queue[i]->two->mode;
- memcpy(p->parent[n].sha1, q->queue[i]->one->sha1, 20);
+ hashcpy(p->parent[n].sha1, q->queue[i]->one->sha1);
p->parent[n].mode = q->queue[i]->one->mode;
p->parent[n].status = q->queue[i]->status;
*tail = p;
len = strlen(path);
if (len == p->len && !memcmp(path, p->path, len)) {
found = 1;
- memcpy(p->parent[n].sha1,
- q->queue[i]->one->sha1, 20);
+ hashcpy(p->parent[n].sha1, q->queue[i]->one->sha1);
p->parent[n].mode = q->queue[i]->one->mode;
p->parent[n].status = q->queue[i]->status;
break;
for (parents = commit->parents, num_parent = 0;
parents;
parents = parents->next, num_parent++)
- memcpy(parent + num_parent, parents->item->object.sha1, 20);
+ hashcpy((unsigned char*)(parent + num_parent),
+ parents->item->object.sha1);
diff_tree_combined(sha1, parent, num_parent, dense, rev);
}
diff --git a/connect.c b/connect.c
index 7a6a73f2a333d067c5a5442004f76ebbb9aaed17..e501ccce259e7ac1a4e92fecc713950e82d3b71a 100644 (file)
--- a/connect.c
+++ b/connect.c
if (nr_match && !path_match(name, nr_match, match))
continue;
ref = xcalloc(1, sizeof(*ref) + len - 40);
- memcpy(ref->old_sha1, old_sha1, 20);
+ hashcpy(ref->old_sha1, old_sha1);
memcpy(ref->name, buffer + 41, len - 40);
*list = ref;
list = &ref->next;
len = strlen(name) + 1;
ref = xcalloc(1, sizeof(*ref) + len);
memcpy(ref->name, name, len);
- memcpy(ref->new_sha1, sha1, 20);
+ hashcpy(ref->new_sha1, sha1);
return ref;
}
int len = strlen(src->name) + 1;
dst_peer = xcalloc(1, sizeof(*dst_peer) + len);
memcpy(dst_peer->name, src->name, len);
- memcpy(dst_peer->new_sha1, src->new_sha1, 20);
+ hashcpy(dst_peer->new_sha1, src->new_sha1);
link_dst_tail(dst_peer, dst_tail);
}
dst_peer->peer_ref = src;
diff --git a/convert-objects.c b/convert-objects.c
index 4e7ff7517f40f5dd5c23cd3fd6a42d3cb621aec1..631678b08a7cb83b0349f1a683d3cd7fb797fb7a 100644 (file)
--- a/convert-objects.c
+++ b/convert-objects.c
static struct entry *insert_new(unsigned char *sha1, int pos)
{
struct entry *new = xcalloc(1, sizeof(struct entry));
- memcpy(new->old_sha1, sha1, 20);
+ hashcpy(new->old_sha1, sha1);
memmove(convert + pos + 1, convert + pos, (nr_convert - pos) * sizeof(struct entry *));
convert[pos] = new;
nr_convert++;
static void convert_binary_sha1(void *buffer)
{
struct entry *entry = convert_entry(buffer);
- memcpy(buffer, entry->new_sha1, 20);
+ hashcpy(buffer, entry->new_sha1);
}
static void convert_ascii_sha1(void *buffer)
@@ -104,7 +104,7 @@ static int write_subdirectory(void *buffer, unsigned long size, const char *base
if (!slash) {
newlen += sprintf(new + newlen, "%o %s", mode, path);
new[newlen++] = '\0';
- memcpy(new + newlen, (char *) buffer + len - 20, 20);
+ hashcpy((unsigned char*)new + newlen, (unsigned char *) buffer + len - 20);
newlen += 20;
used += len;
diff --git a/csum-file.c b/csum-file.c
index e2278897d08b750f383ae5bb2ac7e738a99a7ae5..b7174c6c056c5a8f2a800ecbcb3cdf304c0bfc3f 100644 (file)
--- a/csum-file.c
+++ b/csum-file.c
}
SHA1_Final(f->buffer, &f->ctx);
if (result)
- memcpy(result, f->buffer, 20);
+ hashcpy(result, f->buffer);
if (update)
sha1flush(f, 20);
if (close(f->fd))
diff --git a/diff-lib.c b/diff-lib.c
index 3e4b3b96b71925974eee5f1f691158c314722011..2fc41263aee87547cd755c96bb6f7c345d4b2550 100644 (file)
--- a/diff-lib.c
+++ b/diff-lib.c
if (2 <= stage) {
int mode = ntohl(nce->ce_mode);
num_compare_stages++;
- memcpy(dpath->parent[stage-2].sha1,
- nce->sha1, 20);
+ hashcpy(dpath->parent[stage-2].sha1, nce->sha1);
dpath->parent[stage-2].mode =
canon_mode(mode);
dpath->parent[stage-2].status =
index da7cca1952e7e245730bd81419e1b23ce57ef173..ca171e8e69680f8f873529729b129858a8201e08 100644 (file)
--- a/diff.c
+++ b/diff.c
{
if (mode) {
spec->mode = canon_mode(mode);
- memcpy(spec->sha1, sha1, 20);
+ hashcpy(spec->sha1, sha1);
spec->sha1_valid = !is_null_sha1(sha1);
}
}
sizeof(*sha1_size_cache));
e = xmalloc(sizeof(struct sha1_size_cache));
sha1_size_cache[first] = e;
- memcpy(e->sha1, sha1, 20);
+ hashcpy(e->sha1, sha1);
e->size = size;
return e;
}
}
}
else
- memset(one->sha1, 0, 20);
+ hashclr(one->sha1);
}
static void run_diff(struct diff_filepair *p, struct diff_options *o)
diff --git a/fetch-pack.c b/fetch-pack.c
index e18c1489a1ab8620cade351ec502828b10a41ac4..377feded1ccafdece86499d1917d297145fd28ac 100644 (file)
--- a/fetch-pack.c
+++ b/fetch-pack.c
continue;
}
- memcpy(ref->new_sha1, local, 20);
+ hashcpy(ref->new_sha1, local);
if (!verbose)
continue;
fprintf(stderr,
index aeb6bf2639cc75b6f738348bcc267179a8a0da65..ef60b045eaa0a55ba65499187a3aac082ffb6af2 100644 (file)
--- a/fetch.c
+++ b/fetch.c
if (commit->object.flags & COMPLETE)
return 0;
- memcpy(current_commit_sha1, commit->object.sha1, 20);
+ hashcpy(current_commit_sha1, commit->object.sha1);
pull_say("walk %s\n", sha1_to_hex(commit->object.sha1));
diff --git a/fsck-objects.c b/fsck-objects.c
index 31e00d84b30f95c713b3dc6a654b4ef8459c6729..ae0ec8d039cfce698daa8a9f44c7f49b932373c8 100644 (file)
--- a/fsck-objects.c
+++ b/fsck-objects.c
int nr;
entry->ino = ino;
- memcpy(entry->sha1, sha1, 20);
+ hashcpy(entry->sha1, sha1);
nr = sha1_list.nr;
if (nr == MAX_SHA1_ENTRIES) {
fsck_sha1_list();
diff --git a/http-fetch.c b/http-fetch.c
index d1f74b443be23e8cd7f10128713217acfab5254b..7619b338feb92a431268fc5a3963415af1b53e99 100644 (file)
--- a/http-fetch.c
+++ b/http-fetch.c
char *filename = sha1_file_name(sha1);
newreq = xmalloc(sizeof(*newreq));
- memcpy(newreq->sha1, sha1, 20);
+ hashcpy(newreq->sha1, sha1);
newreq->repo = alt;
newreq->url = NULL;
newreq->local = -1;
diff --git a/http-push.c b/http-push.c
index 48497797f1650a2ed3f24010a85123993b14d8aa..ebfcc73a9ef7abb20f149ca433c9bd67649854d3 100644 (file)
--- a/http-push.c
+++ b/http-push.c
struct ref *ref;
int len = strlen(refname) + 1;
ref = xcalloc(1, sizeof(*ref) + len);
- memcpy(ref->new_sha1, sha1, 20);
+ hashcpy(ref->new_sha1, sha1);
memcpy(ref->name, refname, len);
*local_tail = ref;
local_tail = &ref->next;
}
ref = xcalloc(1, sizeof(*ref) + len);
- memcpy(ref->old_sha1, remote_sha1, 20);
+ hashcpy(ref->old_sha1, remote_sha1);
memcpy(ref->name, refname, len);
*remote_tail = ref;
remote_tail = &ref->next;
continue;
}
}
- memcpy(ref->new_sha1, ref->peer_ref->new_sha1, 20);
+ hashcpy(ref->new_sha1, ref->peer_ref->new_sha1);
if (is_zero_sha1(ref->new_sha1)) {
error("cannot happen anymore");
rc = -3;
diff --git a/index-pack.c b/index-pack.c
index 96ea6874634959c18263779a01f8385ee9ffde1e..80bc6cb45b1a91c31dbdf18b48399b7a7a6b2737 100644 (file)
--- a/index-pack.c
+++ b/index-pack.c
case OBJ_DELTA:
if (pos + 20 >= pack_limit)
bad_object(offset, "object extends past end of pack");
- memcpy(delta_base, pack_base + pos, 20);
+ hashcpy(delta_base, pack_base + pos);
pos += 20;
/* fallthru */
case OBJ_COMMIT:
if (obj->type == OBJ_DELTA) {
struct delta_entry *delta = &deltas[nr_deltas++];
delta->obj = obj;
- memcpy(delta->base_sha1, base_sha1, 20);
+ hashcpy(delta->base_sha1, base_sha1);
} else
sha1_object(data, data_size, obj->type, obj->sha1);
free(data);
diff --git a/mktree.c b/mktree.c
index 93241385e4aee76fc42db5849365740c474b9bdd..56205d1e0053cdcb7236bde199817a5529d3f433 100644 (file)
--- a/mktree.c
+++ b/mktree.c
ent = entries[used++] = xmalloc(sizeof(**entries) + len + 1);
ent->mode = mode;
ent->len = len;
- memcpy(ent->sha1, sha1, 20);
+ hashcpy(ent->sha1, sha1);
memcpy(ent->name, path, len+1);
}
offset += sprintf(buffer + offset, "%o ", ent->mode);
offset += sprintf(buffer + offset, "%s", ent->name);
buffer[offset++] = 0;
- memcpy(buffer + offset, ent->sha1, 20);
+ hashcpy((unsigned char*)buffer + offset, ent->sha1);
offset += 20;
}
write_sha1_file(buffer, offset, tree_type, sha1);
diff --git a/object.c b/object.c
index fdcfff7c86057bf8e5a7285518f186c67a1715bb..60bf16b902033d9f256282201ca7aeca74855d7e 100644 (file)
--- a/object.c
+++ b/object.c
obj->used = 0;
obj->type = OBJ_NONE;
obj->flags = 0;
- memcpy(obj->sha1, sha1, 20);
+ hashcpy(obj->sha1, sha1);
if (obj_hash_size - 1 <= nr_objs * 2)
grow_object_hash();
diff --git a/patch-id.c b/patch-id.c
index 3b4c80f764bd11a740a7cce60f2e8c062706e897..086d2d9c68835c6a7434932f6e3b430e0906578d 100644 (file)
--- a/patch-id.c
+++ b/patch-id.c
if (!get_sha1_hex(p, n)) {
flush_current_id(patchlen, sha1, &ctx);
- memcpy(sha1, n, 20);
+ hashcpy(sha1, n);
patchlen = 0;
continue;
}
diff --git a/receive-pack.c b/receive-pack.c
index 81e91909b8ac88423c550a6489285b003378c5f0..201531626c2a60dffd1720ab4d00d7023bcbc78e 100644 (file)
--- a/receive-pack.c
+++ b/receive-pack.c
report_status = 1;
}
cmd = xmalloc(sizeof(struct command) + len - 80);
- memcpy(cmd->old_sha1, old_sha1, 20);
- memcpy(cmd->new_sha1, new_sha1, 20);
+ hashcpy(cmd->old_sha1, old_sha1);
+ hashcpy(cmd->new_sha1, new_sha1);
memcpy(cmd->ref_name, line + 82, len - 81);
cmd->error_string = "n/a (unpacker error)";
cmd->next = NULL;
index 17cd0cef3c9819d70083554f99d8f09391171db1..e70ef0ae0fe58671a35b71a55fbf81425ee84581 100644 (file)
--- a/refs.c
+++ b/refs.c
if (lstat(path, &st) < 0) {
if (reading || errno != ENOENT)
return NULL;
- memset(sha1, 0, 20);
+ hashclr(sha1);
return path;
}
diff --git a/revision.c b/revision.c
index 5a91d06b980d710e30a80c353a636ca1ca6b9a55..1d89d72738ff917d29373d50c2c2cc9bbd10b2c0 100644 (file)
--- a/revision.c
+++ b/revision.c
it = get_reference(revs, arg, sha1, 0);
if (it->type != OBJ_TAG)
break;
- memcpy(sha1, ((struct tag*)it)->tagged->sha1, 20);
+ hashcpy(sha1, ((struct tag*)it)->tagged->sha1);
}
if (it->type != OBJ_COMMIT)
return 0;
diff --git a/send-pack.c b/send-pack.c
index f7c0cfc6f67ba4d325ac6fc9f6c74fad78d1208e..fd79a61923ddc20af216ccd252e40bf38a70eccb 100644 (file)
--- a/send-pack.c
+++ b/send-pack.c
struct ref *ref;
int len = strlen(refname) + 1;
ref = xcalloc(1, sizeof(*ref) + len);
- memcpy(ref->new_sha1, sha1, 20);
+ hashcpy(ref->new_sha1, sha1);
memcpy(ref->name, refname, len);
*local_tail = ref;
local_tail = &ref->next;
continue;
}
}
- memcpy(ref->new_sha1, ref->peer_ref->new_sha1, 20);
+ hashcpy(ref->new_sha1, ref->peer_ref->new_sha1);
if (is_zero_sha1(ref->new_sha1)) {
error("cannot happen anymore");
ret = -3;
diff --git a/sha1_file.c b/sha1_file.c
index 066cff1fa6e8dd1485876984becdecd7bb4987b6..769a80984d25ca362acb8d7c4f97ac3526c2b753 100644 (file)
--- a/sha1_file.c
+++ b/sha1_file.c
p->pack_use_cnt = 0;
p->pack_local = local;
if ((path_len > 44) && !get_sha1_hex(path + path_len - 44, sha1))
- memcpy(p->sha1, sha1, 20);
+ hashcpy(p->sha1, sha1);
return p;
}
@@ -571,7 +571,7 @@ struct packed_git *parse_pack_index_file(const unsigned char *sha1, char *idx_pa
p->pack_base = NULL;
p->pack_last_used = 0;
p->pack_use_cnt = 0;
- memcpy(p->sha1, sha1, 20);
+ hashcpy(p->sha1, sha1);
return p;
}
ptr = unpack_object_header(p, ptr, kindp, sizep);
if (*kindp != OBJ_DELTA)
goto done;
- memcpy(base, (unsigned char *) p->pack_base + ptr, 20);
+ hashcpy(base, (unsigned char *) p->pack_base + ptr);
status = 0;
done:
unuse_packed_git(p);
if (p->pack_size <= offset + 20)
die("pack file %s records an incomplete delta base",
p->pack_name);
- memcpy(base_sha1, pack, 20);
+ hashcpy(base_sha1, pack);
do {
struct pack_entry base_ent;
unsigned long junk;
void *index = p->index_base + 256;
if (n < 0 || num_packed_objects(p) <= n)
return -1;
- memcpy(sha1, (char *) index + (24 * n) + 4, 20);
+ hashcpy(sha1, (unsigned char *) index + (24 * n) + 4);
return 0;
}
int cmp = hashcmp((unsigned char *)index + (24 * mi) + 4, sha1);
if (!cmp) {
e->offset = ntohl(*((unsigned int *) ((char *) index + (24 * mi))));
- memcpy(e->sha1, sha1, 20);
+ hashcpy(e->sha1, sha1);
e->p = p;
return 1;
}
unsigned long isize;
unsigned char actual_sha1[20];
- memcpy(actual_sha1, sha1, 20);
+ hashcpy(actual_sha1, sha1);
while (1) {
int ref_length = -1;
const char *ref_type = NULL;
if (!strcmp(type, required_type)) {
*size = isize;
if (actual_sha1_return)
- memcpy(actual_sha1_return, actual_sha1, 20);
+ hashcpy(actual_sha1_return, actual_sha1);
return buffer;
}
/* Handle references */
@@ -1537,7 +1537,7 @@ int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned cha
*/
filename = write_sha1_file_prepare(buf, len, type, sha1, hdr, &hdrlen);
if (returnsha1)
- memcpy(returnsha1, sha1, 20);
+ hashcpy(returnsha1, sha1);
if (has_sha1_file(sha1))
return 0;
fd = open(filename, O_RDONLY);
diff --git a/sha1_name.c b/sha1_name.c
index e9eb6ce882ea92523c9a871c7581457af2dc78c5..89b9e3b77af068b93e720dc03e71ad189fefb116 100644 (file)
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -103,7 +103,7 @@ static int find_short_packed_object(int len, const unsigned char *match, unsigne
!match_sha(len, match, next)) {
/* unique within this pack */
if (!found) {
- memcpy(found_sha1, now, 20);
+ hashcpy(found_sha1, now);
found++;
}
else if (hashcmp(found_sha1, now)) {
@@ -120,7 +120,7 @@ static int find_short_packed_object(int len, const unsigned char *match, unsigne
}
}
if (found == 1)
- memcpy(sha1, found_sha1, 20);
+ hashcpy(sha1, found_sha1);
return found;
}
if (1 < has_unpacked || 1 < has_packed)
return SHORT_NAME_AMBIGUOUS;
if (has_unpacked != has_packed) {
- memcpy(sha1, (has_packed ? packed_sha1 : unpacked_sha1), 20);
+ hashcpy(sha1, (has_packed ? packed_sha1 : unpacked_sha1));
return 0;
}
/* Both have unique ones -- do they match? */
if (hashcmp(packed_sha1, unpacked_sha1))
return SHORT_NAME_AMBIGUOUS;
- memcpy(sha1, packed_sha1, 20);
+ hashcpy(sha1, packed_sha1);
return 0;
}
if (parse_commit(commit))
return -1;
if (!idx) {
- memcpy(result, commit->object.sha1, 20);
+ hashcpy(result, commit->object.sha1);
return 0;
}
p = commit->parents;
while (p) {
if (!--idx) {
- memcpy(result, p->item->object.sha1, 20);
+ hashcpy(result, p->item->object.sha1);
return 0;
}
p = p->next;
if (!commit || parse_commit(commit) || !commit->parents)
return -1;
- memcpy(sha1, commit->parents->item->object.sha1, 20);
+ hashcpy(sha1, commit->parents->item->object.sha1);
}
- memcpy(result, sha1, 20);
+ hashcpy(result, sha1);
return 0;
}
o = deref_tag(o, name, sp - name - 2);
if (!o || (!o->parsed && !parse_object(o->sha1)))
return -1;
- memcpy(sha1, o->sha1, 20);
+ hashcpy(sha1, o->sha1);
}
else {
/* At this point, the syntax look correct, so
if (!o || (!o->parsed && !parse_object(o->sha1)))
return -1;
if (o->type == expected_type) {
- memcpy(sha1, o->sha1, 20);
+ hashcpy(sha1, o->sha1);
return 0;
}
if (o->type == OBJ_TAG)
memcmp(ce->name, cp, namelen))
break;
if (ce_stage(ce) == stage) {
- memcpy(sha1, ce->sha1, 20);
+ hashcpy(sha1, ce->sha1);
return 0;
}
pos++;
diff --git a/tree-walk.c b/tree-walk.c
index 3f83e98f3a443e4537f53abf32bcca1389c5d9d8..14cc5aea6c4eefbf4b0fa9c72ccb70ec550b44b4 100644 (file)
--- a/tree-walk.c
+++ b/tree-walk.c
if (cmp < 0)
break;
if (entrylen == namelen) {
- memcpy(result, sha1, 20);
+ hashcpy(result, sha1);
return 0;
}
if (name[entrylen] != '/')
if (!S_ISDIR(*mode))
break;
if (++entrylen == namelen) {
- memcpy(result, sha1, 20);
+ hashcpy(result, sha1);
return 0;
}
return get_tree_entry(sha1, name + entrylen, result, mode);
index ef456be9dd0faee46435a3c3b126a36c2be58051..ea386e506659c65224cfe55bdc4f8d086171637a 100644 (file)
--- a/tree.c
+++ b/tree.c
ce->ce_flags = create_ce_flags(baselen + len, stage);
memcpy(ce->name, base, baselen);
memcpy(ce->name + baselen, pathname, len+1);
- memcpy(ce->sha1, sha1, 20);
+ hashcpy(ce->sha1, sha1);
return add_cache_entry(ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK);
}
diff --git a/unpack-trees.c b/unpack-trees.c
index 467d9940f5a2e9cd8a880e4c8f0f1d2a8a5f7aa1..3ac0289b3a3309fca9ade4e271dbd8b0d2f148ea 100644 (file)
--- a/unpack-trees.c
+++ b/unpack-trees.c
any_files = 1;
- memcpy(ce->sha1, posns[i]->sha1, 20);
+ hashcpy(ce->sha1, posns[i]->sha1);
src[i + o->merge] = ce;
subposns[i] = df_conflict_list;
posns[i] = posns[i]->next;
diff --git a/upload-pack.c b/upload-pack.c
index fcf279843ad23b0605f3c2bc558e8d04a903554b..51ce936b060d34a2f759dba4f7aeeecf47a59a4b 100644 (file)
--- a/upload-pack.c
+++ b/upload-pack.c
sha1_to_hex(sha1),
multi_ack ? " continue" : "");
if (multi_ack)
- memcpy(last_sha1, sha1, 20);
+ hashcpy(last_sha1, sha1);
}
continue;
}