|
10 | 10 | #include "remote.h"
|
11 | 11 | #include "list-objects.h"
|
12 | 12 | #include "sigchain.h"
|
| 13 | +#include "argv-array.h" |
13 | 14 |
|
14 | 15 | #ifdef EXPAT_NEEDS_XMLPARSE_H
|
15 | 16 | #include <xmlparse.h>
|
@@ -1856,9 +1857,7 @@ int main(int argc, char **argv)
|
1856 | 1857 | new_refs = 0;
|
1857 | 1858 | for (ref = remote_refs; ref; ref = ref->next) {
|
1858 | 1859 | char old_hex[60], *new_hex;
|
1859 |
| - const char *commit_argv[5]; |
1860 |
| - int commit_argc; |
1861 |
| - char *new_sha1_hex, *old_sha1_hex; |
| 1860 | + struct argv_array commit_argv = ARGV_ARRAY_INIT; |
1862 | 1861 |
|
1863 | 1862 | if (!ref->peer_ref)
|
1864 | 1863 | continue;
|
@@ -1937,27 +1936,15 @@ int main(int argc, char **argv)
|
1937 | 1936 | }
|
1938 | 1937 |
|
1939 | 1938 | /* Set up revision info for this refspec */
|
1940 |
| - commit_argc = 3; |
1941 |
| - new_sha1_hex = xstrdup(sha1_to_hex(ref->new_sha1)); |
1942 |
| - old_sha1_hex = NULL; |
1943 |
| - commit_argv[1] = "--objects"; |
1944 |
| - commit_argv[2] = new_sha1_hex; |
1945 |
| - if (!push_all && !is_null_sha1(ref->old_sha1)) { |
1946 |
| - old_sha1_hex = xmalloc(42); |
1947 |
| - sprintf(old_sha1_hex, "^%s", |
1948 |
| - sha1_to_hex(ref->old_sha1)); |
1949 |
| - commit_argv[3] = old_sha1_hex; |
1950 |
| - commit_argc++; |
1951 |
| - } |
1952 |
| - commit_argv[commit_argc] = NULL; |
| 1939 | + argv_array_push(&commit_argv, ""); /* ignored */ |
| 1940 | + argv_array_push(&commit_argv, "--objects"); |
| 1941 | + argv_array_push(&commit_argv, sha1_to_hex(ref->new_sha1)); |
| 1942 | + if (!push_all && !is_null_sha1(ref->old_sha1)) |
| 1943 | + argv_array_pushf(&commit_argv, "^%s", |
| 1944 | + sha1_to_hex(ref->old_sha1)); |
1953 | 1945 | init_revisions(&revs, setup_git_directory());
|
1954 |
| - setup_revisions(commit_argc, commit_argv, &revs, NULL); |
| 1946 | + setup_revisions(commit_argv.argc, commit_argv.argv, &revs, NULL); |
1955 | 1947 | revs.edge_hint = 0; /* just in case */
|
1956 |
| - free(new_sha1_hex); |
1957 |
| - if (old_sha1_hex) { |
1958 |
| - free(old_sha1_hex); |
1959 |
| - commit_argv[1] = NULL; |
1960 |
| - } |
1961 | 1948 |
|
1962 | 1949 | /* Generate a list of objects that need to be pushed */
|
1963 | 1950 | pushing = 0;
|
@@ -1986,6 +1973,7 @@ int main(int argc, char **argv)
|
1986 | 1973 | printf("%s %s\n", !rc ? "ok" : "error", ref->name);
|
1987 | 1974 | unlock_remote(ref_lock);
|
1988 | 1975 | check_locks();
|
| 1976 | + argv_array_clear(&commit_argv); |
1989 | 1977 | }
|
1990 | 1978 |
|
1991 | 1979 | /* Update remote server info if appropriate */
|
|
0 commit comments