commit: use generations in paint_down_to_common()
[gitweb.git] / builtin / ls-remote.c
index 3a20378b8f5d94134de3969630f7913274b628db..c4be98ab9e84fdcde2842b88d4bb60600f7bf627 100644 (file)
@@ -5,7 +5,8 @@
 
 static const char * const ls_remote_usage[] = {
        N_("git ls-remote [--heads] [--tags] [--refs] [--upload-pack=<exec>]\n"
-          "                     [-q | --quiet] [--exit-code] [--get-url] [<repository> [<refs>...]]"),
+          "                     [-q | --quiet] [--exit-code] [--get-url]\n"
+          "                     [--symref] [<repository> [<refs>...]]"),
        NULL
 };
 
@@ -16,17 +17,19 @@ static const char * const ls_remote_usage[] = {
 static int tail_match(const char **pattern, const char *path)
 {
        const char *p;
-       char pathbuf[PATH_MAX];
+       char *pathbuf;
 
        if (!pattern)
                return 1; /* no restriction */
 
-       if (snprintf(pathbuf, sizeof(pathbuf), "/%s", path) > sizeof(pathbuf))
-               return error("insanely long ref %.*s...", 20, path);
+       pathbuf = xstrfmt("/%s", path);
        while ((p = *(pattern++)) != NULL) {
-               if (!wildmatch(p, pathbuf, 0, NULL))
+               if (!wildmatch(p, pathbuf, 0)) {
+                       free(pathbuf);
                        return 1;
+               }
        }
+       free(pathbuf);
        return 0;
 }
 
@@ -37,6 +40,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
        int get_url = 0;
        int quiet = 0;
        int status = 0;
+       int show_symref_target = 0;
        const char *uploadpack = NULL;
        const char **pattern = NULL;
 
@@ -58,6 +62,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
                         N_("take url.<base>.insteadOf into account")),
                OPT_SET_INT(0, "exit-code", &status,
                            N_("exit with exit code 2 if no matching refs are found"), 2),
+               OPT_BOOL(0, "symref", &show_symref_target,
+                        N_("show underlying ref in addition to the object pointed by it")),
                OPT_END()
        };
 
@@ -101,7 +107,9 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
                        continue;
                if (!tail_match(pattern, ref->name))
                        continue;
-               printf("%s      %s\n", oid_to_hex(&ref->old_oid), ref->name);
+               if (show_symref_target && ref->symref)
+                       printf("ref: %s\t%s\n", ref->symref, ref->name);
+               printf("%s\t%s\n", oid_to_hex(&ref->old_oid), ref->name);
                status = 0; /* we found something */
        }
        return status;