git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] add pretty format configuration to git log/show/whatchanged

From
Denis Cheng <crquan@gmail.com>
Date
Mar 1, 2008, 19:50 UTC
Message-ID
<1204401056-8763-1-git-send-email-crquan@gmail.com>
In-Reply-To
<alpine.LSU.1.00.0803011821420.22527@racer.site>
 * New configuration variable "format.pretty" can be used
    in git log/show/whatchanged.
the "format.pretty" configuration's design background is that I often use
"--pretty=fuller" on my command line, and different "--pretty=format:..."
 on my different local repos, I hope there is a configuration to store this
to git-config, and I think many people also need this to avoid specifying
"--pretty=..." every time.
with applying the patch, code in `git log/show/whatchanged` executed in
the following order:
1. call to gitconfig will set static fmt_pretty according to user's git-config:
   if the user never config "format.pretty", fmt_pretty doesn't need to be
   initialized;
2. rev->commit_format set to CMIT_FMT_DEFAULT in init_revisions;
3. set rev->commit_format according to fmt_pretty if the user has configured
   "format.pretty" in git-config, else default to CMIT_FMT_DEFAULT;
4. setup_revisions will accept "--pretty=" from the command line;
so the pretty format's setting precedence will be:
1. the command line "--pretty=";
2. "format.pretty" from the git-config;
3. default CMIT_FMT_DEFAULT;
here documentation of `git config/log/show/whatchanged` also updated.
Signed-off-by: Denis Cheng <crquan@gmail.com>
---
to Johannes: rev->commit_format default to CMIT_FMT_DEFAULT instead of fmt_pretty
could avoid an extra call to get_commit_format.
---
 Documentation/config.txt          |    5 +++++
 Documentation/git-whatchanged.txt |    9 ++++-----
 Documentation/pretty-options.txt  |    8 ++++++++
 builtin-log.c                     |    9 +++++++++
 4 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 4027726..8a0dff9 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -556,6 +556,11 @@ format.suffix::
 	`.patch`. Use this variable to change that suffix (make sure to
 	include the dot if you want it).
 
+format.pretty::
+	The default pretty format for log/show/whatchanged command,
+	See linkgit:git-log[1], linkgit:git-show[1],
+	linkgit:git-whatchanged[1].
+
 gc.aggressiveWindow::
 	The window size parameter used in the delta compression
 	algorithm used by 'git gc --aggressive'.  This defaults
diff --git a/Documentation/git-whatchanged.txt b/Documentation/git-whatchanged.txt
index 54947b6..a6e7bd4 100644
--- a/Documentation/git-whatchanged.txt
+++ b/Documentation/git-whatchanged.txt
@@ -38,11 +38,6 @@ OPTIONS
 	Show git internal diff output, but for the whole tree,
 	not just the top level.
 
---pretty=<format>::
-	Controls the output format for the commit logs.
-	<format> can be one of 'raw', 'medium', 'short', 'full',
-	and 'oneline'.
-
 -m::
 	By default, differences for merge commits are not shown.
 	With this flag, show differences to that commit from all
@@ -51,6 +46,10 @@ OPTIONS
 However, it is not very useful in general, although it
 *is* useful on a file-by-file basis.
 
+include::pretty-options.txt[]
+
+include::pretty-formats.txt[]
+
 Examples
 --------
 git-whatchanged -p v2.6.12.. include/scsi drivers/scsi::
diff --git a/Documentation/pretty-options.txt b/Documentation/pretty-options.txt
index 973d8dd..15e01fa 100644
--- a/Documentation/pretty-options.txt
+++ b/Documentation/pretty-options.txt
@@ -4,6 +4,14 @@
 	where '<format>' can be one of 'oneline', 'short', 'medium',
 	'full', 'fuller', 'email', 'raw' and 'format:<string>'.
 	When omitted, the format defaults to 'medium'.
++
+Note: now you can specify the default pretty format in the repository
+configuration (see linkgit:git-config[1]), like this in .git/config:
++
+-----------------------
+[format]
+	pretty = fuller
+-----------------------
 
 --abbrev-commit::
 	Instead of showing the full 40-byte hexadecimal commit object
diff --git a/builtin-log.c b/builtin-log.c
index bbadbc0..23c05bc 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -20,6 +20,7 @@
 
 static int default_show_root = 1;
 static const char *fmt_patch_subject_prefix = "PATCH";
+static const char *fmt_pretty;
 
 static void add_name_decoration(const char *prefix, const char *name, struct object *obj)
 {
@@ -54,6 +55,8 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
 
 	rev->abbrev = DEFAULT_ABBREV;
 	rev->commit_format = CMIT_FMT_DEFAULT;
+	if (fmt_pretty)
+		rev->commit_format = get_commit_format(fmt_pretty);
 	rev->verbose_header = 1;
 	DIFF_OPT_SET(&rev->diffopt, RECURSIVE);
 	rev->show_root_diff = default_show_root;
@@ -221,6 +224,12 @@ static int cmd_log_walk(struct rev_info *rev)
 
 static int git_log_config(const char *var, const char *value)
 {
+	if (!strcmp(var, "format.pretty")) {
+		if (!value)
+			config_error_nonbool(var);
+		fmt_pretty = xstrdup(value);
+		return 0;
+	}
 	if (!strcmp(var, "format.subjectprefix")) {
 		if (!value)
 			config_error_nonbool(var);
-- 
1.5.4.2
Previous: Johannes SchindelinNext: Junio C Hamano
Message 6 of 15 in “pretty format now configurable”
  1. pretty format now configurableDenis Cheng, Feb 29, 2008
  2. Linus TorvaldsFeb 29, 2008
  3. rae lMar 1, 2008
  4. add pretty format configuration to git log/show/whatchangedDenis Cheng, Mar 1, 2008
  5. Johannes SchindelinMar 1, 2008
  6. add pretty format configuration to git log/show/whatchangedDenis Cheng, Mar 1, 2008
  7. Junio C HamanoMar 2, 2008
  8. Junio C HamanoMar 2, 2008
  9. 1/3 whatchanged documentation: share description of --pretty with othersDenis Cheng, Mar 2, 2008
  10. 2/3 specify explicit "--pretty=medium" with `git log/show/whatchanged`Denis Cheng, Mar 2, 2008
  11. 3/3 log/show/whatchanged: introduce format.pretty configurationDenis Cheng, Mar 2, 2008
  12. Junio C HamanoMar 2, 2008
  13. rae lMar 2, 2008
  14. Junio C HamanoMar 2, 2008
  15. Johannes SchindelinFeb 29, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.