git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Dressel <MichaelTiloDressel@t-online.de>
To: git@vger.kernel.org, peff@peff.net
Subject: [PATCH 1/2] add '%d' pretty format specifier to show decoration
Date: Wed, 3 Sep 2008 20:40:08 +0200 (CEST)	[thread overview]
Message-ID: <alpine.LNX.1.10.0809032036270.32295@pollux> (raw)


This is a variation of the patch provided by  Jeff King <peff@peff.net>:
allow '%d' pretty format specifier to show decoration

Previously, specifying

   git log --pretty=format:'%H %s' --decorate

would calculate decorations, but not show them. You can now
do:

   git log --pretty=format:'%H (%d) %s'

to see them.

The difference is that you don't need --decorate when %d has been given
because this would be "doppeltgemoppelt" (redundant).

Signed-off-by: Michael Dressel <MichaelTiloDressel@t-online.de>
---
  Documentation/pretty-formats.txt |    1 +
  builtin-log.c                    |   24 +++++++++++++++++++++++-
  pretty.c                         |   15 +++++++++++++++
  3 files changed, 39 insertions(+), 1 deletions(-)

diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
index 388d492..2616d63 100644
--- a/Documentation/pretty-formats.txt
+++ b/Documentation/pretty-formats.txt
@@ -116,6 +116,7 @@ The placeholders are:
  - '%cr': committer date, relative
  - '%ct': committer date, UNIX timestamp
  - '%ci': committer date, ISO 8601 format
+- '%d': decoration
  - '%e': encoding
  - '%s': subject
  - '%b': body
diff --git a/builtin-log.c b/builtin-log.c
index 1d3c5cb..5424012 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -50,11 +50,29 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in
  	return 0;
  }

+static int deco_in_format(int argc, const char **argv)
+{
+	int i;
+	int deco=0;
+	for (i=0;i<argc;i++)
+	{
+		if ((strstr(argv[i], "pretty=format:") ||
+					strstr(argv[i], "pretty=tformat:")) &&
+				strstr(argv[i], "%d"))
+		{
+			deco=1;
+			break;
+		}
+
+	}
+	return deco;
+}
+
  static void cmd_log_init(int argc, const char **argv, const char *prefix,
  		      struct rev_info *rev)
  {
  	int i;
-	int decorate = 0;
+	int decorate = deco_in_format(argc, argv);

  	rev->abbrev = DEFAULT_ABBREV;
  	rev->commit_format = CMIT_FMT_DEFAULT;
@@ -77,6 +95,10 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
  		if (rev->diffopt.nr_paths != 1)
  			usage("git logs can only follow renames on one pathname at a time");
  	}
+	if (decorate)
+	{
+		for_each_ref(add_ref_decoration, NULL);
+	}
  	for (i = 1; i < argc; i++) {
  		const char *arg = argv[i];
  		if (!strcmp(arg, "--decorate")) {
diff --git a/pretty.c b/pretty.c
index a29c290..3430e4d 100644
--- a/pretty.c
+++ b/pretty.c
@@ -520,8 +520,23 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
  			return 3;
  		} else
  			return 0;
+	case 'd':
+		{
+			struct name_decoration *d;
+			const char *prefix = "";
+			d = lookup_decoration(&name_decoration,
+					&commit->object);
+			while (d) {
+				strbuf_addstr(sb, prefix);
+				prefix = ", ";
+				strbuf_addstr(sb, d->name);
+				d = d->next;
+			}
+		}
+		return 1;
  	}

+
  	/* these depend on the commit */
  	if (!commit->object.parsed)
  		parse_object(commit->object.sha1);
-- 
1.6.0.1

             reply	other threads:[~2008-09-03 18:41 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-03 18:40 Michael Dressel [this message]
2008-09-03 19:12 ` [PATCH 1/2] add '%d' pretty format specifier to show decoration Jeff King
2008-09-03 20:10   ` Junio C Hamano
2008-09-03 20:36     ` Jeff King
2008-09-03 20:59       ` Junio C Hamano
2008-09-03 21:04         ` Jeff King
2008-09-03 22:06         ` René Scharfe
2008-09-04  3:51           ` Jeff King
2008-09-04 15:47             ` René Scharfe
2008-09-04 21:38               ` [PATCH 1/3] log: add load_ref_decorations() René Scharfe
2008-09-04 21:39               ` [PATCH 2/3] move load_ref_decorations() to log-tree.c and export it René Scharfe
2008-09-04 21:40               ` [PATCH 3/3] add '%d' pretty format specifier to show decoration René Scharfe
2008-09-05  0:11                 ` Jeff King
2008-09-05  0:28                   ` Junio C Hamano
2008-09-05  0:37                     ` Jeff King
2008-09-05  0:41                       ` Junio C Hamano
2008-09-05 18:38                     ` Michael Dressel
2008-09-09 17:33                       ` Michael Dressel
2008-09-09 20:15                         ` René Scharfe
2008-09-05 16:14                   ` René Scharfe
2008-09-03 19:17 ` [PATCH 1/2] " Jeff King
2008-09-03 20:06   ` Michael Dressel
2008-09-03 20:33     ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LNX.1.10.0809032036270.32295@pollux \
    --to=michaeltilodressel@t-online.de \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).