l10n: git.pot: v2.10.0 round 2 (12 new, 44 removed)
[gitweb.git] / builtin / fetch.c
index 2bc609b7f7152af97c5adea0172ba90f807ac7b0..164623bb6f2eb3ffad3eac59b8ec440b9cf60d9c 100644 (file)
@@ -451,6 +451,7 @@ static int s_update_ref(const char *action,
 }
 
 static int refcol_width = 10;
+static int compact_format;
 
 static void adjust_refcol_width(const struct ref *ref)
 {
@@ -462,6 +463,7 @@ static void adjust_refcol_width(const struct ref *ref)
 
        max    = term_columns();
        rlen   = utf8_strwidth(prettify_refname(ref->name));
+
        llen   = utf8_strwidth(prettify_refname(ref->peer_ref->name));
 
        /*
@@ -470,10 +472,19 @@ static void adjust_refcol_width(const struct ref *ref)
         * anyway because we don't know if the error explanation part
         * will be printed in update_local_ref)
         */
+       if (compact_format) {
+               llen = 0;
+               max = max * 2 / 3;
+       }
        len = 21 /* flag and summary */ + rlen + 4 /* -> */ + llen;
        if (len >= max)
                return;
 
+       /*
+        * Not precise calculation for compact mode because '*' can
+        * appear on the left hand side of '->' and shrink the column
+        * back.
+        */
        if (refcol_width < rlen)
                refcol_width = rlen;
 }
@@ -481,6 +492,16 @@ static void adjust_refcol_width(const struct ref *ref)
 static void prepare_format_display(struct ref *ref_map)
 {
        struct ref *rm;
+       const char *format = "full";
+
+       git_config_get_string_const("fetch.output", &format);
+       if (!strcasecmp(format, "full"))
+               compact_format = 0;
+       else if (!strcasecmp(format, "compact"))
+               compact_format = 1;
+       else
+               die(_("configuration fetch.output contains invalid value %s"),
+                   format);
 
        for (rm = ref_map; rm; rm = rm->next) {
                if (rm->status == REF_STATUS_REJECT_SHALLOW ||
@@ -492,12 +513,66 @@ static void prepare_format_display(struct ref *ref_map)
        }
 }
 
+static void print_remote_to_local(struct strbuf *display,
+                                 const char *remote, const char *local)
+{
+       strbuf_addf(display, "%-*s -> %s", refcol_width, remote, local);
+}
+
+static int find_and_replace(struct strbuf *haystack,
+                           const char *needle,
+                           const char *placeholder)
+{
+       const char *p = strstr(haystack->buf, needle);
+       int plen, nlen;
+
+       if (!p)
+               return 0;
+
+       if (p > haystack->buf && p[-1] != '/')
+               return 0;
+
+       plen = strlen(p);
+       nlen = strlen(needle);
+       if (plen > nlen && p[nlen] != '/')
+               return 0;
+
+       strbuf_splice(haystack, p - haystack->buf, nlen,
+                     placeholder, strlen(placeholder));
+       return 1;
+}
+
+static void print_compact(struct strbuf *display,
+                         const char *remote, const char *local)
+{
+       struct strbuf r = STRBUF_INIT;
+       struct strbuf l = STRBUF_INIT;
+
+       if (!strcmp(remote, local)) {
+               strbuf_addf(display, "%-*s -> *", refcol_width, remote);
+               return;
+       }
+
+       strbuf_addstr(&r, remote);
+       strbuf_addstr(&l, local);
+
+       if (!find_and_replace(&r, local, "*"))
+               find_and_replace(&l, remote, "*");
+       print_remote_to_local(display, r.buf, l.buf);
+
+       strbuf_release(&r);
+       strbuf_release(&l);
+}
+
 static void format_display(struct strbuf *display, char code,
                           const char *summary, const char *error,
                           const char *remote, const char *local)
 {
        strbuf_addf(display, "%c %-*s ", code, TRANSPORT_SUMMARY(summary));
-       strbuf_addf(display, "%-*s -> %s", refcol_width, remote, local);
+       if (!compact_format)
+               print_remote_to_local(display, remote, local);
+       else
+               print_compact(display, remote, local);
        if (error)
                strbuf_addf(display, "  (%s)", error);
 }
@@ -654,7 +729,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
                url = xstrdup("foreign");
 
        rm = ref_map;
-       if (check_everything_connected(iterate_ref_map, 0, &rm)) {
+       if (check_connected(iterate_ref_map, &rm, NULL)) {
                rc = error(_("%s did not send all necessary objects\n"), url);
                goto abort;
        }
@@ -791,6 +866,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
 static int quickfetch(struct ref *ref_map)
 {
        struct ref *rm = ref_map;
+       struct check_connected_options opt = CHECK_CONNECTED_INIT;
 
        /*
         * If we are deepening a shallow clone we already have these
@@ -801,7 +877,8 @@ static int quickfetch(struct ref *ref_map)
         */
        if (depth)
                return -1;
-       return check_everything_connected(iterate_ref_map, 1, &rm);
+       opt.quiet = 1;
+       return check_connected(iterate_ref_map, &rm, &opt);
 }
 
 static int fetch_refs(struct transport *transport, struct ref *ref_map)
@@ -846,7 +923,7 @@ static int prune_refs(struct refspec *refs, int ref_count, struct ref *ref_map,
                for (ref = stale_refs; ref; ref = ref->next)
                        string_list_append(&refnames, ref->name);
 
-               result = delete_refs(&refnames);
+               result = delete_refs(&refnames, 0);
                string_list_clear(&refnames, 0);
        }
 
@@ -1047,7 +1124,7 @@ static int get_remote_group(const char *key, const char *value, void *priv)
                        size_t wordlen = strcspn(value, " \t\n");
 
                        if (wordlen >= 1)
-                               string_list_append(g->list,
+                               string_list_append_nodup(g->list,
                                                   xstrndup(value, wordlen));
                        value += wordlen + (value[wordlen] != '\0');
                }
@@ -1185,7 +1262,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv)
 int cmd_fetch(int argc, const char **argv, const char *prefix)
 {
        int i;
-       struct string_list list = STRING_LIST_INIT_NODUP;
+       struct string_list list = STRING_LIST_INIT_DUP;
        struct remote *remote;
        int result = 0;
        struct argv_array argv_gc_auto = ARGV_ARRAY_INIT;
@@ -1268,8 +1345,6 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
                argv_array_clear(&options);
        }
 
-       /* All names were strdup()ed or strndup()ed */
-       list.strdup_strings = 1;
        string_list_clear(&list, 0);
 
        close_all_packs();