drop strcpy in favor of raw sha1_to_hex

In some cases where we strcpy() the result of sha1_to_hex(), there's no need; the result goes directly into a printf statement, and we can simply pass the return value from sha1_to_hex() directly. When this code was originally written, sha1_to_hex used a single buffer, and it was not safe to use it twice within a single expression. That changed as of dcb3450 (sha1_to_hex() usage cleanup, 2006-05-03), but this code was never updated. History-dug-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Sep 24, 2015 at 17:08 UTC 2b87d3a89633fb6078203a77d2610175f94cef95
2 files changed +4 -7
http-push.c
+2 -4
@@ -1856,7 +1856,6 @@ int main(int argc, char **argv)
1856
1857 new_refs = 0;
1858 for (ref = remote_refs; ref; ref = ref->next) {
1859 - char old_hex[60], *new_hex;
1859 struct argv_array commit_argv = ARGV_ARRAY_INIT;
1860
1861 if (!ref->peer_ref)
@@ -1911,13 +1910,12 @@ int main(int argc, char **argv)
1910 }
1911 hashcpy(ref->new_sha1, ref->peer_ref->new_sha1);
1912 new_refs++;
1914 - strcpy(old_hex, sha1_to_hex(ref->old_sha1));
1915 - new_hex = sha1_to_hex(ref->new_sha1);
1913
1914 fprintf(stderr, "updating '%s'", ref->name);
1915 if (strcmp(ref->name, ref->peer_ref->name))
1916 fprintf(stderr, " using '%s'", ref->peer_ref->name);
1920 - fprintf(stderr, "\n from %s\n to %s\n", old_hex, new_hex);
1917 + fprintf(stderr, "\n from %s\n to %s\n",
1918 + sha1_to_hex(ref->old_sha1), sha1_to_hex(ref->new_sha1));
1919 if (dry_run) {
1920 if (helper_status)
1921 printf("ok %s\n", ref->name);
walker.c
+2 -3
@@ -17,10 +17,9 @@ void walker_say(struct walker *walker, const char *fmt, const char *hex)
17
18 static void report_missing(const struct object *obj)
19 {
20 - char missing_hex[41];
21 - strcpy(missing_hex, sha1_to_hex(obj->sha1));
20 fprintf(stderr, "Cannot obtain needed %s %s\n",
23 - obj->type ? typename(obj->type): "object", missing_hex);
21 + obj->type ? typename(obj->type): "object",
22 + sha1_to_hex(obj->sha1));
23 if (!is_null_sha1(current_commit_sha1))
24 fprintf(stderr, "while processing commit %s.\n",
25 sha1_to_hex(current_commit_sha1));