From: Junio C Hamano Date: Fri, 20 Mar 2015 20:11:52 +0000 (-0700) Subject: Merge branch 'rs/use-isxdigit' X-Git-Tag: v2.4.0-rc0~31 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/daea6fca3564e880dfe29bfab65fd5b608e9491d?hp=-c Merge branch 'rs/use-isxdigit' Code cleanup. * rs/use-isxdigit: use isxdigit() for checking if a character is a hexadecimal digit --- daea6fca3564e880dfe29bfab65fd5b608e9491d diff --combined sha1_name.c index 95f9f8fa1a,dc85aafeca..6d10f052b5 --- a/sha1_name.c +++ b/sha1_name.c @@@ -372,10 -372,10 +372,10 @@@ const char *find_unique_abbrev(const un int status, exists; static char hex[41]; - exists = has_sha1_file(sha1); memcpy(hex, sha1_to_hex(sha1), 40); if (len == 40 || !len) return hex; + exists = has_sha1_file(sha1); while (len < 40) { unsigned char sha1_ret[20]; status = get_short_sha1(hex, len, sha1_ret, GET_SHA1_QUIETLY); @@@ -432,8 -432,7 +432,8 @@@ static inline int upstream_mark(const c static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned lookup_flags); static int interpret_nth_prior_checkout(const char *name, int namelen, struct strbuf *buf); -static int get_sha1_basic(const char *str, int len, unsigned char *sha1) +static int get_sha1_basic(const char *str, int len, unsigned char *sha1, + unsigned int flags) { static const char *warn_msg = "refname '%.*s' is ambiguous."; static const char *object_name_msg = N_( @@@ -512,7 -511,7 +512,7 @@@ if (!refs_found) return -1; - if (warn_ambiguous_refs && + if (warn_ambiguous_refs && !(flags & GET_SHA1_QUIETLY) && (refs_found > 1 || !get_short_sha1(str, len, tmp_sha1, GET_SHA1_QUIETLY))) warning(warn_msg, len, str); @@@ -541,12 -540,10 +541,12 @@@ char *tmp = xstrndup(str + at + 2, reflog_len); at_time = approxidate_careful(tmp, &errors); free(tmp); - if (errors) + if (errors) { + free(real_ref); return -1; + } } - if (read_ref_at(real_ref, at_time, nth, sha1, NULL, + if (read_ref_at(real_ref, flags, at_time, nth, sha1, NULL, &co_time, &co_tz, &co_cnt)) { if (!len) { if (starts_with(real_ref, "refs/heads/")) { @@@ -558,16 -555,11 +558,16 @@@ len = 4; } } - if (at_time) - warning("Log for '%.*s' only goes " - "back to %s.", len, str, - show_date(co_time, co_tz, DATE_RFC2822)); - else { + if (at_time) { + if (!(flags & GET_SHA1_QUIETLY)) { + warning("Log for '%.*s' only goes " + "back to %s.", len, str, + show_date(co_time, co_tz, DATE_RFC2822)); + } + } else { + if (flags & GET_SHA1_QUIETLY) { + exit(128); + } die("Log for '%.*s' only has %d entries.", len, str, co_cnt); } @@@ -757,7 -749,7 +757,7 @@@ static int get_describe_name(const cha for (cp = name + len - 1; name + 2 <= cp; cp--) { char ch = *cp; - if (hexval(ch) & ~0377) { + if (!isxdigit(ch)) { /* We must be looking at g in "SOMETHING-g" * for it to be describe output. */ @@@ -807,7 -799,7 +807,7 @@@ static int get_sha1_1(const char *name if (!ret) return 0; - ret = get_sha1_basic(name, len, sha1); + ret = get_sha1_basic(name, len, sha1, lookup_flags); if (!ret) return 0; @@@ -845,7 -837,7 +845,7 @@@ static int handle_one_ref(const char *p } if (object->type != OBJ_COMMIT) return 0; - commit_list_insert_by_date((struct commit *)object, list); + commit_list_insert((struct commit *)object, list); return 0; } @@@ -909,8 -901,10 +909,8 @@@ static int grab_nth_branch_switch(unsig const char *match = NULL, *target = NULL; size_t len; - if (starts_with(message, "checkout: moving from ")) { - match = message + strlen("checkout: moving from "); + if (skip_prefix(message, "checkout: moving from ", &match)) target = strstr(match, " to "); - } if (!match || !target) return 0; @@@ -954,7 -948,7 +954,7 @@@ static int interpret_nth_prior_checkout retval = 0; if (0 < for_each_reflog_ent_reverse("HEAD", grab_nth_branch_switch, &cb)) { strbuf_reset(buf); - strbuf_add(buf, cb.buf.buf, cb.buf.len); + strbuf_addbuf(buf, &cb.buf); retval = brace - name + 1; } @@@ -993,7 -987,7 +993,7 @@@ int get_sha1_mb(const char *name, unsig two = lookup_commit_reference_gently(sha1_tmp, 0); if (!two) return -1; - mbs = get_merge_bases(one, two, 1); + mbs = get_merge_bases(one, two); if (!mbs || mbs->next) st = -1; else { @@@ -1248,7 -1242,10 +1248,7 @@@ static void diagnose_invalid_sha1_path( die("Path '%s' exists on disk, but not in '%.*s'.", filename, object_name_len, object_name); if (errno == ENOENT || errno == ENOTDIR) { - char *fullname = xmalloc(strlen(filename) - + strlen(prefix) + 1); - strcpy(fullname, prefix); - strcat(fullname, filename); + char *fullname = xstrfmt("%s%s", prefix, filename); if (!get_tree_entry(tree_sha1, fullname, sha1, &mode)) { @@@ -1372,7 -1369,6 +1372,7 @@@ static int get_sha1_with_context_1(cons if (!only_to_die && namelen > 2 && name[1] == '/') { struct commit_list *list = NULL; for_each_ref(handle_one_ref, &list); + commit_list_sort_by_date(&list); return get_sha1_oneline(name + 2, sha1, list); } if (namelen < 3 || @@@ -1391,7 -1387,9 +1391,7 @@@ namelen = strlen(cp); } - strncpy(oc->path, cp, - sizeof(oc->path)); - oc->path[sizeof(oc->path)-1] = '\0'; + strlcpy(oc->path, cp, sizeof(oc->path)); if (!active_cache) read_cache(); @@@ -1441,7 -1439,9 +1441,7 @@@ name, len); } hashcpy(oc->tree, tree_sha1); - strncpy(oc->path, filename, - sizeof(oc->path)); - oc->path[sizeof(oc->path)-1] = '\0'; + strlcpy(oc->path, filename, sizeof(oc->path)); free(new_filename); return ret; diff --combined transport.c index 0694a7cf3e,7ac0df21ea..00f39d9f5b --- a/transport.c +++ b/transport.c @@@ -117,7 -117,7 +117,7 @@@ static void insert_packed_refs(const ch return; } - if (hexval(buffer[0]) > 0xf) + if (!isxdigit(buffer[0])) continue; len = strlen(buffer); if (len && buffer[len - 1] == '\n') @@@ -168,8 -168,7 +168,8 @@@ static void set_upstreams(struct transp /* Follow symbolic refs (mainly for HEAD). */ localname = ref->peer_ref->name; remotename = ref->name; - tmp = resolve_ref_unsafe(localname, sha, 1, &flag); + tmp = resolve_ref_unsafe(localname, RESOLVE_REF_READING, + sha, &flag); if (tmp && flag & REF_ISSYMREF && starts_with(tmp, "refs/heads/")) localname = tmp; @@@ -193,16 -192,14 +193,16 @@@ static const char *rsync_url(const char *url) { - return !starts_with(url, "rsync://") ? skip_prefix(url, "rsync:") : url; + if (!starts_with(url, "rsync://")) + skip_prefix(url, "rsync:", &url); + return url; } static struct ref *get_refs_via_rsync(struct transport *transport, int for_push) { struct strbuf buf = STRBUF_INIT, temp_dir = STRBUF_INIT; struct ref dummy = {NULL}, *tail = &dummy; - struct child_process rsync; + struct child_process rsync = CHILD_PROCESS_INIT; const char *args[5]; int temp_dir_len; @@@ -219,6 -216,7 +219,6 @@@ strbuf_addstr(&buf, rsync_url(transport->url)); strbuf_addstr(&buf, "/refs"); - memset(&rsync, 0, sizeof(rsync)); rsync.argv = args; rsync.stdout_to_stderr = 1; args[0] = "rsync"; @@@ -263,19 -261,32 +263,19 @@@ static int fetch_objs_via_rsync(struct transport *transport, int nr_objs, struct ref **to_fetch) { - struct strbuf buf = STRBUF_INIT; - struct child_process rsync; - const char *args[8]; - int result; + struct child_process rsync = CHILD_PROCESS_INIT; - strbuf_addstr(&buf, rsync_url(transport->url)); - strbuf_addstr(&buf, "/objects/"); - - memset(&rsync, 0, sizeof(rsync)); - rsync.argv = args; rsync.stdout_to_stderr = 1; - args[0] = "rsync"; - args[1] = (transport->verbose > 1) ? "-rv" : "-r"; - args[2] = "--ignore-existing"; - args[3] = "--exclude"; - args[4] = "info"; - args[5] = buf.buf; - args[6] = get_object_directory(); - args[7] = NULL; + argv_array_push(&rsync.args, "rsync"); + argv_array_push(&rsync.args, (transport->verbose > 1) ? "-rv" : "-r"); + argv_array_push(&rsync.args, "--ignore-existing"); + argv_array_push(&rsync.args, "--exclude"); + argv_array_push(&rsync.args, "info"); + argv_array_pushf(&rsync.args, "%s/objects/", rsync_url(transport->url)); + argv_array_push(&rsync.args, get_object_directory()); /* NEEDSWORK: handle one level of alternates */ - result = run_command(&rsync); - - strbuf_release(&buf); - - return result; + return run_command(&rsync); } static int write_one_ref(const char *name, const unsigned char *sha1, @@@ -326,7 -337,7 +326,7 @@@ static int rsync_transport_push(struct { struct strbuf buf = STRBUF_INIT, temp_dir = STRBUF_INIT; int result = 0, i; - struct child_process rsync; + struct child_process rsync = CHILD_PROCESS_INIT; const char *args[10]; if (flags & TRANSPORT_PUSH_MIRROR) @@@ -337,6 -348,7 +337,6 @@@ strbuf_addstr(&buf, rsync_url(transport->url)); strbuf_addch(&buf, '/'); - memset(&rsync, 0, sizeof(rsync)); rsync.argv = args; rsync.stdout_to_stderr = 1; i = 0; @@@ -478,9 -490,6 +478,9 @@@ static int set_git_option(struct git_tr die("transport: invalid depth option '%s'", value); } return 0; + } else if (!strcmp(name, TRANS_OPT_PUSH_CERT)) { + opts->push_cert = !!value; + return 0; } return 1; } @@@ -728,10 -737,6 +728,10 @@@ static int print_one_push_status(struc ref->deletion ? NULL : ref->peer_ref, "remote failed to report status", porcelain); break; + case REF_STATUS_ATOMIC_PUSH_FAILED: + print_ref_status('!', "[rejected]", ref, ref->peer_ref, + "atomic push failed", porcelain); + break; case REF_STATUS_OK: print_ok_ref_status(ref, porcelain); break; @@@ -748,7 -753,7 +748,7 @@@ void transport_print_push_status(const unsigned char head_sha1[20]; char *head; - head = resolve_refdup("HEAD", head_sha1, 1, NULL); + head = resolve_refdup("HEAD", RESOLVE_REF_READING, head_sha1, NULL); if (verbose) { for (ref = refs; ref; ref = ref->next) @@@ -779,7 -784,6 +779,7 @@@ *reject_reasons |= REJECT_NEEDS_FORCE; } } + free(head); } void transport_verify_remote_names(int nr_heads, const char **heads) @@@ -829,9 -833,6 +829,9 @@@ static int git_transport_push(struct tr args.progress = transport->progress; args.dry_run = !!(flags & TRANSPORT_PUSH_DRY_RUN); args.porcelain = !!(flags & TRANSPORT_PUSH_PORCELAIN); + args.push_cert = !!(flags & TRANSPORT_PUSH_CERT); + args.atomic = !!(flags & TRANSPORT_PUSH_ATOMIC); + args.url = transport->url; ret = send_pack(&args, data->fd, data->conn, remote_refs, &data->extra_have); @@@ -976,7 -977,9 +976,7 @@@ struct transport *transport_get(struct } else { /* Unknown protocol in URL. Pass to external handler. */ int len = external_specification_len(url); - char *handler = xmalloc(len + 1); - handler[len] = 0; - strncpy(handler, url, len); + char *handler = xmemdupz(url, len); transport_helper_init(ret, handler); } @@@ -1063,7 -1066,7 +1063,7 @@@ static int run_pre_push_hook(struct tra { int ret = 0, x; struct ref *r; - struct child_process proc; + struct child_process proc = CHILD_PROCESS_INIT; struct strbuf buf; const char *argv[4]; @@@ -1074,6 -1077,7 +1074,6 @@@ argv[2] = transport->url; argv[3] = NULL; - memset(&proc, 0, sizeof(proc)); proc.argv = argv; proc.in = -1; @@@ -1182,8 -1186,10 +1182,8 @@@ int transport_push(struct transport *tr if ((flags & (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND | TRANSPORT_RECURSE_SUBMODULES_CHECK)) && !is_bare_repository()) { struct ref *ref = remote_refs; - struct string_list needs_pushing; + struct string_list needs_pushing = STRING_LIST_INIT_DUP; - memset(&needs_pushing, 0, sizeof(struct string_list)); - needs_pushing.strdup_strings = 1; for (; ref; ref = ref->next) if (!is_null_sha1(ref->new_sha1) && find_unpushed_submodules(ref->new_sha1, @@@ -1363,11 -1369,11 +1363,11 @@@ static int refs_from_alternate_cb(struc while (other[len-1] == '/') other[--len] = '\0'; if (len < 8 || memcmp(other + len - 8, "/objects", 8)) - return 0; + goto out; /* Is this a git repository with refs? */ memcpy(other + len - 8, "/refs", 6); if (!is_directory(other)) - return 0; + goto out; other[len - 8] = '\0'; remote = remote_get(other); transport = transport_get(remote, other); @@@ -1376,7 -1382,6 +1376,7 @@@ extra = extra->next) cb->fn(extra, cb->data); transport_disconnect(transport); +out: free(other); return 0; }