Use hashcpy() when copying object names
We invented hashcpy() to keep the abstraction of "object name" behind it. Use it instead of calling memcpy() with hard-coded 20-byte length when moving object names between pieces of memory. Leave ppc/sha1.c as-is, because the function is about the SHA-1 hash algorithm whose output is and will always be 20 bytes. Helped-by: Michael Haggerty <mhagger@alum.mit.edu> Helped-by: Duy Nguyen <pclouds@gmail.com> Signed-off-by: Sun He <sunheehnus@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Sun He committed
Mar 3, 2014 at 17:39 UTC
50546b15ed1df25837f8b291e6fa5bbcdb84635e
5 files changed
+6
-6
bundle.c
+1
-1
@@ -19,7 +19,7 @@ static void add_to_ref_list(const unsigned char *sha1, const char *name,
19
list->list = xrealloc(list->list,
20
list->alloc * sizeof(list->list[0]));
21
}
22
- memcpy(list->list[list->nr].sha1, sha1, 20);
22
+ hashcpy(list->list[list->nr].sha1, sha1);
23
list->list[list->nr].name = xstrdup(name);
24
list->nr++;
25
}
grep.c
+1
-1
@@ -1650,7 +1650,7 @@ void grep_source_init(struct grep_source *gs, enum grep_source_type type,
1650
break;
1651
case GREP_SOURCE_SHA1:
1652
gs->identifier = xmalloc(20);
1653
- memcpy(gs->identifier, identifier, 20);
1653
+ hashcpy(gs->identifier, identifier);
1654
break;
1655
case GREP_SOURCE_BUF:
1656
gs->identifier = NULL;
pack-bitmap-write.c
+1
-1
@@ -530,7 +530,7 @@ void bitmap_writer_finish(struct pack_idx_entry **index,
530
header.version = htons(default_version);
531
header.options = htons(flags | options);
532
header.entry_count = htonl(writer.selected_nr);
533
- memcpy(header.checksum, writer.pack_checksum, 20);
533
+ hashcpy(header.checksum, writer.pack_checksum);
534
535
sha1write(f, &header, sizeof(header));
536
dump_bitmap(f, writer.commits);
reflog-walk.c
+2
-2
@@ -32,8 +32,8 @@ static int read_one_reflog(unsigned char *osha1, unsigned char *nsha1,
32
sizeof(struct reflog_info));
33
}
34
item = array->items + array->nr;
35
- memcpy(item->osha1, osha1, 20);
36
- memcpy(item->nsha1, nsha1, 20);
35
+ hashcpy(item->osha1, osha1);
36
+ hashcpy(item->nsha1, nsha1);
37
item->email = xstrdup(email);
38
item->timestamp = timestamp;
39
item->tz = tz;
refs.c
+1
-1
@@ -1222,7 +1222,7 @@ static int resolve_gitlink_packed_ref(struct ref_cache *refs,
1222
if (ref == NULL)
1223
return -1;
1224
1225
- memcpy(sha1, ref->u.value.sha1, 20);
1225
+ hashcpy(sha1, ref->u.value.sha1);
1226
return 0;
1227
}
1228