From: Frantisek Hrbata Date: Thu, 26 May 2022 06:31:05 +0000 (+0200) Subject: backup X-Git-Url: http://www.hrbata.com/gitweb/?a=commitdiff_plain;p=gimrr_c.git backup Signed-off-by: Frantisek Hrbata --- diff --git a/src/common.c b/src/common.c index 21ddd7d..b2e1c0d 100644 --- a/src/common.c +++ b/src/common.c @@ -46,6 +46,7 @@ struct expand_ref_data { const char *str; struct strvec prefixes; struct object_id oid; + char *refname; int refs_found; }; @@ -57,8 +58,17 @@ static int expand_ref_cb(const char *refname, const struct object_id *oid, if (!ends_with(refname, "/head")) return 0; - if (!data->refs_found++) + switch (data->refs_found++) { + case 0: oidcpy(&data->oid, oid); + data->refname = xstrdup(refname); + break; + case 1: + error(_("found '%s' for '%s'"), data->refname, data->str); + /* fallthrough */ + default: + error(_("found '%s' for '%s'"), refname, data->str); + } return 0; } @@ -91,15 +101,14 @@ static struct commit *lookup_commit_reference_by_short_name(const char *str) for_each_remote(remote_ref_cb, &data); for_each_fullref_in_prefixes(NULL, data.prefixes.v, expand_ref_cb, &data); + free(data.refname); strvec_clear(&data.prefixes); if (!data.refs_found) return NULL; - if (data.refs_found > 1) { - warning(_("ambiguous mrid '%s'"), str); - return NULL; - } + if (data.refs_found > 1) + die(_("ambiguous mrid '%s'"), str); return lookup_commit_reference(the_repository, &data.oid); } diff --git a/src/gimrr.h b/src/gimrr.h index ae88d99..1e0ba30 100644 --- a/src/gimrr.h +++ b/src/gimrr.h @@ -16,6 +16,6 @@ int cmd_create(int argc, const char **argv, const char *prefix); int cmd_list(int argc, const char **argv, const char *prefix); -int cmd_push(int argc, const char **argv, const char *prefix); +int cmd_upload(int argc, const char **argv, const char *prefix); #endif diff --git a/src/upload.c b/src/upload.c index 1e6652c..c5cb230 100644 --- a/src/upload.c +++ b/src/upload.c @@ -1,7 +1,5 @@ #include "gimrr.h" -#define HAS_LOCAL_REFS 1 - #define UPLOAD_HEAD (1<<1) #define UPLOAD_TAGS (1<<2) #define UPLOAD_MBOX (1<<3) @@ -78,17 +76,16 @@ static int get_local_refs(struct remote *remote, void *cb_data) ref_tail = &local_ref->ref; for_each_string_list_item(item, &mrids) { - struct ref **ref_tail_orig = ref_tail; strbuf_reset(&ref_prefix); strbuf_addf(&ref_prefix, "refs/mrs/local/%s/%s/", remote->name, item->string); for_each_fullref_in(ref_prefix.buf, get_mr_refs, &ref_tail); - /* no new refs added for remote */ - if (ref_tail_orig == ref_tail) - continue; - if (item->util) - warning(_("mr '%s' in different remotes"), item->string); - item->util = (void *)HAS_LOCAL_REFS; + } + + if (!mrids.nr) { + strbuf_reset(&ref_prefix); + strbuf_addf(&ref_prefix, "refs/mrs/local/%s/", remote->name); + for_each_fullref_in(ref_prefix.buf, get_mr_refs, &ref_tail); } strbuf_release(&ref_prefix); @@ -100,8 +97,13 @@ static void set_remote_prefixes(struct ref *local_refs, struct strvec *names) { struct ref *ref = local_refs; + if (!ref) { + strvec_push(names, "refs/mrs/"); + return; + } + while (ref) { - strvec_pushf(names, "refs/mrs/%s", local_ref_suffix(ref->name)); + strvec_pushf(names, "refs/mrs/%s/", local_ref_suffix(ref->name)); ref = ref->next; } } @@ -341,7 +343,7 @@ static int upload_local_refs_url(struct remote *remote, const char *url, err += transport_disconnect(t); done: if (err) - error(_("failed to upload some refs to remote '%s' " + error(_("Failed to upload some refs to remote '%s' " "with url '%s'"), remote->name, anon_url); free_refs(remote_refs); @@ -417,6 +419,13 @@ int cmd_upload(int argc, const char **argv, const char *prefix) for_each_remote(get_local_refs, NULL); for (i = 0; i < local_refs_nr; ++i) { + if (!local_refs[i].ref) { + if (!quiet) + fprintf(stderr, "Nothing new to upload for '%s'\n", + local_refs[i].remote->name); + continue; + } + rv += upload_local_refs(local_refs[i].remote, local_refs[i].ref); }