backup main
authorFrantisek Hrbata <frantisek@hrbata.com>
Thu, 26 May 2022 06:31:05 +0000 (08:31 +0200)
committerFrantisek Hrbata <frantisek@hrbata.com>
Thu, 26 May 2022 06:31:05 +0000 (08:31 +0200)
Signed-off-by: Frantisek Hrbata <frantisek@hrbata.com>
src/common.c
src/gimrr.h
src/upload.c

index 21ddd7dd76cea712e4ec4f5478b53903a46ff2b5..b2e1c0da428aff9e32fb214d3af2ce07ce02b633 100644 (file)
@@ -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);
 }
index ae88d9979e6eb67c40d0c3bd41290e0bb46a20d8..1e0ba303ab3abbe8397fffcfd9f6eb5bb712d94e 100644 (file)
@@ -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
index 1e6652c06ff28bd9a767b0eccae657d540a2f241..c5cb230d08da3f882c8833d66c6a75e2b6f9a154 100644 (file)
@@ -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);
        }