Convert memcpy(a,b,20) to hashcpy(a,b).
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>
This commit is contained in:

committed by
Junio C Hamano

parent
b05faa2da9
commit
e702496e43
@ -1874,7 +1874,7 @@ static int one_local_ref(const char *refname, const unsigned char *sha1)
|
||||
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;
|
||||
@ -1909,7 +1909,7 @@ static void one_remote_ref(char *refname)
|
||||
}
|
||||
|
||||
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;
|
||||
@ -2445,7 +2445,7 @@ int main(int argc, char **argv)
|
||||
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;
|
||||
|
Reference in New Issue
Block a user