@matheusbsbs / matheus-bagliano / commits / 8da7149394
Fork 0

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: this is a follow-up patch for merge-recursive.c which is not in "master" yet. The original was sent-in for "next" so I splitted it out. ] Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Shawn Pearce committed Aug 23, 2006 at 02:49 UTC 8da714939458fed99ff750ca09d4169fe68b034e
1 file changed +10 -10
merge-recursive.c
+10 -10
@@ -158,7 +158,7 @@ static struct cache_entry *make_cache_entry(unsigned int mode,
158 size = cache_entry_size(len);
159 ce = xcalloc(1, size);
160
161 - memcpy(ce->sha1, sha1, 20);
161 + hashcpy(ce->sha1, sha1);
162 memcpy(ce->name, path, len);
163 ce->ce_flags = create_ce_flags(len, stage);
164 ce->ce_mode = create_ce_mode(mode);
@@ -355,7 +355,7 @@ static struct path_list *get_unmerged(void)
355 }
356 e = item->util;
357 e->stages[ce_stage(ce)].mode = ntohl(ce->ce_mode);
358 - memcpy(e->stages[ce_stage(ce)].sha, ce->sha1, 20);
358 + hashcpy(e->stages[ce_stage(ce)].sha, ce->sha1);
359 }
360
361 return unmerged;
@@ -636,10 +636,10 @@ static struct merge_file_info merge_file(struct diff_filespec *o,
636 result.clean = 0;
637 if (S_ISREG(a->mode)) {
638 result.mode = a->mode;
639 - memcpy(result.sha, a->sha1, 20);
639 + hashcpy(result.sha, a->sha1);
640 } else {
641 result.mode = b->mode;
642 - memcpy(result.sha, b->sha1, 20);
642 + hashcpy(result.sha, b->sha1);
643 }
644 } else {
645 if (!sha_eq(a->sha1, o->sha1) && !sha_eq(b->sha1, o->sha1))
@@ -648,9 +648,9 @@ static struct merge_file_info merge_file(struct diff_filespec *o,
648 result.mode = a->mode == o->mode ? b->mode: a->mode;
649
650 if (sha_eq(a->sha1, o->sha1))
651 - memcpy(result.sha, b->sha1, 20);
651 + hashcpy(result.sha, b->sha1);
652 else if (sha_eq(b->sha1, o->sha1))
653 - memcpy(result.sha, a->sha1, 20);
653 + hashcpy(result.sha, a->sha1);
654 else if (S_ISREG(a->mode)) {
655 int code = 1, fd;
656 struct stat st;
@@ -699,7 +699,7 @@ static struct merge_file_info merge_file(struct diff_filespec *o,
699 if (!(S_ISLNK(a->mode) || S_ISLNK(b->mode)))
700 die("cannot merge modes?");
701
702 - memcpy(result.sha, a->sha1, 20);
702 + hashcpy(result.sha, a->sha1);
703
704 if (!sha_eq(a->sha1, b->sha1))
705 result.clean = 0;
@@ -1096,11 +1096,11 @@ static int process_entry(const char *path, struct stage_data *entry,
1096
1097 output("Auto-merging %s", path);
1098 o.path = a.path = b.path = (char *)path;
1099 - memcpy(o.sha1, o_sha, 20);
1099 + hashcpy(o.sha1, o_sha);
1100 o.mode = o_mode;
1101 - memcpy(a.sha1, a_sha, 20);
1101 + hashcpy(a.sha1, a_sha);
1102 a.mode = a_mode;
1103 - memcpy(b.sha1, b_sha, 20);
1103 + hashcpy(b.sha1, b_sha);
1104 b.mode = b_mode;
1105
1106 mfi = merge_file(&o, &a, &b,