Skip to content

Commit 0b282cc

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a0355f6 commit 0b282cc

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

remote.c

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "tag.h"
99
#include "string-list.h"
1010
#include "mergesort.h"
11+
#include "argv-array.h"
1112

1213
enum map_direction { FROM_SRC, FROM_DST };
1314

@@ -1997,10 +1998,9 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
19971998
{
19981999
unsigned char sha1[20];
19992000
struct commit *ours, *theirs;
2000-
char symmetric[84];
20012001
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;
20042004

20052005
/* Cannot stat unless we are marked to build on top of somebody else. */
20062006
base = branch_get_upstream(branch, NULL);
@@ -2029,19 +2029,15 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
20292029
}
20302030

20312031
/* 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, "--");
20422038

20432039
init_revisions(&revs, NULL);
2044-
setup_revisions(rev_argc, rev_argv, &revs, NULL);
2040+
setup_revisions(argv.argc, argv.argv, &revs, NULL);
20452041
if (prepare_revision_walk(&revs))
20462042
die("revision walk setup failed");
20472043

@@ -2061,6 +2057,8 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
20612057
/* clear object flags smudged by the above traversal */
20622058
clear_commit_marks(ours, ALL_REV_FLAGS);
20632059
clear_commit_marks(theirs, ALL_REV_FLAGS);
2060+
2061+
argv_array_clear(&argv);
20642062
return 0;
20652063
}
20662064

0 commit comments

Comments
 (0)