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>maint
parent
a0355f6bcd
commit
0b282cc4b2
26
remote.c
26
remote.c
|
@ -8,6 +8,7 @@
|
||||||
#include "tag.h"
|
#include "tag.h"
|
||||||
#include "string-list.h"
|
#include "string-list.h"
|
||||||
#include "mergesort.h"
|
#include "mergesort.h"
|
||||||
|
#include "argv-array.h"
|
||||||
|
|
||||||
enum map_direction { FROM_SRC, FROM_DST };
|
enum map_direction { FROM_SRC, FROM_DST };
|
||||||
|
|
||||||
|
@ -1997,10 +1998,9 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
|
||||||
{
|
{
|
||||||
unsigned char sha1[20];
|
unsigned char sha1[20];
|
||||||
struct commit *ours, *theirs;
|
struct commit *ours, *theirs;
|
||||||
char symmetric[84];
|
|
||||||
struct rev_info revs;
|
struct rev_info revs;
|
||||||
const char *rev_argv[10], *base;
|
const char *base;
|
||||||
int rev_argc;
|
struct argv_array argv = ARGV_ARRAY_INIT;
|
||||||
|
|
||||||
/* Cannot stat unless we are marked to build on top of somebody else. */
|
/* Cannot stat unless we are marked to build on top of somebody else. */
|
||||||
base = branch_get_upstream(branch, NULL);
|
base = branch_get_upstream(branch, NULL);
|
||||||
|
@ -2029,19 +2029,15 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Run "rev-list --left-right ours...theirs" internally... */
|
/* Run "rev-list --left-right ours...theirs" internally... */
|
||||||
rev_argc = 0;
|
argv_array_push(&argv, ""); /* ignored */
|
||||||
rev_argv[rev_argc++] = NULL;
|
argv_array_push(&argv, "--left-right");
|
||||||
rev_argv[rev_argc++] = "--left-right";
|
argv_array_pushf(&argv, "%s...%s",
|
||||||
rev_argv[rev_argc++] = symmetric;
|
sha1_to_hex(ours->object.sha1),
|
||||||
rev_argv[rev_argc++] = "--";
|
sha1_to_hex(theirs->object.sha1));
|
||||||
rev_argv[rev_argc] = NULL;
|
argv_array_push(&argv, "--");
|
||||||
|
|
||||||
strcpy(symmetric, sha1_to_hex(ours->object.sha1));
|
|
||||||
strcpy(symmetric + 40, "...");
|
|
||||||
strcpy(symmetric + 43, sha1_to_hex(theirs->object.sha1));
|
|
||||||
|
|
||||||
init_revisions(&revs, NULL);
|
init_revisions(&revs, NULL);
|
||||||
setup_revisions(rev_argc, rev_argv, &revs, NULL);
|
setup_revisions(argv.argc, argv.argv, &revs, NULL);
|
||||||
if (prepare_revision_walk(&revs))
|
if (prepare_revision_walk(&revs))
|
||||||
die("revision walk setup failed");
|
die("revision walk setup failed");
|
||||||
|
|
||||||
|
@ -2061,6 +2057,8 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
|
||||||
/* clear object flags smudged by the above traversal */
|
/* clear object flags smudged by the above traversal */
|
||||||
clear_commit_marks(ours, ALL_REV_FLAGS);
|
clear_commit_marks(ours, ALL_REV_FLAGS);
|
||||||
clear_commit_marks(theirs, ALL_REV_FLAGS);
|
clear_commit_marks(theirs, ALL_REV_FLAGS);
|
||||||
|
|
||||||
|
argv_array_clear(&argv);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue