@matheusbsbs / matheus-bagliano / commits / e702496e43
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: 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>

Shawn Pearce committed Aug 23, 2006 at 02:49 UTC e702496e434a160f798447b95b9cea3cd138c140
34 files changed +81 -78
blame.c
+2 -2
@@ -176,7 +176,7 @@ static int get_blob_sha1(struct tree *t, const char *pathname,
176 if (i == 20)
177 return -1;
178
179 - memcpy(sha1, blob_sha1, 20);
179 + hashcpy(sha1, blob_sha1);
180 return 0;
181 }
182
@@ -191,7 +191,7 @@ static int get_blob_sha1_internal(const unsigned char *sha1, const char *base,
191 strcmp(blame_file + baselen, pathname))
192 return -1;
193
194 - memcpy(blob_sha1, sha1, 20);
194 + hashcpy(blob_sha1, sha1);
195 return -1;
196 }
197
builtin-diff.c
+2 -2
@@ -192,7 +192,7 @@ static int builtin_diff_combined(struct rev_info *revs,
192 parent = xmalloc(ents * sizeof(*parent));
193 /* Again, the revs are all reverse */
194 for (i = 0; i < ents; i++)
195 - memcpy(parent + i, ent[ents - 1 - i].item->sha1, 20);
195 + hashcpy((unsigned char*)parent + i, ent[ents - 1 - i].item->sha1);
196 diff_tree_combined(parent[0], parent + 1, ents - 1,
197 revs->dense_combined_merges, revs);
198 return 0;
@@ -290,7 +290,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
290 if (obj->type == OBJ_BLOB) {
291 if (2 <= blobs)
292 die("more than two blobs given: '%s'", name);
293 - memcpy(blob[blobs].sha1, obj->sha1, 20);
293 + hashcpy(blob[blobs].sha1, obj->sha1);
294 blob[blobs].name = name;
295 blobs++;
296 continue;
builtin-pack-objects.c
+3 -3
@@ -534,7 +534,7 @@ static int add_object_entry(const unsigned char *sha1, unsigned hash, int exclud
534 entry = objects + idx;
535 nr_objects = idx + 1;
536 memset(entry, 0, sizeof(*entry));
537 - memcpy(entry->sha1, sha1, 20);
537 + hashcpy(entry->sha1, sha1);
538 entry->hash = hash;
539
540 if (object_ix_hashsz * 3 <= nr_objects * 4)
@@ -649,7 +649,7 @@ static struct pbase_tree_cache *pbase_tree_get(const unsigned char *sha1)
649 free(ent->tree_data);
650 nent = ent;
651 }
652 - memcpy(nent->sha1, sha1, 20);
652 + hashcpy(nent->sha1, sha1);
653 nent->tree_data = data;
654 nent->tree_size = size;
655 nent->ref = 1;
@@ -799,7 +799,7 @@ static void add_preferred_base(unsigned char *sha1)
799 it->next = pbase_tree;
800 pbase_tree = it;
801
802 - memcpy(it->pcache.sha1, tree_sha1, 20);
802 + hashcpy(it->pcache.sha1, tree_sha1);
803 it->pcache.tree_data = data;
804 it->pcache.tree_size = size;
805 }
builtin-read-tree.c
+1 -1
@@ -53,7 +53,7 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
53 struct name_entry entry;
54 int cnt;
55
56 - memcpy(it->sha1, tree->object.sha1, 20);
56 + hashcpy(it->sha1, tree->object.sha1);
57 desc.buf = tree->buffer;
58 desc.size = tree->size;
59 cnt = 0;
builtin-unpack-objects.c
+2 -2
@@ -95,7 +95,7 @@ static void add_delta_to_list(unsigned char *base_sha1, void *delta, unsigned lo
95 {
96 struct delta_info *info = xmalloc(sizeof(*info));
97
98 - memcpy(info->base_sha1, base_sha1, 20);
98 + hashcpy(info->base_sha1, base_sha1);
99 info->size = size;
100 info->delta = delta;
101 info->next = delta_list;
@@ -173,7 +173,7 @@ static int unpack_delta_entry(unsigned long delta_size)
173 unsigned char base_sha1[20];
174 int result;
175
176 - memcpy(base_sha1, fill(20), 20);
176 + hashcpy(base_sha1, fill(20));
177 use(20);
178
179 delta_data = get_data(delta_size);
builtin-update-index.c
+2 -2
@@ -142,7 +142,7 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,
142 size = cache_entry_size(len);
143 ce = xcalloc(1, size);
144
145 - memcpy(ce->sha1, sha1, 20);
145 + hashcpy(ce->sha1, sha1);
146 memcpy(ce->name, path, len);
147 ce->ce_flags = create_ce_flags(len, stage);
148 ce->ce_mode = create_ce_mode(mode);
@@ -333,7 +333,7 @@ static struct cache_entry *read_one_ent(const char *which,
333 size = cache_entry_size(namelen);
334 ce = xcalloc(1, size);
335
336 - memcpy(ce->sha1, sha1, 20);
336 + hashcpy(ce->sha1, sha1);
337 memcpy(ce->name, path, namelen);
338 ce->ce_flags = create_ce_flags(namelen, stage);
339 ce->ce_mode = create_ce_mode(mode);
builtin-write-tree.c
+2 -2
@@ -50,10 +50,10 @@ int write_tree(unsigned char *sha1, int missing_ok, const char *prefix)
50 if (prefix) {
51 struct cache_tree *subtree =
52 cache_tree_find(active_cache_tree, prefix);
53 - memcpy(sha1, subtree->sha1, 20);
53 + hashcpy(sha1, subtree->sha1);
54 }
55 else
56 - memcpy(sha1, active_cache_tree->sha1, 20);
56 + hashcpy(sha1, active_cache_tree->sha1);
57
58 rollback_lock_file(lock_file);
59
cache-tree.c
+3 -3
@@ -335,7 +335,7 @@ static int update_one(struct cache_tree *it,
335 offset += sprintf(buffer + offset,
336 "%o %.*s", mode, entlen, path + baselen);
337 buffer[offset++] = 0;
338 - memcpy(buffer + offset, sha1, 20);
338 + hashcpy((unsigned char*)buffer + offset, sha1);
339 offset += 20;
340
341 #if DEBUG
@@ -412,7 +412,7 @@ static void *write_one(struct cache_tree *it,
412 #endif
413
414 if (0 <= it->entry_count) {
415 - memcpy(buffer + *offset, it->sha1, 20);
415 + hashcpy((unsigned char*)buffer + *offset, it->sha1);
416 *offset += 20;
417 }
418 for (i = 0; i < it->subtree_nr; i++) {
@@ -478,7 +478,7 @@ static struct cache_tree *read_one(const char **buffer, unsigned long *size_p)
478 if (0 <= it->entry_count) {
479 if (size < 20)
480 goto free_return;
481 - memcpy(it->sha1, buf, 20);
481 + hashcpy(it->sha1, (unsigned char*)buf);
482 buf += 20;
483 size -= 20;
484 }
cache.h
+4
@@ -218,6 +218,10 @@ static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)
218 {
219 return memcmp(sha1, sha2, 20);
220 }
221 +static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)
222 +{
223 + memcpy(sha_dst, sha_src, 20);
224 +}
225
226 int git_mkstemp(char *path, size_t n, const char *template);
227
combine-diff.c
+5 -5
@@ -31,9 +31,9 @@ static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr,
31 memset(p->parent, 0,
32 sizeof(p->parent[0]) * num_parent);
33
34 - memcpy(p->sha1, q->queue[i]->two->sha1, 20);
34 + hashcpy(p->sha1, q->queue[i]->two->sha1);
35 p->mode = q->queue[i]->two->mode;
36 - memcpy(p->parent[n].sha1, q->queue[i]->one->sha1, 20);
36 + hashcpy(p->parent[n].sha1, q->queue[i]->one->sha1);
37 p->parent[n].mode = q->queue[i]->one->mode;
38 p->parent[n].status = q->queue[i]->status;
39 *tail = p;
@@ -56,8 +56,7 @@ static struct combine_diff_path *intersect_paths(struct combine_diff_path *curr,
56 len = strlen(path);
57 if (len == p->len && !memcmp(path, p->path, len)) {
58 found = 1;
59 - memcpy(p->parent[n].sha1,
60 - q->queue[i]->one->sha1, 20);
59 + hashcpy(p->parent[n].sha1, q->queue[i]->one->sha1);
60 p->parent[n].mode = q->queue[i]->one->mode;
61 p->parent[n].status = q->queue[i]->status;
62 break;
@@ -927,6 +926,7 @@ void diff_tree_combined_merge(const unsigned char *sha1,
926 for (parents = commit->parents, num_parent = 0;
927 parents;
928 parents = parents->next, num_parent++)
930 - memcpy(parent + num_parent, parents->item->object.sha1, 20);
929 + hashcpy((unsigned char*)(parent + num_parent),
930 + parents->item->object.sha1);
931 diff_tree_combined(sha1, parent, num_parent, dense, rev);
932 }
connect.c
+3 -3
@@ -77,7 +77,7 @@ struct ref **get_remote_heads(int in, struct ref **list,
77 if (nr_match && !path_match(name, nr_match, match))
78 continue;
79 ref = xcalloc(1, sizeof(*ref) + len - 40);
80 - memcpy(ref->old_sha1, old_sha1, 20);
80 + hashcpy(ref->old_sha1, old_sha1);
81 memcpy(ref->name, buffer + 41, len - 40);
82 *list = ref;
83 list = &ref->next;
@@ -208,7 +208,7 @@ static struct ref *try_explicit_object_name(const char *name)
208 len = strlen(name) + 1;
209 ref = xcalloc(1, sizeof(*ref) + len);
210 memcpy(ref->name, name, len);
211 - memcpy(ref->new_sha1, sha1, 20);
211 + hashcpy(ref->new_sha1, sha1);
212 return ref;
213 }
214
@@ -318,7 +318,7 @@ int match_refs(struct ref *src, struct ref *dst, struct ref ***dst_tail,
318 int len = strlen(src->name) + 1;
319 dst_peer = xcalloc(1, sizeof(*dst_peer) + len);
320 memcpy(dst_peer->name, src->name, len);
321 - memcpy(dst_peer->new_sha1, src->new_sha1, 20);
321 + hashcpy(dst_peer->new_sha1, src->new_sha1);
322 link_dst_tail(dst_peer, dst_tail);
323 }
324 dst_peer->peer_ref = src;
convert-objects.c
+3 -3
@@ -23,7 +23,7 @@ static struct entry * convert_entry(unsigned char *sha1);
23 static struct entry *insert_new(unsigned char *sha1, int pos)
24 {
25 struct entry *new = xcalloc(1, sizeof(struct entry));
26 - memcpy(new->old_sha1, sha1, 20);
26 + hashcpy(new->old_sha1, sha1);
27 memmove(convert + pos + 1, convert + pos, (nr_convert - pos) * sizeof(struct entry *));
28 convert[pos] = new;
29 nr_convert++;
@@ -54,7 +54,7 @@ static struct entry *lookup_entry(unsigned char *sha1)
54 static void convert_binary_sha1(void *buffer)
55 {
56 struct entry *entry = convert_entry(buffer);
57 - memcpy(buffer, entry->new_sha1, 20);
57 + hashcpy(buffer, entry->new_sha1);
58 }
59
60 static void convert_ascii_sha1(void *buffer)
@@ -104,7 +104,7 @@ static int write_subdirectory(void *buffer, unsigned long size, const char *base
104 if (!slash) {
105 newlen += sprintf(new + newlen, "%o %s", mode, path);
106 new[newlen++] = '\0';
107 - memcpy(new + newlen, (char *) buffer + len - 20, 20);
107 + hashcpy((unsigned char*)new + newlen, (unsigned char *) buffer + len - 20);
108 newlen += 20;
109
110 used += len;
csum-file.c
+1 -1
@@ -38,7 +38,7 @@ int sha1close(struct sha1file *f, unsigned char *result, int update)
38 }
39 SHA1_Final(f->buffer, &f->ctx);
40 if (result)
41 - memcpy(result, f->buffer, 20);
41 + hashcpy(result, f->buffer);
42 if (update)
43 sha1flush(f, 20);
44 if (close(f->fd))
diff-lib.c
+1 -2
@@ -66,8 +66,7 @@ int run_diff_files(struct rev_info *revs, int silent_on_removed)
66 if (2 <= stage) {
67 int mode = ntohl(nce->ce_mode);
68 num_compare_stages++;
69 - memcpy(dpath->parent[stage-2].sha1,
70 - nce->sha1, 20);
69 + hashcpy(dpath->parent[stage-2].sha1, nce->sha1);
70 dpath->parent[stage-2].mode =
71 canon_mode(mode);
72 dpath->parent[stage-2].status =
diff.c
+3 -3
@@ -1101,7 +1101,7 @@ void fill_filespec(struct diff_filespec *spec, const unsigned char *sha1,
1101 {
1102 if (mode) {
1103 spec->mode = canon_mode(mode);
1104 - memcpy(spec->sha1, sha1, 20);
1104 + hashcpy(spec->sha1, sha1);
1105 spec->sha1_valid = !is_null_sha1(sha1);
1106 }
1107 }
@@ -1194,7 +1194,7 @@ static struct sha1_size_cache *locate_size_cache(unsigned char *sha1,
1194 sizeof(*sha1_size_cache));
1195 e = xmalloc(sizeof(struct sha1_size_cache));
1196 sha1_size_cache[first] = e;
1197 - memcpy(e->sha1, sha1, 20);
1197 + hashcpy(e->sha1, sha1);
1198 e->size = size;
1199 return e;
1200 }
@@ -1516,7 +1516,7 @@ static void diff_fill_sha1_info(struct diff_filespec *one)
1516 }
1517 }
1518 else
1519 - memset(one->sha1, 0, 20);
1519 + hashclr(one->sha1);
1520 }
1521
1522 static void run_diff(struct diff_filepair *p, struct diff_options *o)
fetch-pack.c
+1 -1
@@ -404,7 +404,7 @@ static int everything_local(struct ref **refs, int nr_match, char **match)
404 continue;
405 }
406
407 - memcpy(ref->new_sha1, local, 20);
407 + hashcpy(ref->new_sha1, local);
408 if (!verbose)
409 continue;
410 fprintf(stderr,
fetch.c
+1 -1
@@ -84,7 +84,7 @@ static int process_commit(struct commit *commit)
84 if (commit->object.flags & COMPLETE)
85 return 0;
86
87 - memcpy(current_commit_sha1, commit->object.sha1, 20);
87 + hashcpy(current_commit_sha1, commit->object.sha1);
88
89 pull_say("walk %s\n", sha1_to_hex(commit->object.sha1));
90
fsck-objects.c
+1 -1
@@ -356,7 +356,7 @@ static void add_sha1_list(unsigned char *sha1, unsigned long ino)
356 int nr;
357
358 entry->ino = ino;
359 - memcpy(entry->sha1, sha1, 20);
359 + hashcpy(entry->sha1, sha1);
360 nr = sha1_list.nr;
361 if (nr == MAX_SHA1_ENTRIES) {
362 fsck_sha1_list();
http-fetch.c
+1 -1
@@ -393,7 +393,7 @@ void prefetch(unsigned char *sha1)
393 char *filename = sha1_file_name(sha1);
394
395 newreq = xmalloc(sizeof(*newreq));
396 - memcpy(newreq->sha1, sha1, 20);
396 + hashcpy(newreq->sha1, sha1);
397 newreq->repo = alt;
398 newreq->url = NULL;
399 newreq->local = -1;
http-push.c
+3 -3
@@ -1874,7 +1874,7 @@ static int one_local_ref(const char *refname, const unsigned char *sha1)
1874 struct ref *ref;
1875 int len = strlen(refname) + 1;
1876 ref = xcalloc(1, sizeof(*ref) + len);
1877 - memcpy(ref->new_sha1, sha1, 20);
1877 + hashcpy(ref->new_sha1, sha1);
1878 memcpy(ref->name, refname, len);
1879 *local_tail = ref;
1880 local_tail = &ref->next;
@@ -1909,7 +1909,7 @@ static void one_remote_ref(char *refname)
1909 }
1910
1911 ref = xcalloc(1, sizeof(*ref) + len);
1912 - memcpy(ref->old_sha1, remote_sha1, 20);
1912 + hashcpy(ref->old_sha1, remote_sha1);
1913 memcpy(ref->name, refname, len);
1914 *remote_tail = ref;
1915 remote_tail = &ref->next;
@@ -2445,7 +2445,7 @@ int main(int argc, char **argv)
2445 continue;
2446 }
2447 }
2448 - memcpy(ref->new_sha1, ref->peer_ref->new_sha1, 20);
2448 + hashcpy(ref->new_sha1, ref->peer_ref->new_sha1);
2449 if (is_zero_sha1(ref->new_sha1)) {
2450 error("cannot happen anymore");
2451 rc = -3;
index-pack.c
+2 -2
@@ -161,7 +161,7 @@ static void *unpack_raw_entry(unsigned long offset,
161 case OBJ_DELTA:
162 if (pos + 20 >= pack_limit)
163 bad_object(offset, "object extends past end of pack");
164 - memcpy(delta_base, pack_base + pos, 20);
164 + hashcpy(delta_base, pack_base + pos);
165 pos += 20;
166 /* fallthru */
167 case OBJ_COMMIT:
@@ -304,7 +304,7 @@ static void parse_pack_objects(void)
304 if (obj->type == OBJ_DELTA) {
305 struct delta_entry *delta = &deltas[nr_deltas++];
306 delta->obj = obj;
307 - memcpy(delta->base_sha1, base_sha1, 20);
307 + hashcpy(delta->base_sha1, base_sha1);
308 } else
309 sha1_object(data, data_size, obj->type, obj->sha1);
310 free(data);
mktree.c
+2 -2
@@ -30,7 +30,7 @@ static void append_to_tree(unsigned mode, unsigned char *sha1, char *path)
30 ent = entries[used++] = xmalloc(sizeof(**entries) + len + 1);
31 ent->mode = mode;
32 ent->len = len;
33 - memcpy(ent->sha1, sha1, 20);
33 + hashcpy(ent->sha1, sha1);
34 memcpy(ent->name, path, len+1);
35 }
36
@@ -64,7 +64,7 @@ static void write_tree(unsigned char *sha1)
64 offset += sprintf(buffer + offset, "%o ", ent->mode);
65 offset += sprintf(buffer + offset, "%s", ent->name);
66 buffer[offset++] = 0;
67 - memcpy(buffer + offset, ent->sha1, 20);
67 + hashcpy((unsigned char*)buffer + offset, ent->sha1);
68 offset += 20;
69 }
70 write_sha1_file(buffer, offset, tree_type, sha1);
object.c
+1 -1
@@ -91,7 +91,7 @@ void created_object(const unsigned char *sha1, struct object *obj)
91 obj->used = 0;
92 obj->type = OBJ_NONE;
93 obj->flags = 0;
94 - memcpy(obj->sha1, sha1, 20);
94 + hashcpy(obj->sha1, sha1);
95
96 if (obj_hash_size - 1 <= nr_objs * 2)
97 grow_object_hash();
patch-id.c
+1 -1
@@ -47,7 +47,7 @@ static void generate_id_list(void)
47
48 if (!get_sha1_hex(p, n)) {
49 flush_current_id(patchlen, sha1, &ctx);
50 - memcpy(sha1, n, 20);
50 + hashcpy(sha1, n);
51 patchlen = 0;
52 continue;
53 }
receive-pack.c
+2 -2
@@ -247,8 +247,8 @@ static void read_head_info(void)
247 report_status = 1;
248 }
249 cmd = xmalloc(sizeof(struct command) + len - 80);
250 - memcpy(cmd->old_sha1, old_sha1, 20);
251 - memcpy(cmd->new_sha1, new_sha1, 20);
250 + hashcpy(cmd->old_sha1, old_sha1);
251 + hashcpy(cmd->new_sha1, new_sha1);
252 memcpy(cmd->ref_name, line + 82, len - 81);
253 cmd->error_string = "n/a (unpacker error)";
254 cmd->next = NULL;
refs.c
+1 -1
@@ -29,7 +29,7 @@ const char *resolve_ref(const char *path, unsigned char *sha1, int reading)
29 if (lstat(path, &st) < 0) {
30 if (reading || errno != ENOENT)
31 return NULL;
32 - memset(sha1, 0, 20);
32 + hashclr(sha1);
33 return path;
34 }
35
revision.c
+1 -1
@@ -496,7 +496,7 @@ static int add_parents_only(struct rev_info *revs, const char *arg, int flags)
496 it = get_reference(revs, arg, sha1, 0);
497 if (it->type != OBJ_TAG)
498 break;
499 - memcpy(sha1, ((struct tag*)it)->tagged->sha1, 20);
499 + hashcpy(sha1, ((struct tag*)it)->tagged->sha1);
500 }
501 if (it->type != OBJ_COMMIT)
502 return 0;
send-pack.c
+2 -2
@@ -185,7 +185,7 @@ static int one_local_ref(const char *refname, const unsigned char *sha1)
185 struct ref *ref;
186 int len = strlen(refname) + 1;
187 ref = xcalloc(1, sizeof(*ref) + len);
188 - memcpy(ref->new_sha1, sha1, 20);
188 + hashcpy(ref->new_sha1, sha1);
189 memcpy(ref->name, refname, len);
190 *local_tail = ref;
191 local_tail = &ref->next;
@@ -310,7 +310,7 @@ static int send_pack(int in, int out, int nr_refspec, char **refspec)
310 continue;
311 }
312 }
313 - memcpy(ref->new_sha1, ref->peer_ref->new_sha1, 20);
313 + hashcpy(ref->new_sha1, ref->peer_ref->new_sha1);
314 if (is_zero_sha1(ref->new_sha1)) {
315 error("cannot happen anymore");
316 ret = -3;
sha1_file.c
+9 -9
@@ -540,7 +540,7 @@ struct packed_git *add_packed_git(char *path, int path_len, int local)
540 p->pack_use_cnt = 0;
541 p->pack_local = local;
542 if ((path_len > 44) && !get_sha1_hex(path + path_len - 44, sha1))
543 - memcpy(p->sha1, sha1, 20);
543 + hashcpy(p->sha1, sha1);
544 return p;
545 }
546
@@ -571,7 +571,7 @@ struct packed_git *parse_pack_index_file(const unsigned char *sha1, char *idx_pa
571 p->pack_base = NULL;
572 p->pack_last_used = 0;
573 p->pack_use_cnt = 0;
574 - memcpy(p->sha1, sha1, 20);
574 + hashcpy(p->sha1, sha1);
575 return p;
576 }
577
@@ -953,7 +953,7 @@ int check_reuse_pack_delta(struct packed_git *p, unsigned long offset,
953 ptr = unpack_object_header(p, ptr, kindp, sizep);
954 if (*kindp != OBJ_DELTA)
955 goto done;
956 - memcpy(base, (unsigned char *) p->pack_base + ptr, 20);
956 + hashcpy(base, (unsigned char *) p->pack_base + ptr);
957 status = 0;
958 done:
959 unuse_packed_git(p);
@@ -981,7 +981,7 @@ void packed_object_info_detail(struct pack_entry *e,
981 if (p->pack_size <= offset + 20)
982 die("pack file %s records an incomplete delta base",
983 p->pack_name);
984 - memcpy(base_sha1, pack, 20);
984 + hashcpy(base_sha1, pack);
985 do {
986 struct pack_entry base_ent;
987 unsigned long junk;
@@ -1201,7 +1201,7 @@ int nth_packed_object_sha1(const struct packed_git *p, int n,
1201 void *index = p->index_base + 256;
1202 if (n < 0 || num_packed_objects(p) <= n)
1203 return -1;
1204 - memcpy(sha1, (char *) index + (24 * n) + 4, 20);
1204 + hashcpy(sha1, (unsigned char *) index + (24 * n) + 4);
1205 return 0;
1206 }
1207
@@ -1218,7 +1218,7 @@ int find_pack_entry_one(const unsigned char *sha1,
1218 int cmp = hashcmp((unsigned char *)index + (24 * mi) + 4, sha1);
1219 if (!cmp) {
1220 e->offset = ntohl(*((unsigned int *) ((char *) index + (24 * mi))));
1221 - memcpy(e->sha1, sha1, 20);
1221 + hashcpy(e->sha1, sha1);
1222 e->p = p;
1223 return 1;
1224 }
@@ -1331,7 +1331,7 @@ void *read_object_with_reference(const unsigned char *sha1,
1331 unsigned long isize;
1332 unsigned char actual_sha1[20];
1333
1334 - memcpy(actual_sha1, sha1, 20);
1334 + hashcpy(actual_sha1, sha1);
1335 while (1) {
1336 int ref_length = -1;
1337 const char *ref_type = NULL;
@@ -1342,7 +1342,7 @@ void *read_object_with_reference(const unsigned char *sha1,
1342 if (!strcmp(type, required_type)) {
1343 *size = isize;
1344 if (actual_sha1_return)
1345 - memcpy(actual_sha1_return, actual_sha1, 20);
1345 + hashcpy(actual_sha1_return, actual_sha1);
1346 return buffer;
1347 }
1348 /* Handle references */
@@ -1537,7 +1537,7 @@ int write_sha1_file(void *buf, unsigned long len, const char *type, unsigned cha
1537 */
1538 filename = write_sha1_file_prepare(buf, len, type, sha1, hdr, &hdrlen);
1539 if (returnsha1)
1540 - memcpy(returnsha1, sha1, 20);
1540 + hashcpy(returnsha1, sha1);
1541 if (has_sha1_file(sha1))
1542 return 0;
1543 fd = open(filename, O_RDONLY);
sha1_name.c
+11 -11
@@ -103,7 +103,7 @@ static int find_short_packed_object(int len, const unsigned char *match, unsigne
103 !match_sha(len, match, next)) {
104 /* unique within this pack */
105 if (!found) {
106 - memcpy(found_sha1, now, 20);
106 + hashcpy(found_sha1, now);
107 found++;
108 }
109 else if (hashcmp(found_sha1, now)) {
@@ -120,7 +120,7 @@ static int find_short_packed_object(int len, const unsigned char *match, unsigne
120 }
121 }
122 if (found == 1)
123 - memcpy(sha1, found_sha1, 20);
123 + hashcpy(sha1, found_sha1);
124 return found;
125 }
126
@@ -140,13 +140,13 @@ static int find_unique_short_object(int len, char *canonical,
140 if (1 < has_unpacked || 1 < has_packed)
141 return SHORT_NAME_AMBIGUOUS;
142 if (has_unpacked != has_packed) {
143 - memcpy(sha1, (has_packed ? packed_sha1 : unpacked_sha1), 20);
143 + hashcpy(sha1, (has_packed ? packed_sha1 : unpacked_sha1));
144 return 0;
145 }
146 /* Both have unique ones -- do they match? */
147 if (hashcmp(packed_sha1, unpacked_sha1))
148 return SHORT_NAME_AMBIGUOUS;
149 - memcpy(sha1, packed_sha1, 20);
149 + hashcpy(sha1, packed_sha1);
150 return 0;
151 }
152
@@ -320,13 +320,13 @@ static int get_parent(const char *name, int len,
320 if (parse_commit(commit))
321 return -1;
322 if (!idx) {
323 - memcpy(result, commit->object.sha1, 20);
323 + hashcpy(result, commit->object.sha1);
324 return 0;
325 }
326 p = commit->parents;
327 while (p) {
328 if (!--idx) {
329 - memcpy(result, p->item->object.sha1, 20);
329 + hashcpy(result, p->item->object.sha1);
330 return 0;
331 }
332 p = p->next;
@@ -347,9 +347,9 @@ static int get_nth_ancestor(const char *name, int len,
347
348 if (!commit || parse_commit(commit) || !commit->parents)
349 return -1;
350 - memcpy(sha1, commit->parents->item->object.sha1, 20);
350 + hashcpy(sha1, commit->parents->item->object.sha1);
351 }
352 - memcpy(result, sha1, 20);
352 + hashcpy(result, sha1);
353 return 0;
354 }
355
@@ -401,7 +401,7 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
401 o = deref_tag(o, name, sp - name - 2);
402 if (!o || (!o->parsed && !parse_object(o->sha1)))
403 return -1;
404 - memcpy(sha1, o->sha1, 20);
404 + hashcpy(sha1, o->sha1);
405 }
406 else {
407 /* At this point, the syntax look correct, so
@@ -413,7 +413,7 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
413 if (!o || (!o->parsed && !parse_object(o->sha1)))
414 return -1;
415 if (o->type == expected_type) {
416 - memcpy(sha1, o->sha1, 20);
416 + hashcpy(sha1, o->sha1);
417 return 0;
418 }
419 if (o->type == OBJ_TAG)
@@ -520,7 +520,7 @@ int get_sha1(const char *name, unsigned char *sha1)
520 memcmp(ce->name, cp, namelen))
521 break;
522 if (ce_stage(ce) == stage) {
523 - memcpy(sha1, ce->sha1, 20);
523 + hashcpy(sha1, ce->sha1);
524 return 0;
525 }
526 pos++;
tree-walk.c
+2 -2
@@ -179,7 +179,7 @@ static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char
179 if (cmp < 0)
180 break;
181 if (entrylen == namelen) {
182 - memcpy(result, sha1, 20);
182 + hashcpy(result, sha1);
183 return 0;
184 }
185 if (name[entrylen] != '/')
@@ -187,7 +187,7 @@ static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char
187 if (!S_ISDIR(*mode))
188 break;
189 if (++entrylen == namelen) {
190 - memcpy(result, sha1, 20);
190 + hashcpy(result, sha1);
191 return 0;
192 }
193 return get_tree_entry(sha1, name + entrylen, result, mode);
tree.c
+1 -1
@@ -25,7 +25,7 @@ static int read_one_entry(const unsigned char *sha1, const char *base, int basel
25 ce->ce_flags = create_ce_flags(baselen + len, stage);
26 memcpy(ce->name, base, baselen);
27 memcpy(ce->name + baselen, pathname, len+1);
28 - memcpy(ce->sha1, sha1, 20);
28 + hashcpy(ce->sha1, sha1);
29 return add_cache_entry(ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK);
30 }
31
unpack-trees.c
+1 -1
@@ -200,7 +200,7 @@ static int unpack_trees_rec(struct tree_entry_list **posns, int len,
200
201 any_files = 1;
202
203 - memcpy(ce->sha1, posns[i]->sha1, 20);
203 + hashcpy(ce->sha1, posns[i]->sha1);
204 src[i + o->merge] = ce;
205 subposns[i] = df_conflict_list;
206 posns[i] = posns[i]->next;
upload-pack.c
+1 -1
@@ -374,7 +374,7 @@ static int get_common_commits(void)
374 sha1_to_hex(sha1),
375 multi_ack ? " continue" : "");
376 if (multi_ack)
377 - memcpy(last_sha1, sha1, 20);
377 + hashcpy(last_sha1, sha1);
378 }
379 continue;
380 }