git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] custom log formats for "diff --submodule=log"
@ 2012-11-08 20:29 Jeff King
  2012-11-11 11:26 ` Ramkumar Ramachandra
  0 siblings, 1 reply; 4+ messages in thread
From: Jeff King @ 2012-11-08 20:29 UTC (permalink / raw
  To: git; +Cc: Jeffrey S. Haemer

An off-list discussion made me wonder if something like this would be
useful:

  git log -p --submodule=log:'  %m %an <%ae>: %s'

where the format could be whatever you find useful.

I do not use submodules myself, so writing the patch below was just a
fun exercise. I'm not planning on polishing it for inclusion. But I
thought I would publish it here in case anybody who is more interested
feels like picking it up. It would need documentation and tests at the
very least.

---
diff --git a/diff.c b/diff.c
index 86e5f2a..f2adaca 100644
--- a/diff.c
+++ b/diff.c
@@ -2241,7 +2241,7 @@ static void builtin_diff(const char *name_a,
 		const char *add = diff_get_color_opt(o, DIFF_FILE_NEW);
 		show_submodule_summary(o->file, one ? one->path : two->path,
 				one->sha1, two->sha1, two->dirty_submodule,
-				del, add, reset);
+				del, add, reset, o->submodule_log_format);
 		return;
 	}
 
@@ -3654,8 +3654,13 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
 	} else if (!strcmp(arg, "--submodule"))
 		DIFF_OPT_SET(options, SUBMODULE_LOG);
 	else if (!prefixcmp(arg, "--submodule=")) {
-		if (!strcmp(arg + 12, "log"))
+		const char *v = arg + 12;
+		if (!strcmp(v, "log"))
 			DIFF_OPT_SET(options, SUBMODULE_LOG);
+		else if (!prefixcmp(v, "log:")) {
+			DIFF_OPT_SET(options, SUBMODULE_LOG);
+			options->submodule_log_format = xstrdup(v + 4);
+		}
 	}
 
 	/* misc options */
diff --git a/diff.h b/diff.h
index a658f85..9726375 100644
--- a/diff.h
+++ b/diff.h
@@ -132,6 +132,8 @@ struct diff_options {
 	const char *stat_sep;
 	long xdl_opts;
 
+	char *submodule_log_format;
+
 	int stat_width;
 	int stat_name_width;
 	int stat_graph_width;
diff --git a/submodule.c b/submodule.c
index e3e0b45..149bd87 100644
--- a/submodule.c
+++ b/submodule.c
@@ -217,12 +217,16 @@ static int prepare_submodule_summary(struct rev_info *rev, const char *path,
 }
 
 static void print_submodule_summary(struct rev_info *rev, FILE *f,
-		const char *del, const char *add, const char *reset)
+		const char *del, const char *add, const char *reset,
+		const char *format)
 {
-	static const char format[] = "  %m %s";
+	static const char default_format[] = "  %m %s";
 	struct strbuf sb = STRBUF_INIT;
 	struct commit *commit;
 
+	if (!format)
+		format = default_format;
+
 	while ((commit = get_revision(rev))) {
 		struct pretty_print_context ctx = {0};
 		ctx.date_mode = rev->date_mode;
@@ -259,7 +263,8 @@ int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg)
 void show_submodule_summary(FILE *f, const char *path,
 		unsigned char one[20], unsigned char two[20],
 		unsigned dirty_submodule,
-		const char *del, const char *add, const char *reset)
+		const char *del, const char *add, const char *reset,
+		const char *format)
 {
 	struct rev_info rev;
 	struct commit *left = left, *right = right;
@@ -304,7 +309,7 @@ void show_submodule_summary(FILE *f, const char *path,
 	fwrite(sb.buf, sb.len, 1, f);
 
 	if (!message) {
-		print_submodule_summary(&rev, f, del, add, reset);
+		print_submodule_summary(&rev, f, del, add, reset, format);
 		clear_commit_marks(left, ~0);
 		clear_commit_marks(right, ~0);
 	}
diff --git a/submodule.h b/submodule.h
index f2e8271..49a7b75 100644
--- a/submodule.h
+++ b/submodule.h
@@ -21,7 +21,8 @@ int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg);
 void show_submodule_summary(FILE *f, const char *path,
 		unsigned char one[20], unsigned char two[20],
 		unsigned dirty_submodule,
-		const char *del, const char *add, const char *reset);
+		const char *del, const char *add, const char *reset,
+		const char *format);
 void set_config_fetch_recurse_submodules(int value);
 void check_for_new_submodule_commits(unsigned char new_sha1[20]);
 int fetch_populated_submodules(const struct argv_array *options,

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] custom log formats for "diff --submodule=log"
  2012-11-08 20:29 [PATCH] custom log formats for "diff --submodule=log" Jeff King
@ 2012-11-11 11:26 ` Ramkumar Ramachandra
  2012-11-11 13:05   ` Ramkumar Ramachandra
  0 siblings, 1 reply; 4+ messages in thread
From: Ramkumar Ramachandra @ 2012-11-11 11:26 UTC (permalink / raw
  To: Jeff King; +Cc: git, Jeffrey S. Haemer

Hi Peff,

Jeff King wrote:
> An off-list discussion made me wonder if something like this would be
> useful:
>
>   git log -p --submodule=log:'  %m %an <%ae>: %s'
>
> where the format could be whatever you find useful.

Interesting.  Don't you mean `git diff` in place of `git log -p`
though?  I don't think `git log --submodule` does anything differently
from `git log`.  Should this respect format.pretty?  Does it?

Ram

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] custom log formats for "diff --submodule=log"
  2012-11-11 11:26 ` Ramkumar Ramachandra
@ 2012-11-11 13:05   ` Ramkumar Ramachandra
  2012-11-12 22:19     ` Jeff King
  0 siblings, 1 reply; 4+ messages in thread
From: Ramkumar Ramachandra @ 2012-11-11 13:05 UTC (permalink / raw
  To: Jeff King; +Cc: git, Jeffrey S. Haemer

Hi again,

Ramkumar Ramachandra wrote:
> Don't you mean `git diff` in place of `git log -p`
> though?  I don't think `git log --submodule` does anything differently
> from `git log`.

Sorry for the nonsense.  I just realized that it affects the diffs
shown by `git log -p`.

Ram

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] custom log formats for "diff --submodule=log"
  2012-11-11 13:05   ` Ramkumar Ramachandra
@ 2012-11-12 22:19     ` Jeff King
  0 siblings, 0 replies; 4+ messages in thread
From: Jeff King @ 2012-11-12 22:19 UTC (permalink / raw
  To: Ramkumar Ramachandra; +Cc: git, Jeffrey S. Haemer

On Sun, Nov 11, 2012 at 06:35:16PM +0530, Ramkumar Ramachandra wrote:

> Ramkumar Ramachandra wrote:
> > Don't you mean `git diff` in place of `git log -p`
> > though?  I don't think `git log --submodule` does anything differently
> > from `git log`.
> 
> Sorry for the nonsense.  I just realized that it affects the diffs
> shown by `git log -p`.

Right. I don't know if that is a common workflow (I do not really use
submodules), but it was the first thing I tried when I heard about
--submodule (and it does make sense to me that it would work).

But the logic could apply equally well to:

  git diff --submodule=log:%an

-Peff

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-11-12 22:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-08 20:29 [PATCH] custom log formats for "diff --submodule=log" Jeff King
2012-11-11 11:26 ` Ramkumar Ramachandra
2012-11-11 13:05   ` Ramkumar Ramachandra
2012-11-12 22:19     ` Jeff King

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).