Merge branch 'rs/code-cleaning'
* rs/code-cleaning: remote-testsvn: use internal argv_array of struct child_process in cmd_import() bundle: use internal argv_array of struct child_process in create_bundle() fast-import: use hashcmp() for SHA1 hash comparison transport: simplify fetch_objs_via_rsync() using argv_array run-command: use internal argv_array of struct child_process in run_hook_ve() use commit_list_count() to count the members of commit_lists strbuf: use strbuf_addstr() for adding C stringsmaint
commit
12621cb222
|
@ -1371,11 +1371,8 @@ static struct commit_list *first_scapegoat(struct rev_info *revs, struct commit
|
||||||
|
|
||||||
static int num_scapegoats(struct rev_info *revs, struct commit *commit)
|
static int num_scapegoats(struct rev_info *revs, struct commit *commit)
|
||||||
{
|
{
|
||||||
int cnt;
|
|
||||||
struct commit_list *l = first_scapegoat(revs, commit);
|
struct commit_list *l = first_scapegoat(revs, commit);
|
||||||
for (cnt = 0; l; l = l->next)
|
return commit_list_count(l);
|
||||||
cnt++;
|
|
||||||
return cnt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Distribute collected unsorted blames to the respected sorted lists
|
/* Distribute collected unsorted blames to the respected sorted lists
|
||||||
|
|
|
@ -702,7 +702,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
|
||||||
char *buffer;
|
char *buffer;
|
||||||
buffer = strstr(use_message_buffer, "\n\n");
|
buffer = strstr(use_message_buffer, "\n\n");
|
||||||
if (buffer)
|
if (buffer)
|
||||||
strbuf_add(&sb, buffer + 2, strlen(buffer + 2));
|
strbuf_addstr(&sb, buffer + 2);
|
||||||
hook_arg1 = "commit";
|
hook_arg1 = "commit";
|
||||||
hook_arg2 = use_message;
|
hook_arg2 = use_message;
|
||||||
} else if (fixup_message) {
|
} else if (fixup_message) {
|
||||||
|
|
|
@ -283,18 +283,6 @@ static void grab_tag_values(struct atom_value *val, int deref, struct object *ob
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int num_parents(struct commit *commit)
|
|
||||||
{
|
|
||||||
struct commit_list *parents;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0, parents = commit->parents;
|
|
||||||
parents;
|
|
||||||
parents = parents->next)
|
|
||||||
i++;
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* See grab_values */
|
/* See grab_values */
|
||||||
static void grab_commit_values(struct atom_value *val, int deref, struct object *obj, void *buf, unsigned long sz)
|
static void grab_commit_values(struct atom_value *val, int deref, struct object *obj, void *buf, unsigned long sz)
|
||||||
{
|
{
|
||||||
|
@ -315,12 +303,12 @@ static void grab_commit_values(struct atom_value *val, int deref, struct object
|
||||||
}
|
}
|
||||||
if (!strcmp(name, "numparent")) {
|
if (!strcmp(name, "numparent")) {
|
||||||
char *s = xmalloc(40);
|
char *s = xmalloc(40);
|
||||||
v->ul = num_parents(commit);
|
v->ul = commit_list_count(commit->parents);
|
||||||
sprintf(s, "%lu", v->ul);
|
sprintf(s, "%lu", v->ul);
|
||||||
v->s = s;
|
v->s = s;
|
||||||
}
|
}
|
||||||
else if (!strcmp(name, "parent")) {
|
else if (!strcmp(name, "parent")) {
|
||||||
int num = num_parents(commit);
|
int num = commit_list_count(commit->parents);
|
||||||
int i;
|
int i;
|
||||||
struct commit_list *parents;
|
struct commit_list *parents;
|
||||||
char *s = xmalloc(41 * num + 1);
|
char *s = xmalloc(41 * num + 1);
|
||||||
|
|
15
bundle.c
15
bundle.c
|
@ -237,8 +237,6 @@ int create_bundle(struct bundle_header *header, const char *path,
|
||||||
static struct lock_file lock;
|
static struct lock_file lock;
|
||||||
int bundle_fd = -1;
|
int bundle_fd = -1;
|
||||||
int bundle_to_stdout;
|
int bundle_to_stdout;
|
||||||
struct argv_array argv_boundary = ARGV_ARRAY_INIT;
|
|
||||||
struct argv_array argv_pack = ARGV_ARRAY_INIT;
|
|
||||||
int i, ref_count = 0;
|
int i, ref_count = 0;
|
||||||
struct strbuf buf = STRBUF_INIT;
|
struct strbuf buf = STRBUF_INIT;
|
||||||
struct rev_info revs;
|
struct rev_info revs;
|
||||||
|
@ -260,14 +258,12 @@ int create_bundle(struct bundle_header *header, const char *path,
|
||||||
init_revisions(&revs, NULL);
|
init_revisions(&revs, NULL);
|
||||||
|
|
||||||
/* write prerequisites */
|
/* write prerequisites */
|
||||||
argv_array_pushl(&argv_boundary,
|
memset(&rls, 0, sizeof(rls));
|
||||||
|
argv_array_pushl(&rls.args,
|
||||||
"rev-list", "--boundary", "--pretty=oneline",
|
"rev-list", "--boundary", "--pretty=oneline",
|
||||||
NULL);
|
NULL);
|
||||||
for (i = 1; i < argc; i++)
|
for (i = 1; i < argc; i++)
|
||||||
argv_array_push(&argv_boundary, argv[i]);
|
argv_array_push(&rls.args, argv[i]);
|
||||||
|
|
||||||
memset(&rls, 0, sizeof(rls));
|
|
||||||
rls.argv = argv_boundary.argv;
|
|
||||||
rls.out = -1;
|
rls.out = -1;
|
||||||
rls.git_cmd = 1;
|
rls.git_cmd = 1;
|
||||||
if (start_command(&rls))
|
if (start_command(&rls))
|
||||||
|
@ -382,12 +378,11 @@ int create_bundle(struct bundle_header *header, const char *path,
|
||||||
write_or_die(bundle_fd, "\n", 1);
|
write_or_die(bundle_fd, "\n", 1);
|
||||||
|
|
||||||
/* write pack */
|
/* write pack */
|
||||||
argv_array_pushl(&argv_pack,
|
memset(&rls, 0, sizeof(rls));
|
||||||
|
argv_array_pushl(&rls.args,
|
||||||
"pack-objects", "--all-progress-implied",
|
"pack-objects", "--all-progress-implied",
|
||||||
"--stdout", "--thin", "--delta-base-offset",
|
"--stdout", "--thin", "--delta-base-offset",
|
||||||
NULL);
|
NULL);
|
||||||
memset(&rls, 0, sizeof(rls));
|
|
||||||
rls.argv = argv_pack.argv;
|
|
||||||
rls.in = -1;
|
rls.in = -1;
|
||||||
rls.out = bundle_fd;
|
rls.out = bundle_fd;
|
||||||
rls.git_cmd = 1;
|
rls.git_cmd = 1;
|
||||||
|
|
7
commit.c
7
commit.c
|
@ -970,12 +970,7 @@ struct commit_list *get_merge_bases_many(struct commit *one,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* There are more than one */
|
/* There are more than one */
|
||||||
cnt = 0;
|
cnt = commit_list_count(result);
|
||||||
list = result;
|
|
||||||
while (list) {
|
|
||||||
list = list->next;
|
|
||||||
cnt++;
|
|
||||||
}
|
|
||||||
rslt = xcalloc(cnt, sizeof(*rslt));
|
rslt = xcalloc(cnt, sizeof(*rslt));
|
||||||
for (list = result, i = 0; list; list = list->next)
|
for (list = result, i = 0; list; list = list->next)
|
||||||
rslt[i++] = list->item;
|
rslt[i++] = list->item;
|
||||||
|
|
12
diff.c
12
diff.c
|
@ -525,9 +525,9 @@ static void emit_hunk_header(struct emit_callback *ecbdata,
|
||||||
ep += 2; /* skip over @@ */
|
ep += 2; /* skip over @@ */
|
||||||
|
|
||||||
/* The hunk header in fraginfo color */
|
/* The hunk header in fraginfo color */
|
||||||
strbuf_add(&msgbuf, frag, strlen(frag));
|
strbuf_addstr(&msgbuf, frag);
|
||||||
strbuf_add(&msgbuf, line, ep - line);
|
strbuf_add(&msgbuf, line, ep - line);
|
||||||
strbuf_add(&msgbuf, reset, strlen(reset));
|
strbuf_addstr(&msgbuf, reset);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* trailing "\r\n"
|
* trailing "\r\n"
|
||||||
|
@ -541,15 +541,15 @@ static void emit_hunk_header(struct emit_callback *ecbdata,
|
||||||
if (*ep != ' ' && *ep != '\t')
|
if (*ep != ' ' && *ep != '\t')
|
||||||
break;
|
break;
|
||||||
if (ep != cp) {
|
if (ep != cp) {
|
||||||
strbuf_add(&msgbuf, plain, strlen(plain));
|
strbuf_addstr(&msgbuf, plain);
|
||||||
strbuf_add(&msgbuf, cp, ep - cp);
|
strbuf_add(&msgbuf, cp, ep - cp);
|
||||||
strbuf_add(&msgbuf, reset, strlen(reset));
|
strbuf_addstr(&msgbuf, reset);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ep < line + len) {
|
if (ep < line + len) {
|
||||||
strbuf_add(&msgbuf, func, strlen(func));
|
strbuf_addstr(&msgbuf, func);
|
||||||
strbuf_add(&msgbuf, ep, line + len - ep);
|
strbuf_add(&msgbuf, ep, line + len - ep);
|
||||||
strbuf_add(&msgbuf, reset, strlen(reset));
|
strbuf_addstr(&msgbuf, reset);
|
||||||
}
|
}
|
||||||
|
|
||||||
strbuf_add(&msgbuf, line + len, org_len - len);
|
strbuf_add(&msgbuf, line + len, org_len - len);
|
||||||
|
|
|
@ -2324,7 +2324,7 @@ static void file_change_m(const char *p, struct branch *b)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Git does not track empty, non-toplevel directories. */
|
/* Git does not track empty, non-toplevel directories. */
|
||||||
if (S_ISDIR(mode) && !memcmp(sha1, EMPTY_TREE_SHA1_BIN, 20) && *p) {
|
if (S_ISDIR(mode) && !hashcmp(sha1, EMPTY_TREE_SHA1_BIN) && *p) {
|
||||||
tree_content_remove(&b->branch_tree, p, NULL, 0);
|
tree_content_remove(&b->branch_tree, p, NULL, 0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
13
line-log.c
13
line-log.c
|
@ -766,17 +766,6 @@ void line_log_init(struct rev_info *rev, const char *prefix, struct string_list
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int count_parents(struct commit *commit)
|
|
||||||
{
|
|
||||||
struct commit_list *parents = commit->parents;
|
|
||||||
int count = 0;
|
|
||||||
while (parents) {
|
|
||||||
count++;
|
|
||||||
parents = parents->next;
|
|
||||||
}
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void move_diff_queue(struct diff_queue_struct *dst,
|
static void move_diff_queue(struct diff_queue_struct *dst,
|
||||||
struct diff_queue_struct *src)
|
struct diff_queue_struct *src)
|
||||||
{
|
{
|
||||||
|
@ -1150,7 +1139,7 @@ static int process_ranges_merge_commit(struct rev_info *rev, struct commit *comm
|
||||||
struct commit **parents;
|
struct commit **parents;
|
||||||
struct commit_list *p;
|
struct commit_list *p;
|
||||||
int i;
|
int i;
|
||||||
int nparents = count_parents(commit);
|
int nparents = commit_list_count(commit->parents);
|
||||||
|
|
||||||
diffqueues = xmalloc(nparents * sizeof(*diffqueues));
|
diffqueues = xmalloc(nparents * sizeof(*diffqueues));
|
||||||
cand = xmalloc(nparents * sizeof(*cand));
|
cand = xmalloc(nparents * sizeof(*cand));
|
||||||
|
|
6
path.c
6
path.c
|
@ -275,16 +275,16 @@ char *expand_user_path(const char *path)
|
||||||
const char *home = getenv("HOME");
|
const char *home = getenv("HOME");
|
||||||
if (!home)
|
if (!home)
|
||||||
goto return_null;
|
goto return_null;
|
||||||
strbuf_add(&user_path, home, strlen(home));
|
strbuf_addstr(&user_path, home);
|
||||||
} else {
|
} else {
|
||||||
struct passwd *pw = getpw_str(username, username_len);
|
struct passwd *pw = getpw_str(username, username_len);
|
||||||
if (!pw)
|
if (!pw)
|
||||||
goto return_null;
|
goto return_null;
|
||||||
strbuf_add(&user_path, pw->pw_dir, strlen(pw->pw_dir));
|
strbuf_addstr(&user_path, pw->pw_dir);
|
||||||
}
|
}
|
||||||
to_copy = first_slash;
|
to_copy = first_slash;
|
||||||
}
|
}
|
||||||
strbuf_add(&user_path, to_copy, strlen(to_copy));
|
strbuf_addstr(&user_path, to_copy);
|
||||||
return strbuf_detach(&user_path, NULL);
|
return strbuf_detach(&user_path, NULL);
|
||||||
return_null:
|
return_null:
|
||||||
strbuf_release(&user_path);
|
strbuf_release(&user_path);
|
||||||
|
|
7
pretty.c
7
pretty.c
|
@ -1554,12 +1554,7 @@ static void pp_header(struct pretty_print_context *pp,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!parents_shown) {
|
if (!parents_shown) {
|
||||||
struct commit_list *parent;
|
unsigned num = commit_list_count(commit->parents);
|
||||||
int num;
|
|
||||||
for (parent = commit->parents, num = 0;
|
|
||||||
parent;
|
|
||||||
parent = parent->next, num++)
|
|
||||||
;
|
|
||||||
/* with enough slop */
|
/* with enough slop */
|
||||||
strbuf_grow(sb, num * 50 + 20);
|
strbuf_grow(sb, num * 50 + 20);
|
||||||
add_merge_info(pp, sb, commit);
|
add_merge_info(pp, sb, commit);
|
||||||
|
|
|
@ -175,8 +175,8 @@ static int cmd_import(const char *line)
|
||||||
char *note_msg;
|
char *note_msg;
|
||||||
unsigned char head_sha1[20];
|
unsigned char head_sha1[20];
|
||||||
unsigned int startrev;
|
unsigned int startrev;
|
||||||
struct argv_array svndump_argv = ARGV_ARRAY_INIT;
|
|
||||||
struct child_process svndump_proc;
|
struct child_process svndump_proc;
|
||||||
|
const char *command = "svnrdump";
|
||||||
|
|
||||||
if (read_ref(private_ref, head_sha1))
|
if (read_ref(private_ref, head_sha1))
|
||||||
startrev = 0;
|
startrev = 0;
|
||||||
|
@ -202,15 +202,14 @@ static int cmd_import(const char *line)
|
||||||
} else {
|
} else {
|
||||||
memset(&svndump_proc, 0, sizeof(struct child_process));
|
memset(&svndump_proc, 0, sizeof(struct child_process));
|
||||||
svndump_proc.out = -1;
|
svndump_proc.out = -1;
|
||||||
argv_array_push(&svndump_argv, "svnrdump");
|
argv_array_push(&svndump_proc.args, command);
|
||||||
argv_array_push(&svndump_argv, "dump");
|
argv_array_push(&svndump_proc.args, "dump");
|
||||||
argv_array_push(&svndump_argv, url);
|
argv_array_push(&svndump_proc.args, url);
|
||||||
argv_array_pushf(&svndump_argv, "-r%u:HEAD", startrev);
|
argv_array_pushf(&svndump_proc.args, "-r%u:HEAD", startrev);
|
||||||
svndump_proc.argv = svndump_argv.argv;
|
|
||||||
|
|
||||||
code = start_command(&svndump_proc);
|
code = start_command(&svndump_proc);
|
||||||
if (code)
|
if (code)
|
||||||
die("Unable to start %s, code %d", svndump_proc.argv[0], code);
|
die("Unable to start %s, code %d", command, code);
|
||||||
dumpin_fd = svndump_proc.out;
|
dumpin_fd = svndump_proc.out;
|
||||||
}
|
}
|
||||||
/* setup marks file import/export */
|
/* setup marks file import/export */
|
||||||
|
@ -226,8 +225,7 @@ static int cmd_import(const char *line)
|
||||||
if (!dump_from_file) {
|
if (!dump_from_file) {
|
||||||
code = finish_command(&svndump_proc);
|
code = finish_command(&svndump_proc);
|
||||||
if (code)
|
if (code)
|
||||||
warning("%s, returned %d", svndump_proc.argv[0], code);
|
warning("%s, returned %d", command, code);
|
||||||
argv_array_clear(&svndump_argv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -770,28 +770,21 @@ char *find_hook(const char *name)
|
||||||
int run_hook_ve(const char *const *env, const char *name, va_list args)
|
int run_hook_ve(const char *const *env, const char *name, va_list args)
|
||||||
{
|
{
|
||||||
struct child_process hook;
|
struct child_process hook;
|
||||||
struct argv_array argv = ARGV_ARRAY_INIT;
|
|
||||||
const char *p;
|
const char *p;
|
||||||
int ret;
|
|
||||||
|
|
||||||
p = find_hook(name);
|
p = find_hook(name);
|
||||||
if (!p)
|
if (!p)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
argv_array_push(&argv, p);
|
|
||||||
|
|
||||||
while ((p = va_arg(args, const char *)))
|
|
||||||
argv_array_push(&argv, p);
|
|
||||||
|
|
||||||
memset(&hook, 0, sizeof(hook));
|
memset(&hook, 0, sizeof(hook));
|
||||||
hook.argv = argv.argv;
|
argv_array_push(&hook.args, p);
|
||||||
|
while ((p = va_arg(args, const char *)))
|
||||||
|
argv_array_push(&hook.args, p);
|
||||||
hook.env = env;
|
hook.env = env;
|
||||||
hook.no_stdin = 1;
|
hook.no_stdin = 1;
|
||||||
hook.stdout_to_stderr = 1;
|
hook.stdout_to_stderr = 1;
|
||||||
|
|
||||||
ret = run_command(&hook);
|
return run_command(&hook);
|
||||||
argv_array_clear(&argv);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int run_hook_le(const char *const *env, const char *name, ...)
|
int run_hook_le(const char *const *env, const char *name, ...)
|
||||||
|
|
28
transport.c
28
transport.c
|
@ -263,32 +263,20 @@ static struct ref *get_refs_via_rsync(struct transport *transport, int for_push)
|
||||||
static int fetch_objs_via_rsync(struct transport *transport,
|
static int fetch_objs_via_rsync(struct transport *transport,
|
||||||
int nr_objs, struct ref **to_fetch)
|
int nr_objs, struct ref **to_fetch)
|
||||||
{
|
{
|
||||||
struct strbuf buf = STRBUF_INIT;
|
|
||||||
struct child_process rsync;
|
struct child_process rsync;
|
||||||
const char *args[8];
|
|
||||||
int result;
|
|
||||||
|
|
||||||
strbuf_addstr(&buf, rsync_url(transport->url));
|
|
||||||
strbuf_addstr(&buf, "/objects/");
|
|
||||||
|
|
||||||
memset(&rsync, 0, sizeof(rsync));
|
memset(&rsync, 0, sizeof(rsync));
|
||||||
rsync.argv = args;
|
|
||||||
rsync.stdout_to_stderr = 1;
|
rsync.stdout_to_stderr = 1;
|
||||||
args[0] = "rsync";
|
argv_array_push(&rsync.args, "rsync");
|
||||||
args[1] = (transport->verbose > 1) ? "-rv" : "-r";
|
argv_array_push(&rsync.args, (transport->verbose > 1) ? "-rv" : "-r");
|
||||||
args[2] = "--ignore-existing";
|
argv_array_push(&rsync.args, "--ignore-existing");
|
||||||
args[3] = "--exclude";
|
argv_array_push(&rsync.args, "--exclude");
|
||||||
args[4] = "info";
|
argv_array_push(&rsync.args, "info");
|
||||||
args[5] = buf.buf;
|
argv_array_pushf(&rsync.args, "%s/objects/", rsync_url(transport->url));
|
||||||
args[6] = get_object_directory();
|
argv_array_push(&rsync.args, get_object_directory());
|
||||||
args[7] = NULL;
|
|
||||||
|
|
||||||
/* NEEDSWORK: handle one level of alternates */
|
/* NEEDSWORK: handle one level of alternates */
|
||||||
result = run_command(&rsync);
|
return run_command(&rsync);
|
||||||
|
|
||||||
strbuf_release(&buf);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int write_one_ref(const char *name, const unsigned char *sha1,
|
static int write_one_ref(const char *name, const unsigned char *sha1,
|
||||||
|
|
Loading…
Reference in New Issue