Code

git-log: allow --decorate[=short|full]
authorLars Hjemli <hjemli@gmail.com>
Sat, 15 Aug 2009 14:23:12 +0000 (16:23 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 18 Aug 2009 20:14:17 +0000 (13:14 -0700)
Commit de435ac0 changed the behavior of --decorate from printing the
full ref (e.g., "refs/heads/master") to a shorter, more human-readable
version (e.g., just "master"). While this is nice for human readers,
external tools using the output from "git log" may prefer the full
version.

This patch introduces an extension to --decorate to allow the caller to
specify either the short or the full versions.

Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-log.txt
builtin-log.c
log-tree.c
log-tree.h
pretty.c
revision.c
revision.h
t/t4013-diff-various.sh
t/t4013/diff.log_--decorate=full_--all [new file with mode: 0644]

index 34cf4e5811d1a6f46fcbd333a2ff48c200eadff8..3d79de11ec36d0212610a4bec68789bdeec6c1fe 100644 (file)
@@ -37,8 +37,12 @@ include::diff-options.txt[]
        and <until>, see "SPECIFYING REVISIONS" section in
        linkgit:git-rev-parse[1].
 
---decorate::
-       Print out the ref names of any commits that are shown.
+--decorate[=short|full]::
+       Print out the ref names of any commits that are shown. If 'short' is
+       specified, the ref name prefixes 'refs/heads/', 'refs/tags/' and
+       'refs/remotes/' will not be printed. If 'full' is specified, the
+       full ref name (including prefix) will be printed. The default option
+       is 'short'.
 
 --source::
        Print out the ref name given on the command line by which each
index 82236c531bb3c70875285467cbd775fec27c939e..25e21ed41534c8c3067c2e0d5afe4284faa2881a 100644 (file)
@@ -35,6 +35,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
                      struct rev_info *rev)
 {
        int i;
+       int decoration_style = 0;
 
        rev->abbrev = DEFAULT_ABBREV;
        rev->commit_format = CMIT_FMT_DEFAULT;
@@ -61,8 +62,15 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
        for (i = 1; i < argc; i++) {
                const char *arg = argv[i];
                if (!strcmp(arg, "--decorate")) {
-                       load_ref_decorations();
-                       rev->show_decorations = 1;
+                       decoration_style = DECORATE_SHORT_REFS;
+               } else if (!prefixcmp(arg, "--decorate=")) {
+                       const char *v = skip_prefix(arg, "--decorate=");
+                       if (!strcmp(v, "full"))
+                               decoration_style = DECORATE_FULL_REFS;
+                       else if (!strcmp(v, "short"))
+                               decoration_style = DECORATE_SHORT_REFS;
+                       else
+                               die("invalid --decorate option: %s", arg);
                } else if (!strcmp(arg, "--source")) {
                        rev->show_source = 1;
                } else if (!strcmp(arg, "-h")) {
@@ -70,6 +78,10 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
                } else
                        die("unrecognized argument: %s", arg);
        }
+       if (decoration_style) {
+               rev->show_decorations = 1;
+               load_ref_decorations(decoration_style);
+       }
 }
 
 /*
index a3b4c0692c6a46a0642cf1cb42e60eee59110d60..1c9eefee33b38a44f34d21c47bc1f16af1443a6c 100644 (file)
@@ -25,7 +25,8 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
        struct object *obj = parse_object(sha1);
        if (!obj)
                return 0;
-       refname = prettify_refname(refname);
+       if (!cb_data || *(int *)cb_data == DECORATE_SHORT_REFS)
+               refname = prettify_refname(refname);
        add_name_decoration("", refname, obj);
        while (obj->type == OBJ_TAG) {
                obj = ((struct tag *)obj)->tagged;
@@ -36,12 +37,12 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
        return 0;
 }
 
-void load_ref_decorations(void)
+void load_ref_decorations(int flags)
 {
        static int loaded;
        if (!loaded) {
                loaded = 1;
-               for_each_ref(add_ref_decoration, NULL);
+               for_each_ref(add_ref_decoration, &flags);
        }
 }
 
index 20b5caf1aa45aa0ba076ec60320d252c42abfb64..3f7b40027b7203985f018e43ab72a6cfc233e8d7 100644 (file)
@@ -17,7 +17,7 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
                             const char **subject_p,
                             const char **extra_headers_p,
                             int *need_8bit_cte_p);
-void load_ref_decorations(void);
+void load_ref_decorations(int flags);
 
 #define FORMAT_PATCH_NAME_MAX 64
 void get_patch_filename(struct commit *commit, int nr, const char *suffix,
index 3b2ecdd20e6f5bdca61ee5e605deac7b8239c70d..f5983f8baa98b69338707b4220e64012ef4e5d11 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -583,7 +583,7 @@ static void format_decoration(struct strbuf *sb, const struct commit *commit)
        struct name_decoration *d;
        const char *prefix = " (";
 
-       load_ref_decorations();
+       load_ref_decorations(DECORATE_SHORT_REFS);
        d = lookup_decoration(&name_decoration, &commit->object);
        while (d) {
                strbuf_addstr(sb, prefix);
index 9f5dac5f1d8a8a654a2ab77e8e26fb134c7e36fa..ce24ad9a8df5589f86fb8974d3784d9a7b7f1960 100644 (file)
@@ -1052,7 +1052,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
                revs->simplify_by_decoration = 1;
                revs->limited = 1;
                revs->prune = 1;
-               load_ref_decorations();
+               load_ref_decorations(DECORATE_SHORT_REFS);
        } else if (!strcmp(arg, "--date-order")) {
                revs->lifo = 0;
                revs->topo_order = 1;
index fb74492714b9276d02992dbe1101efff2cbdb5e6..b10984b603467f2424a282d013e291d67886381e 100644 (file)
@@ -15,6 +15,9 @@
 #define SYMMETRIC_LEFT (1u<<8)
 #define ALL_REV_FLAGS  ((1u<<9)-1)
 
+#define DECORATE_SHORT_REFS    1
+#define DECORATE_FULL_REFS     2
+
 struct rev_info;
 struct log_info;
 
index 8b33321f8c44dc7f8a08fa144bca4f10444ceaa1..8e3694ed5b80a87602d6533f0aa28307bd7b3d1b 100755 (executable)
@@ -207,6 +207,7 @@ log --root --cc --patch-with-stat --summary master
 log -SF master
 log -SF -p master
 log --decorate --all
+log --decorate=full --all
 
 rev-list --parents HEAD
 rev-list --children HEAD
diff --git a/t/t4013/diff.log_--decorate=full_--all b/t/t4013/diff.log_--decorate=full_--all
new file mode 100644 (file)
index 0000000..903d9d9
--- /dev/null
@@ -0,0 +1,34 @@
+$ git log --decorate=full --all
+commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (refs/heads/master)
+Merge: 9a6d494 c7a2ab9
+Author: A U Thor <author@example.com>
+Date:   Mon Jun 26 00:04:00 2006 +0000
+
+    Merge branch 'side'
+
+commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a (refs/heads/side)
+Author: A U Thor <author@example.com>
+Date:   Mon Jun 26 00:03:00 2006 +0000
+
+    Side
+
+commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0
+Author: A U Thor <author@example.com>
+Date:   Mon Jun 26 00:02:00 2006 +0000
+
+    Third
+
+commit 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44
+Author: A U Thor <author@example.com>
+Date:   Mon Jun 26 00:01:00 2006 +0000
+
+    Second
+    
+    This is the second commit.
+
+commit 444ac553ac7612cc88969031b02b3767fb8a353a (refs/heads/initial)
+Author: A U Thor <author@example.com>
+Date:   Mon Jun 26 00:00:00 2006 +0000
+
+    Initial
+$