{"thread":{"id":"13013","subject":"[PATCH 1/2] decorate: use \"const struct object\"","startedAt":"2008-04-07T13:40:07Z","lastAt":"2008-04-10T08:39:32Z","messageCount":4,"participants":["Johannes Schindelin","René Scharfe","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"73824","messageId":"alpine.DEB.1.00.0804071439480.430@eeepc-johanness","threadId":"13013","inReplyTo":null,"subject":"[PATCH 1/2] decorate: use \"const struct object\"","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-04-07T13:40:07Z","receivedAt":"2008-04-07T13:40:07Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nWe use the object only as key for the decoration, therefore we should\naccess it as const struct object.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n decorate.c |   10 +++++-----\n decorate.h |    6 +++---\n 2 files changed, 8 insertions(+), 8 deletions(-)\n\ndiff --git a/decorate.c b/decorate.c\nindex 23f6b00..3aee3b7 100644\n--- a/decorate.c\n+++ b/decorate.c\n@@ -6,13 +6,13 @@\n #include \"object.h\"\n #include \"decorate.h\"\n \n-static unsigned int hash_obj(struct object *obj, unsigned int n)\n+static unsigned int hash_obj(const struct object *obj, unsigned int n)\n {\n \tunsigned int hash = *(unsigned int *)obj->sha1;\n \treturn hash % n;\n }\n \n-static void *insert_decoration(struct decoration *n, struct object *base, void *decoration)\n+static void *insert_decoration(struct decoration *n, const struct object *base, void *decoration)\n {\n \tint size = n->size;\n \tstruct object_decoration *hash = n->hash;\n@@ -47,7 +47,7 @@ static void grow_decoration(struct decoration *n)\n \tn->nr = 0;\n \n \tfor (i = 0; i < old_size; i++) {\n-\t\tstruct object *base = old_hash[i].base;\n+\t\tconst struct object *base = old_hash[i].base;\n \t\tvoid *decoration = old_hash[i].decoration;\n \n \t\tif (!base)\n@@ -58,7 +58,7 @@ static void grow_decoration(struct decoration *n)\n }\n \n /* Add a decoration pointer, return any old one */\n-void *add_decoration(struct decoration *n, struct object *obj, void *decoration)\n+void *add_decoration(struct decoration *n, const struct object *obj, void *decoration)\n {\n \tint nr = n->nr + 1;\n \n@@ -68,7 +68,7 @@ void *add_decoration(struct decoration *n, struct object *obj, void *decoration)\n }\n \n /* Lookup a decoration pointer */\n-void *lookup_decoration(struct decoration *n, struct object *obj)\n+void *lookup_decoration(struct decoration *n, const struct object *obj)\n {\n \tint j;\n \ndiff --git a/decorate.h b/decorate.h\nindex 1fa4ad9..e732804 100644\n--- a/decorate.h\n+++ b/decorate.h\n@@ -2,7 +2,7 @@\n #define DECORATE_H\n \n struct object_decoration {\n-\tstruct object *base;\n+\tconst struct object *base;\n \tvoid *decoration;\n };\n \n@@ -12,7 +12,7 @@ struct decoration {\n \tstruct object_decoration *hash;\n };\n \n-extern void *add_decoration(struct decoration *n, struct object *obj, void *decoration);\n-extern void *lookup_decoration(struct decoration *n, struct object *obj);\n+extern void *add_decoration(struct decoration *n, const struct object *obj, void *decoration);\n+extern void *lookup_decoration(struct decoration *n, const struct object *obj);\n \n #endif\n-- \n1.5.5.rc0.208.g1d50\n"},{"id":"73825","messageId":"alpine.DEB.1.00.0804071441040.430@eeepc-johanness","threadId":"13013","inReplyTo":"alpine.DEB.1.00.0804071439480.430@eeepc-johanness","subject":"[PATCH 2/2] pretty=format: Add %d to show decoration","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-04-07T13:41:12Z","receivedAt":"2008-04-07T13:41:12Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\nWith this patch, \"git log --decorate --pretty=format:%d\", shows the\nname decoration (i.e. whenever a commit matches a ref, that ref's name\nis shown).\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\n\n\tMaybe %d should expand to \" (<name decoration>)\" instead of\n\t\"<name decoration>\"?\n\n Documentation/pretty-formats.txt |    1 +\n pretty.c                         |    9 +++++++++\n 2 files changed, 10 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt\nindex e8bea3e..9d8a8d4 100644\n--- a/Documentation/pretty-formats.txt\n+++ b/Documentation/pretty-formats.txt\n@@ -117,6 +117,7 @@ The placeholders are:\n - '%e': encoding\n - '%s': subject\n - '%b': body\n+- '%d': decoration (needs --decorate)\n - '%Cred': switch color to red\n - '%Cgreen': switch color to green\n - '%Cblue': switch color to blue\ndiff --git a/pretty.c b/pretty.c\nindex 6c04176..37f7c3e 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -489,6 +489,15 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,\n \t\t\treturn 3;\n \t\t} else\n \t\t\treturn 0;\n+\tcase 'd':\n+\t\t{\n+\t\t\tstruct name_decoration *decoration =\n+\t\t\t\tlookup_decoration(&name_decoration,\n+\t\t\t\t&commit->object);\n+\t\t\tif (decoration)\n+\t\t\t\tstrbuf_addstr(sb, decoration->name);\n+\t\t\treturn 1;\n+\t\t}\n \t}\n \n \t/* these depend on the commit */\n-- \n1.5.5.rc0.208.g1d50\n"},{"id":"73987","messageId":"47FD37D6.2030506@lsrfire.ath.cx","threadId":"13013","inReplyTo":"alpine.DEB.1.00.0804071441040.430@eeepc-johanness","subject":"Re: [PATCH 2/2] pretty=format: Add %d to show decoration","fromName":"René Scharfe","fromEmail":"rene.scharfe@lsrfire.ath.cx","sentAt":"2008-04-09T21:40:38Z","receivedAt":"2008-04-09T21:40:38Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Johannes Schindelin schrieb:\n> With this patch, \"git log --decorate --pretty=format:%d\", shows the \n> name decoration (i.e. whenever a commit matches a ref, that ref's \n> name is shown).\n\nCute idea. :)\n\nWhat about objects with multiple decoration?  How about producing a\ncomma-separated list like git-log does?\n\nHow about making %d imply --decorate?  You could load the decorations\nlazily when it's first encountered.\n\n> Maybe %d should expand to \" (<name decoration>)\" instead of \"<name \n> decoration>\"?\n\nfoobar2000 (http://foobar2000.org/) has a kind of music tagging\nlanguage, and one of its features might be interesting for us here: you\ncan group a placeholder and other stuff inside brackets.  The construct\nresolves to an empty string if the placeholder is NULL, i.e. in your\nexample \"[ (%d)]\" would resolve to either \" (the decoration)\" or \"\",\ndepending on the object having a decoration or not.  (It might be a\nbetter fit for --pretty=format: to use %[ and %].)\n\nBy the way, your patch reminds me that I wanted to add a placeholder for\ngit-describe's output.  I doubt I'll find time for that in the near\nfuture, though..\n\nRené\n"},{"id":"74044","messageId":"7v1w5exfwb.fsf@gitster.siamese.dyndns.org","threadId":"13013","inReplyTo":"alpine.DEB.1.00.0804071441040.430@eeepc-johanness","subject":"Re: [PATCH 2/2] pretty=format: Add %d to show decoration","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-04-10T08:39:32Z","receivedAt":"2008-04-10T08:39:32Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:\n\n> With this patch, \"git log --decorate --pretty=format:%d\", shows the\n> name decoration (i.e. whenever a commit matches a ref, that ref's name\n> is shown).\n>\n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n>\n> \tMaybe %d should expand to \" (<name decoration>)\" instead of\n> \t\"<name decoration>\"?\n\nNot necessarily.  %d in --pretty=\"format:%h%d %s\" may want to expand to\n\"(<name>) \" instead of \" (<name>)\".\n"}]}