From: Junio C Hamano Date: Fri, 4 Sep 2015 02:17:47 +0000 (-0700) Subject: Merge branch 'mh/get-remote-group-fix' into maint X-Git-Tag: v2.5.2~22 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/03ea02771a3752b81db355d70adf430f217b5d7a?hp=-c Merge branch 'mh/get-remote-group-fix' into maint An off-by-one error made "git remote" to mishandle a remote with a single letter nickname. * mh/get-remote-group-fix: get_remote_group(): use skip_prefix() get_remote_group(): eliminate superfluous call to strcspn() get_remote_group(): rename local variable "space" to "wordlen" get_remote_group(): handle remotes with single-character names --- 03ea02771a3752b81db355d70adf430f217b5d7a diff --combined builtin/fetch.c index 8d5b2dba2b,262809c787..635bbdfc88 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@@ -179,15 -179,13 +179,15 @@@ static void add_merge_config(struct re } } -static int add_existing(const char *refname, const unsigned char *sha1, +static int add_existing(const char *refname, const struct object_id *oid, int flag, void *cbdata) { struct string_list *list = (struct string_list *)cbdata; struct string_list_item *item = string_list_insert(list, refname); - item->util = xmalloc(20); - hashcpy(item->util, sha1); + struct object_id *old_oid = xmalloc(sizeof(*old_oid)); + + oidcpy(old_oid, oid); + item->util = old_oid; return 0; } @@@ -417,10 -415,8 +417,10 @@@ static int s_update_ref(const char *act transaction = ref_transaction_begin(&err); if (!transaction || - ref_transaction_update(transaction, ref->name, ref->new_sha1, - ref->old_sha1, 0, check_old, msg, &err)) + ref_transaction_update(transaction, ref->name, + ref->new_sha1, + check_old ? ref->old_sha1 : NULL, + 0, msg, &err)) goto fail; ret = ref_transaction_commit(transaction, &err); @@@ -590,8 -586,7 +590,8 @@@ static int store_updated_refs(const cha struct strbuf note = STRBUF_INIT; const char *what, *kind; struct ref *rm; - char *url, *filename = dry_run ? "/dev/null" : git_path("FETCH_HEAD"); + char *url; + const char *filename = dry_run ? "/dev/null" : git_path("FETCH_HEAD"); int want_status; fp = fopen(filename, "a"); @@@ -825,7 -820,7 +825,7 @@@ static void check_not_current_branch(st static int truncate_fetch_head(void) { - char *filename = git_path("FETCH_HEAD"); + const char *filename = git_path("FETCH_HEAD"); FILE *fp = fopen(filename, "w"); if (!fp) @@@ -915,10 -910,9 +915,10 @@@ static int do_fetch(struct transport *t struct string_list_item *peer_item = string_list_lookup(&existing_refs, rm->peer_ref->name); - if (peer_item) - hashcpy(rm->peer_ref->old_sha1, - peer_item->util); + if (peer_item) { + struct object_id *old_oid = peer_item->util; + hashcpy(rm->peer_ref->old_sha1, old_oid->hash); + } } } @@@ -979,17 -973,15 +979,15 @@@ static int get_remote_group(const char { struct remote_group_data *g = priv; - if (starts_with(key, "remotes.") && - !strcmp(key + 8, g->name)) { + if (skip_prefix(key, "remotes.", &key) && !strcmp(key, g->name)) { /* split list by white space */ - int space = strcspn(value, " \t\n"); while (*value) { - if (space > 1) { + size_t wordlen = strcspn(value, " \t\n"); + + if (wordlen >= 1) string_list_append(g->list, - xstrndup(value, space)); - } - value += space + (value[space] != '\0'); - space = strcspn(value, " \t\n"); + xstrndup(value, wordlen)); + value += wordlen + (value[wordlen] != '\0'); } }