stat_tracking_info: convert to argv_array
In addition to dropping the magic number for the fixed-size argv, we can also drop a fixed-length buffer and some strcpy's into it. 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:07 UTC
0b282cc4b2ceaf2f7f3376f0303f63e9d02fdc91
1 file changed
+12
-14
remote.c
+12
-14
@@ -8,6 +8,7 @@
8
#include "tag.h"
9
#include "string-list.h"
10
#include "mergesort.h"
11
+#include "argv-array.h"
12
13
enum map_direction { FROM_SRC, FROM_DST };
14
@@ -1997,10 +1998,9 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
1998
{
1999
unsigned char sha1[20];
2000
struct commit *ours, *theirs;
2000
- char symmetric[84];
2001
struct rev_info revs;
2002
- const char *rev_argv[10], *base;
2003
- int rev_argc;
2002
+ const char *base;
2003
+ struct argv_array argv = ARGV_ARRAY_INIT;
2004
2005
/* Cannot stat unless we are marked to build on top of somebody else. */
2006
base = branch_get_upstream(branch, NULL);
@@ -2029,19 +2029,15 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
2029
}
2030
2031
/* Run "rev-list --left-right ours...theirs" internally... */
2032
- rev_argc = 0;
2033
- rev_argv[rev_argc++] = NULL;
2034
- rev_argv[rev_argc++] = "--left-right";
2035
- rev_argv[rev_argc++] = symmetric;
2036
- rev_argv[rev_argc++] = "--";
2037
- rev_argv[rev_argc] = NULL;
2038
-
2039
- strcpy(symmetric, sha1_to_hex(ours->object.sha1));
2040
- strcpy(symmetric + 40, "...");
2041
- strcpy(symmetric + 43, sha1_to_hex(theirs->object.sha1));
2032
+ argv_array_push(&argv, ""); /* ignored */
2033
+ argv_array_push(&argv, "--left-right");
2034
+ argv_array_pushf(&argv, "%s...%s",
2035
+ sha1_to_hex(ours->object.sha1),
2036
+ sha1_to_hex(theirs->object.sha1));
2037
+ argv_array_push(&argv, "--");
2038
2039
init_revisions(&revs, NULL);
2044
- setup_revisions(rev_argc, rev_argv, &revs, NULL);
2040
+ setup_revisions(argv.argc, argv.argv, &revs, NULL);
2041
if (prepare_revision_walk(&revs))
2042
die("revision walk setup failed");
2043
@@ -2061,6 +2057,8 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
2057
/* clear object flags smudged by the above traversal */
2058
clear_commit_marks(ours, ALL_REV_FLAGS);
2059
clear_commit_marks(theirs, ALL_REV_FLAGS);
2060
+
2061
+ argv_array_clear(&argv);
2062
return 0;
2063
}
2064