* [PATCH] git-log: allow --decorate[=short|full]
@ 2009-08-15 9:50 Lars Hjemli
2009-08-15 10:26 ` Lars Hjemli
2009-08-15 12:28 ` Jeff King
0 siblings, 2 replies; 6+ messages in thread
From: Lars Hjemli @ 2009-08-15 9:50 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Git Mailing List
This extension to --decorate makes it possible to generate decorations
similar to pre-1.6.4 git, which is nice when the output from git-log
is used by external tools.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
Documentation/git-log.txt | 6 ++++--
builtin-log.c | 12 ++++++++++--
log-tree.c | 7 ++++---
log-tree.h | 2 +-
pretty.c | 2 +-
revision.c | 2 +-
revision.h | 6 +++++-
t/t4013-diff-various.sh | 1 +
...corate_--all => diff.log_--decorate=full_--all} | 8 ++++----
9 files changed, 31 insertions(+), 15 deletions(-)
copy t/t4013/{diff.log_--decorate_--all =>
diff.log_--decorate=full_--all} (72%)
diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt
index 34cf4e5..451839c 100644
--- a/Documentation/git-log.txt
+++ b/Documentation/git-log.txt
@@ -37,8 +37,10 @@ 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 names will be shortened, and if 'full' is specified,
+ the ref names will not be shortened. The default option is 'short'.
--source::
Print out the ref name given on the command line by which each
diff --git a/builtin-log.c b/builtin-log.c
index 3817bf1..cb886d8 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -61,8 +61,14 @@ 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;
+ rev->show_decorations = DECORATE_SHORT_REFS;
+ } else if (!strncmp(arg, "--decorate=", 11)) {
+ if (!strcmp(arg + 11, "full"))
+ rev->show_decorations = DECORATE_FULL_REFS;
+ else if (!strcmp(arg + 11, "short"))
+ rev->show_decorations = DECORATE_SHORT_REFS;
+ else
+ die("invalid --decorate option: %s", arg + 11);
} else if (!strcmp(arg, "--source")) {
rev->show_source = 1;
} else if (!strcmp(arg, "-h")) {
@@ -70,6 +76,8 @@ static void cmd_log_init(int argc, const char
**argv, const char *prefix,
} else
die("unrecognized argument: %s", arg);
}
+ if (rev->show_decorations)
+ load_ref_decorations(rev->show_decorations);
}
/*
diff --git a/log-tree.c b/log-tree.c
index 6f73c17..70223eb 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -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);
}
}
diff --git a/log-tree.h b/log-tree.h
index 20b5caf..3f7b400 100644
--- a/log-tree.h
+++ b/log-tree.h
@@ -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,
diff --git a/pretty.c b/pretty.c
index e5328da..daa721b 100644
--- a/pretty.c
+++ b/pretty.c
@@ -571,7 +571,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);
diff --git a/revision.c b/revision.c
index 9f5dac5..ce24ad9 100644
--- a/revision.c
+++ b/revision.c
@@ -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;
diff --git a/revision.h b/revision.h
index fb74492..16e65f6 100644
--- a/revision.h
+++ b/revision.h
@@ -15,6 +15,10 @@
#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;
@@ -56,7 +60,7 @@ struct rev_info {
rewrite_parents:1,
print_parents:1,
show_source:1,
- show_decorations:1,
+ show_decorations:2,
reverse:1,
reverse_output_stage:1,
cherry_pick:1,
diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh
index 8b33321..8e3694e 100755
--- a/t/t4013-diff-various.sh
+++ b/t/t4013-diff-various.sh
@@ -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_--all
b/t/t4013/diff.log_--decorate=full_--all
similarity index 72%
copy from t/t4013/diff.log_--decorate_--all
copy to t/t4013/diff.log_--decorate=full_--all
index 954210e..903d9d9 100644
--- a/t/t4013/diff.log_--decorate_--all
+++ b/t/t4013/diff.log_--decorate=full_--all
@@ -1,12 +1,12 @@
-$ git log --decorate --all
-commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (master)
+$ 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 (side)
+commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a (refs/heads/side)
Author: A U Thor <author@example.com>
Date: Mon Jun 26 00:03:00 2006 +0000
@@ -26,7 +26,7 @@ Date: Mon Jun 26 00:01:00 2006 +0000
This is the second commit.
-commit 444ac553ac7612cc88969031b02b3767fb8a353a (initial)
+commit 444ac553ac7612cc88969031b02b3767fb8a353a (refs/heads/initial)
Author: A U Thor <author@example.com>
Date: Mon Jun 26 00:00:00 2006 +0000
--
1.6.4.135.g4e5b
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] git-log: allow --decorate[=short|full]
2009-08-15 9:50 [PATCH] git-log: allow --decorate[=short|full] Lars Hjemli
@ 2009-08-15 10:26 ` Lars Hjemli
2009-08-15 12:28 ` Jeff King
1 sibling, 0 replies; 6+ messages in thread
From: Lars Hjemli @ 2009-08-15 10:26 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Git Mailing List
On Sat, Aug 15, 2009 at 11:50, Lars Hjemli<hjemli@gmail.com> wrote:
> This extension to --decorate makes it possible to generate decorations
> similar to pre-1.6.4 git, which is nice when the output from git-log
> is used by external tools.
BTW: the patch was made on top of current master (b2139dbd) - if
accepted, it might be considered for maint.
--
larsh
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] git-log: allow --decorate[=short|full]
2009-08-15 9:50 [PATCH] git-log: allow --decorate[=short|full] Lars Hjemli
2009-08-15 10:26 ` Lars Hjemli
@ 2009-08-15 12:28 ` Jeff King
2009-08-15 14:23 ` Lars Hjemli
1 sibling, 1 reply; 6+ messages in thread
From: Jeff King @ 2009-08-15 12:28 UTC (permalink / raw)
To: Lars Hjemli; +Cc: Junio C Hamano, Git Mailing List
On Sat, Aug 15, 2009 at 11:50:25AM +0200, Lars Hjemli wrote:
> This extension to --decorate makes it possible to generate decorations
> similar to pre-1.6.4 git, which is nice when the output from git-log
> is used by external tools.
This commit message really lacks context. When I read it, I thought to
myself "what happened to decorations in 1.6.4?" It really needs to say:
- exactly what changed
- why did it change
- why the change has drawbacks
After reading the patch and digging through the history, I think you
want something more like:
-- >8 --
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.
-- 8< --
As for the patch, it mostly looks good, but a few comments:
> + } else if (!strncmp(arg, "--decorate=", 11)) {
> + if (!strcmp(arg + 11, "full"))
> + rev->show_decorations = DECORATE_FULL_REFS;
> + else if (!strcmp(arg + 11, "short"))
> + rev->show_decorations = DECORATE_SHORT_REFS;
> + else
> + die("invalid --decorate option: %s", arg + 11);
To avoid the magic 11's, we have a few helpers:
if (!prefixcmp(arg, "--decorate=")) {
const char *v = skip_prefix(arg, "--decorate=");
...
though arguably that is just as bad because you have to repeat the
"--decorate=".
> --- a/revision.h
> +++ b/revision.h
> @@ -15,6 +15,10 @@
> #define SYMMETRIC_LEFT (1u<<8)
> #define ALL_REV_FLAGS ((1u<<9)-1)
>
> +
> +#define DECORATE_SHORT_REFS 1
> +#define DECORATE_FULL_REFS 2
> +
Style nit: extra blank line?
> @@ -56,7 +60,7 @@ struct rev_info {
> rewrite_parents:1,
> print_parents:1,
> show_source:1,
> - show_decorations:1,
> + show_decorations:2,
> reverse:1,
> reverse_output_stage:1,
> cherry_pick:1,
Should we perhaps just turn show_decorations into its own variable? It
just seems like a trap for future maintainers to want to add more
DECORATE_* flags but not realize they have to keep bumping up the size
of the bitfield.
And rev_info is not a struct that we are particularly trying to optimize
the memory on.
> diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh
> index 8b33321..8e3694e 100755
> --- a/t/t4013-diff-various.sh
> +++ b/t/t4013-diff-various.sh
> @@ -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
Yay, tests.
-Peff
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] git-log: allow --decorate[=short|full]
2009-08-15 12:28 ` Jeff King
@ 2009-08-15 14:23 ` Lars Hjemli
2009-08-18 9:33 ` Jeff King
2009-08-18 20:18 ` Junio C Hamano
0 siblings, 2 replies; 6+ messages in thread
From: Lars Hjemli @ 2009-08-15 14:23 UTC (permalink / raw)
To: Jeff King; +Cc: Junio C Hamano, Git Mailing List
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>
---
Thanks for the review. I've adapted the patch to your comments, and
modified the documentation of '--decorate' to be more specific.
Documentation/git-log.txt | 8 ++++++--
builtin-log.c | 13 +++++++++++--
log-tree.c | 7 ++++---
log-tree.h | 2 +-
pretty.c | 2 +-
revision.c | 2 +-
revision.h | 5 ++++-
t/t4013-diff-various.sh | 1 +
...corate_--all => diff.log_--decorate=full_--all} | 8 ++++----
9 files changed, 33 insertions(+), 15 deletions(-)
copy t/t4013/{diff.log_--decorate_--all =>
diff.log_--decorate=full_--all} (72%)
diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt
index 34cf4e5..3d79de1 100644
--- a/Documentation/git-log.txt
+++ b/Documentation/git-log.txt
@@ -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
diff --git a/builtin-log.c b/builtin-log.c
index 3817bf1..1ed4c76 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -61,8 +61,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;
+ rev->show_decorations = DECORATE_SHORT_REFS;
+ } else if (!prefixcmp(arg, "--decorate=")) {
+ const char *v = skip_prefix(arg, "--decorate=");
+ if (!strcmp(v, "full"))
+ rev->show_decorations = DECORATE_FULL_REFS;
+ else if (!strcmp(v, "short"))
+ rev->show_decorations = 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 +77,8 @@ static void cmd_log_init(int argc, const char
**argv, const char *prefix,
} else
die("unrecognized argument: %s", arg);
}
+ if (rev->show_decorations)
+ load_ref_decorations(rev->show_decorations);
}
/*
diff --git a/log-tree.c b/log-tree.c
index 6f73c17..70223eb 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -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);
}
}
diff --git a/log-tree.h b/log-tree.h
index 20b5caf..3f7b400 100644
--- a/log-tree.h
+++ b/log-tree.h
@@ -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,
diff --git a/pretty.c b/pretty.c
index e5328da..daa721b 100644
--- a/pretty.c
+++ b/pretty.c
@@ -571,7 +571,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);
diff --git a/revision.c b/revision.c
index 9f5dac5..ce24ad9 100644
--- a/revision.c
+++ b/revision.c
@@ -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;
diff --git a/revision.h b/revision.h
index fb74492..9a644ee 100644
--- a/revision.h
+++ b/revision.h
@@ -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;
@@ -56,7 +59,6 @@ struct rev_info {
rewrite_parents:1,
print_parents:1,
show_source:1,
- show_decorations:1,
reverse:1,
reverse_output_stage:1,
cherry_pick:1,
@@ -96,6 +98,7 @@ struct rev_info {
const char *subject_prefix;
int no_inline;
int show_log_size;
+ int show_decorations;
/* Filter by commit log message */
struct grep_opt grep_filter;
diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh
index 8b33321..8e3694e 100755
--- a/t/t4013-diff-various.sh
+++ b/t/t4013-diff-various.sh
@@ -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_--all
b/t/t4013/diff.log_--decorate=full_--all
similarity index 72%
copy from t/t4013/diff.log_--decorate_--all
copy to t/t4013/diff.log_--decorate=full_--all
index 954210e..903d9d9 100644
--- a/t/t4013/diff.log_--decorate_--all
+++ b/t/t4013/diff.log_--decorate=full_--all
@@ -1,12 +1,12 @@
-$ git log --decorate --all
-commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (master)
+$ 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 (side)
+commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a (refs/heads/side)
Author: A U Thor <author@example.com>
Date: Mon Jun 26 00:03:00 2006 +0000
@@ -26,7 +26,7 @@ Date: Mon Jun 26 00:01:00 2006 +0000
This is the second commit.
-commit 444ac553ac7612cc88969031b02b3767fb8a353a (initial)
+commit 444ac553ac7612cc88969031b02b3767fb8a353a (refs/heads/initial)
Author: A U Thor <author@example.com>
Date: Mon Jun 26 00:00:00 2006 +0000
--
1.6.4.135.g4e5b
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] git-log: allow --decorate[=short|full]
2009-08-15 14:23 ` Lars Hjemli
@ 2009-08-18 9:33 ` Jeff King
2009-08-18 20:18 ` Junio C Hamano
1 sibling, 0 replies; 6+ messages in thread
From: Jeff King @ 2009-08-18 9:33 UTC (permalink / raw)
To: Lars Hjemli; +Cc: Junio C Hamano, Git Mailing List
On Sat, Aug 15, 2009 at 04:23:12PM +0200, Lars Hjemli wrote:
> 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>
> ---
>
> Thanks for the review. I've adapted the patch to your comments, and
> modified the documentation of '--decorate' to be more specific.
Thanks. Looks good to me.
Acked-by: Jeff King <peff@peff.net>
-Peff
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] git-log: allow --decorate[=short|full]
2009-08-15 14:23 ` Lars Hjemli
2009-08-18 9:33 ` Jeff King
@ 2009-08-18 20:18 ` Junio C Hamano
1 sibling, 0 replies; 6+ messages in thread
From: Junio C Hamano @ 2009-08-18 20:18 UTC (permalink / raw)
To: Lars Hjemli; +Cc: Jeff King, Junio C Hamano, Git Mailing List
Lars Hjemli <hjemli@gmail.com> writes:
> diff --git a/builtin-log.c b/builtin-log.c
> index 3817bf1..1ed4c76 100644
> --- a/builtin-log.c
> +++ b/builtin-log.c
> @@ -61,8 +61,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;
> + rev->show_decorations = DECORATE_SHORT_REFS;
> + } else if (!prefixcmp(arg, "--decorate=")) {
> + const char *v = skip_prefix(arg, "--decorate=");
> + if (!strcmp(v, "full"))
> + rev->show_decorations = DECORATE_FULL_REFS;
> + else if (!strcmp(v, "short"))
> + rev->show_decorations = 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 +77,8 @@ static void cmd_log_init(int argc, const char
> **argv, const char *prefix,
> } else
> die("unrecognized argument: %s", arg);
> }
> + if (rev->show_decorations)
> + load_ref_decorations(rev->show_decorations);
> }
If you are deciding whether full refs are given or short ones when you
call load_ref_decorations(), I do not think there is any reason for you to
change the type of rev->short_decorations from bool to enum. Shouldn't
you maintain a local variable in this function and pass it down to this
call instead?
That is, something like this on top (I had to fix the breakage your MUA
has done to your patch, so there might be some fuzz around whitespace).
builtin-log.c | 13 ++++++++-----
log-tree.c | 2 +-
revision.h | 2 +-
3 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/builtin-log.c b/builtin-log.c
index 2a0f5f7..25e21ed 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -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,13 +62,13 @@ 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")) {
- rev->show_decorations = DECORATE_SHORT_REFS;
+ decoration_style = DECORATE_SHORT_REFS;
} else if (!prefixcmp(arg, "--decorate=")) {
const char *v = skip_prefix(arg, "--decorate=");
if (!strcmp(v, "full"))
- rev->show_decorations = DECORATE_FULL_REFS;
+ decoration_style = DECORATE_FULL_REFS;
else if (!strcmp(v, "short"))
- rev->show_decorations = DECORATE_SHORT_REFS;
+ decoration_style = DECORATE_SHORT_REFS;
else
die("invalid --decorate option: %s", arg);
} else if (!strcmp(arg, "--source")) {
@@ -77,8 +78,10 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
} else
die("unrecognized argument: %s", arg);
}
- if (rev->show_decorations)
- load_ref_decorations(rev->show_decorations);
+ if (decoration_style) {
+ rev->show_decorations = 1;
+ load_ref_decorations(decoration_style);
+ }
}
/*
diff --git a/log-tree.c b/log-tree.c
index 1c767c9..1c9eefe 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -25,7 +25,7 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
struct object *obj = parse_object(sha1);
if (!obj)
return 0;
- if (!cb_data || *(int *)cb_data & DECORATE_SHORT_REFS)
+ if (!cb_data || *(int *)cb_data == DECORATE_SHORT_REFS)
refname = prettify_refname(refname);
add_name_decoration("", refname, obj);
while (obj->type == OBJ_TAG) {
diff --git a/revision.h b/revision.h
index 9a644ee..b10984b 100644
--- a/revision.h
+++ b/revision.h
@@ -59,6 +59,7 @@ struct rev_info {
rewrite_parents:1,
print_parents:1,
show_source:1,
+ show_decorations:1,
reverse:1,
reverse_output_stage:1,
cherry_pick:1,
@@ -98,7 +99,6 @@ struct rev_info {
const char *subject_prefix;
int no_inline;
int show_log_size;
- int show_decorations;
/* Filter by commit log message */
struct grep_opt grep_filter;
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2009-08-18 20:18 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-15 9:50 [PATCH] git-log: allow --decorate[=short|full] Lars Hjemli
2009-08-15 10:26 ` Lars Hjemli
2009-08-15 12:28 ` Jeff King
2009-08-15 14:23 ` Lars Hjemli
2009-08-18 9:33 ` Jeff King
2009-08-18 20:18 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).