mirror of
https://github.com/git/git
synced 2024-08-27 11:39:22 +00:00
http-push: use an argv_array for setup_revisions
This drops the magic number for the fixed-size argv arrays, so we do not have to wonder if we are overflowing it. We can also drop some confusing sha1_to_hex memory allocation (which seems to predate the ring of buffers allowing multiple calls), and get rid of an unchecked sprintf call. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
984a43b902
commit
a0355f6bcd
32
http-push.c
32
http-push.c
|
@ -10,6 +10,7 @@
|
||||||
#include "remote.h"
|
#include "remote.h"
|
||||||
#include "list-objects.h"
|
#include "list-objects.h"
|
||||||
#include "sigchain.h"
|
#include "sigchain.h"
|
||||||
|
#include "argv-array.h"
|
||||||
|
|
||||||
#ifdef EXPAT_NEEDS_XMLPARSE_H
|
#ifdef EXPAT_NEEDS_XMLPARSE_H
|
||||||
#include <xmlparse.h>
|
#include <xmlparse.h>
|
||||||
|
@ -1856,9 +1857,7 @@ int main(int argc, char **argv)
|
||||||
new_refs = 0;
|
new_refs = 0;
|
||||||
for (ref = remote_refs; ref; ref = ref->next) {
|
for (ref = remote_refs; ref; ref = ref->next) {
|
||||||
char old_hex[60], *new_hex;
|
char old_hex[60], *new_hex;
|
||||||
const char *commit_argv[5];
|
struct argv_array commit_argv = ARGV_ARRAY_INIT;
|
||||||
int commit_argc;
|
|
||||||
char *new_sha1_hex, *old_sha1_hex;
|
|
||||||
|
|
||||||
if (!ref->peer_ref)
|
if (!ref->peer_ref)
|
||||||
continue;
|
continue;
|
||||||
|
@ -1937,27 +1936,15 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set up revision info for this refspec */
|
/* Set up revision info for this refspec */
|
||||||
commit_argc = 3;
|
argv_array_push(&commit_argv, ""); /* ignored */
|
||||||
new_sha1_hex = xstrdup(sha1_to_hex(ref->new_sha1));
|
argv_array_push(&commit_argv, "--objects");
|
||||||
old_sha1_hex = NULL;
|
argv_array_push(&commit_argv, sha1_to_hex(ref->new_sha1));
|
||||||
commit_argv[1] = "--objects";
|
if (!push_all && !is_null_sha1(ref->old_sha1))
|
||||||
commit_argv[2] = new_sha1_hex;
|
argv_array_pushf(&commit_argv, "^%s",
|
||||||
if (!push_all && !is_null_sha1(ref->old_sha1)) {
|
sha1_to_hex(ref->old_sha1));
|
||||||
old_sha1_hex = xmalloc(42);
|
|
||||||
sprintf(old_sha1_hex, "^%s",
|
|
||||||
sha1_to_hex(ref->old_sha1));
|
|
||||||
commit_argv[3] = old_sha1_hex;
|
|
||||||
commit_argc++;
|
|
||||||
}
|
|
||||||
commit_argv[commit_argc] = NULL;
|
|
||||||
init_revisions(&revs, setup_git_directory());
|
init_revisions(&revs, setup_git_directory());
|
||||||
setup_revisions(commit_argc, commit_argv, &revs, NULL);
|
setup_revisions(commit_argv.argc, commit_argv.argv, &revs, NULL);
|
||||||
revs.edge_hint = 0; /* just in case */
|
revs.edge_hint = 0; /* just in case */
|
||||||
free(new_sha1_hex);
|
|
||||||
if (old_sha1_hex) {
|
|
||||||
free(old_sha1_hex);
|
|
||||||
commit_argv[1] = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Generate a list of objects that need to be pushed */
|
/* Generate a list of objects that need to be pushed */
|
||||||
pushing = 0;
|
pushing = 0;
|
||||||
|
@ -1986,6 +1973,7 @@ int main(int argc, char **argv)
|
||||||
printf("%s %s\n", !rc ? "ok" : "error", ref->name);
|
printf("%s %s\n", !rc ? "ok" : "error", ref->name);
|
||||||
unlock_remote(ref_lock);
|
unlock_remote(ref_lock);
|
||||||
check_locks();
|
check_locks();
|
||||||
|
argv_array_clear(&commit_argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update remote server info if appropriate */
|
/* Update remote server info if appropriate */
|
||||||
|
|
Loading…
Reference in a new issue