git stash list with more than 10 items?
Hi,
Is it possible to make "git stash list" show more than 10 items?
Jef
Quoted 1 line · Jef Driesen
Is it possible to make "git stash list" show more than 10 items?
Try "git stash list -30".
Stash listing is internally just "git log -g refs/stash", so you can pass any formatting or limiting arguments you want there (see the git log documentation for ideas). If no arguments are given, we pass "-10".
-Peff
PATCH 1/1 git-stash documentation: mention default options for 'list'
---
I just noticed this was not mentioned in the manpage.
Documentation/git-stash.txt | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
Documentation/git-stash.txt +2 -1
@@ -78,7 +78,8 @@ stash@{1}: On master: 9cc0589... Add git-stash ---------------------------------------------------------------- + The command takes options applicable to the 'git-log' -command to control what is shown and how. See linkgit:git-log[1]. +command to control what is shown and how. If no options are set, the +default is `-n 10`. See linkgit:git-log[1]. show [<stash>]::
Signature · 1 line
1.6.4
Re: [PATCH] git-stash documentation: mention default options for 'list'
Quoted 1 line · Miklos Vajna
I just noticed this was not mentioned in the manpage.
Thanks, looks like an improvement to me.
-Peff
cover Pretty formats for reflog data
In reply to Jeff King[I forgot to address the list on the first batch, sorry for the spam.]
Quoted 9 lines · Jeff King
Quoted 1 line · Jef Driesen
Is it possible to make "git stash list" show more than 10 items?
Try "git stash list -30".
Stash listing is internally just "git log -g refs/stash", so you can pass any formatting or limiting arguments you want there (see the git log documentation for ideas). If no arguments are given, we pass "-10".
This seems fairly arbitrary, doesn't it? My own working theory is that Nanako put it in because the git-log|sed construct inherently bars any way to a pager, so it needs to be cut short.
So suppose we could somehow get rid of the |sed... like if we had --pretty specifiers for the reflog information.
Sadly
git log -g --format="%h %g: %G"
still fails to exactly replicate the reflog format: if the reflog was cut off during garbage collection, the last entry refers to a no longer existing commit causing a stray ':' on that line. Oh, well.
It's also still RFC because:
* I don't like the massive code churn in 2/5, maybe someone sees a better option.
* 5/5 has a pretty lame excuse. I could also just change it in 'git stash list' to limit the backwards-incompatibility damage, but that's also a maintenance headache.
Thomas Rast (5):
reflog-walk: refactor the branch@{num} formatting Introduce new pretty formats %g and %G for reflog information
stash: Use new %g/%G formats instead of sed
stash list: drop the default limit of 10 stashes
stash: change built-in ref to 'stash' instead of 'refs/stash'
archive.c | 2 +- builtin-branch.c | 3 +- builtin-checkout.c | 2 +- builtin-commit.c | 4 +- builtin-log.c | 2 +- builtin-merge.c | 2 +- builtin-rev-list.c | 2 +- builtin-shortlog.c | 2 +- builtin-show-branch.c | 2 +- commit.h | 7 +++- git-stash.sh | 10 +----- log-tree.c | 4 +- pretty.c | 20 +++++++++++-- reflog-walk.c | 72 ++++++++++++++++++++++++++++++++++--------------- reflog-walk.h | 7 +++++ 15 files changed, 94 insertions(+), 47 deletions(-)
RFC PATCH 1/5 reflog-walk: refactor the branch@{num} formatting
We'll use the same output in an upcoming commit, so refactor its formatting (which was duplicated anyway) into a separate function.
--- reflog-walk.c | 56 ++++++++++++++++++++++++++++++++++---------------------- 1 files changed, 34 insertions(+), 22 deletions(-)
reflog-walk.c +34 -22
@@ -241,36 +241,48 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit) commit->object.flags &= ~(ADDED |SEEN |SHOWN ); } -void show_reflog_message (struct reflog_walk_info *info,int oneline, +void get_reflog_selector (struct strbuf *sb, +struct reflog_walk_info *reflog_info, +enum date_mode dmode) +{ +struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog; +struct reflog_info *info; + +if (!commit_reflog) +return ; + +strbuf_addf (sb,"%s@{" , commit_reflog->reflogs->ref); +if (commit_reflog->flag || dmode) { + info = &commit_reflog->reflogs->items[commit_reflog->recno+1 ]; +strbuf_addf (sb,"%s" ,show_date (info->timestamp, + info->tz, + dmode)); + }else { +strbuf_addf (sb,"%d" , commit_reflog->reflogs->nr + -2 - commit_reflog->recno); + } + +strbuf_addch (sb,'}' ); +} + +void show_reflog_message (struct reflog_walk_info *reflog_info,int oneline,enum date_mode dmode) { -if (info && info->last_commit_reflog) { -struct commit_reflog *commit_reflog = info->last_commit_reflog; +if (reflog_info && reflog_info->last_commit_reflog) { +struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog;struct reflog_info *info; +struct strbuf selector =STRBUF_INIT ; info = &commit_reflog->reflogs->items[commit_reflog->recno+1 ]; +get_reflog_selector (&selector, reflog_info, dmode);if (oneline) { -printf ("%s@{" , commit_reflog->reflogs->ref); -if (commit_reflog->flag || dmode) -printf ("%s" ,show_date (info->timestamp, - info->tz, - dmode)); -else -printf ("%d" , commit_reflog->reflogs->nr - -2 - commit_reflog->recno); -printf ("}: %s" , info->message); +printf ("%s: %s" , selector.buf, info->message); }else { -printf ("Reflog: %s@{" , commit_reflog->reflogs->ref); -if (commit_reflog->flag || dmode) -printf ("%s" ,show_date (info->timestamp, - info->tz, - dmode)); -else -printf ("%d" , commit_reflog->reflogs->nr - -2 - commit_reflog->recno); -printf ("} (%s)\nReflog message: %s" , - info->email, info->message); +printf ("Reflog: %s (%s)\nReflog message: %s" , + selector.buf, info->email, info->message); } + +strbuf_release (&selector); } }
Signature · 1 line
1.6.5.64.g01287
RFC PATCH 2/5 Introduce new pretty formats %g and %G for reflog information
In reply to Thomas RastAdd two new pretty escapes: %g expands to the reflog selector (i.e., branch@{number} or branch@{date}) and %G expands to the reflog message.
We use the newly refactored selector formatting function and introduce another wrapper to get the reflog message.
Unfortunately, we also need to pass down the reflog_walk_info from show_log(), so this commit touches a lot of (unrelated) callers to pretty_print_commit() and format_commit_message() to accomodate the extra argument.
--- archive.c | 2 +- builtin-branch.c | 3 ++- builtin-checkout.c | 2 +- builtin-commit.c | 4 ++-- builtin-log.c | 2 +- builtin-merge.c | 2 +- builtin-rev-list.c | 2 +- builtin-shortlog.c | 2 +- builtin-show-branch.c | 2 +- commit.h | 7 +++++-- log-tree.c | 4 ++-- pretty.c | 20 +++++++++++++++++--- reflog-walk.c | 16 ++++++++++++++++ reflog-walk.h | 7 +++++++ 14 files changed, 58 insertions(+), 17 deletions(-)
archive.c +1 -1
@@ -48,7 +48,7 @@ static void format_subst(const struct commit *commit,strbuf_add (&fmt, b +8 , c - b -8 );strbuf_add (buf, src, b - src); -format_commit_message (commit, fmt.buf, buf,DATE_NORMAL ); +format_commit_message (commit, fmt.buf, buf,DATE_NORMAL ,NULL ); len -= c +1 - src; src = c +1 ; }
builtin-branch.c +2 -1
@@ -388,7 +388,8 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose, commit = item->commit;if (commit && !parse_commit (commit)) {pretty_print_commit (CMIT_FMT_ONELINE , commit, - &subject,0 ,NULL ,NULL ,0 ,0 ); + &subject,0 ,NULL ,NULL ,0 ,0 , +NULL ); sub = subject.buf; }
builtin-checkout.c +1 -1
@@ -303,7 +303,7 @@ static void describe_detached_head(char *msg, struct commit *commit) {struct strbuf sb =STRBUF_INIT ;parse_commit (commit); -pretty_print_commit (CMIT_FMT_ONELINE , commit, &sb,0 ,NULL ,NULL ,0 ,0 ); +pretty_print_commit (CMIT_FMT_ONELINE , commit, &sb,0 ,NULL ,NULL ,0 ,0 ,NULL );fprintf (stderr,"%s %s... %s\n" , msg,find_unique_abbrev (commit->object.sha1,DEFAULT_ABBREV ), sb.buf);strbuf_release (&sb);
builtin-commit.c +2 -2
@@ -685,7 +685,7 @@ static int message_is_empty(struct strbuf *sb) commit =get_revision (&revs);if (commit) {strbuf_release (&buf); -format_commit_message (commit,"%an <%ae>" , &buf,DATE_NORMAL ); +format_commit_message (commit,"%an <%ae>" , &buf,DATE_NORMAL ,NULL );return strbuf_detach (&buf,NULL ); }die ("No existing author found with '%s'" , name);
@@ -943,7 +943,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1)if (!log_tree_commit (&rev, commit)) {struct strbuf buf =STRBUF_INIT ; -format_commit_message (commit, format +7 , &buf,DATE_NORMAL ); +format_commit_message (commit, format +7 , &buf,DATE_NORMAL ,NULL );printf ("%s\n" , buf.buf);strbuf_release (&buf); }
builtin-log.c +1 -1
@@ -1305,7 +1305,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)if (verbose) {struct strbuf buf =STRBUF_INIT ;pretty_print_commit (CMIT_FMT_ONELINE , commit, - &buf,0 ,NULL ,NULL ,0 ,0 ); + &buf,0 ,NULL ,NULL ,0 ,0 ,NULL );printf ("%c %s %s\n" , sign,sha1_to_hex (commit->object.sha1), buf.buf);strbuf_release (&buf);
builtin-merge.c +1 -1
@@ -291,7 +291,7 @@ static void squash_message(void)strbuf_addf (&out,"commit %s\n" ,sha1_to_hex (commit->object.sha1));pretty_print_commit (rev.commit_format, commit, &out, rev.abbrev, -NULL ,NULL , rev.date_mode,0 ); +NULL ,NULL , rev.date_mode,0 ,NULL ); }if (write (fd, out.buf, out.len) <0 )die_errno ("Writing SQUASH_MSG" );
builtin-rev-list.c +1 -1
@@ -98,7 +98,7 @@ static void show_commit(struct commit *commit, void *data)struct strbuf buf =STRBUF_INIT ;pretty_print_commit (revs->commit_format, commit, &buf, revs->abbrev,NULL ,NULL , - revs->date_mode,0 ); + revs->date_mode,0 ,NULL );if (revs->graph) {if (buf.len) {if (revs->commit_format !=CMIT_FMT_ONELINE )
builtin-shortlog.c +1 -1
@@ -160,7 +160,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)struct strbuf buf =STRBUF_INIT ;pretty_print_commit (CMIT_FMT_USERFORMAT , commit, &buf, -DEFAULT_ABBREV ,"" ,"" ,DATE_NORMAL ,0 ); +DEFAULT_ABBREV ,"" ,"" ,DATE_NORMAL ,0 ,NULL );insert_one_record (log, author, buf.buf);strbuf_release (&buf);return ;
builtin-show-branch.c +1 -1
@@ -294,7 +294,7 @@ static void show_one_commit(struct commit *commit, int no_name)if (commit->object.parsed) {pretty_print_commit (CMIT_FMT_ONELINE , commit, - &pretty,0 ,NULL ,NULL ,0 ,0 ); + &pretty,0 ,NULL ,NULL ,0 ,0 ,NULL ); pretty_str = pretty.buf; }if (!prefixcmp (pretty_str,"[PATCH] " ))
commit.h +5 -2
@@ -69,14 +69,17 @@ enum cmit_fmt {extern char *reencode_commit_message (const struct commit *commit,const char **encoding_p);extern void get_commit_format (const char *arg,struct rev_info *); +struct reflog_walk_info ;extern void format_commit_message (const struct commit *commit,const void *format,struct strbuf *sb, -enum date_mode dmode); +enum date_mode dmode, +struct reflog_walk_info *reflog_info);extern void pretty_print_commit (enum cmit_fmt fmt,const struct commit *,struct strbuf *,int abbrev,const char *subject,const char *after_subject,enum date_mode , -int need_8bit_cte); +int need_8bit_cte, +struct reflog_walk_info *reflog_info);void pp_user_info (const char *what,enum cmit_fmt fmt,struct strbuf *sb,const char *line,enum date_mode dmode,const char *encoding);
log-tree.c +2 -2
@@ -179,7 +179,7 @@ void get_patch_filename(struct commit *commit, int nr, const char *suffix,if (commit) {int max_len = start_len +FORMAT_PATCH_NAME_MAX - suffix_len; -format_commit_message (commit,"%f" , buf,DATE_NORMAL ); +format_commit_message (commit,"%f" , buf,DATE_NORMAL ,NULL );if (max_len < buf->len)strbuf_setlen (buf, max_len);strbuf_addstr (buf, suffix);
@@ -408,7 +408,7 @@ void show_log(struct rev_info *opt) need_8bit_cte =has_non_ascii (opt->add_signoff);pretty_print_commit (opt->commit_format, commit, &msgbuf, abbrev, subject, extra_headers, opt->date_mode, - need_8bit_cte); + need_8bit_cte, opt->reflog_info);if (opt->add_signoff)append_signoff (&msgbuf, opt->add_signoff);
pretty.c +17 -3
@@ -7,6 +7,7 @@#include "mailmap.h" #include "log-tree.h" #include "color.h" +#include "reflog-walk.h" static char *user_format;
@@ -443,6 +444,7 @@ struct chunk {struct format_commit_context {const struct commit *commit;enum date_mode dmode; +struct reflog_walk_info *reflog_info;unsigned commit_header_parsed:1 ;unsigned commit_message_parsed:1 ;
@@ -701,6 +703,14 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,case 'd' :format_decoration (sb, commit);return 1 ; +case 'g' :/* reflog handle */ +if (c->reflog_info) +get_reflog_selector (sb, c->reflog_info, c->dmode); +return 1 ; +case 'G' :/* reflog message */ +if (c->reflog_info) +get_reflog_message (sb, c->reflog_info); +return 1 ; }/* For the rest we have to parse the commit header. */
@@ -741,13 +751,15 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,void format_commit_message (const struct commit *commit,const void *format,struct strbuf *sb, -enum date_mode dmode) +enum date_mode dmode, +struct reflog_walk_info *reflog_info) {struct format_commit_context context;memset (&context,0 ,sizeof (context)); context.commit = commit; context.dmode = dmode; + context.reflog_info = reflog_info;strbuf_expand (sb, format, format_commit_item, &context); }
@@ -902,7 +914,8 @@ void pp_remainder(enum cmit_fmt fmt,void pretty_print_commit (enum cmit_fmt fmt,const struct commit *commit,struct strbuf *sb,int abbrev,const char *subject,const char *after_subject, -enum date_mode dmode,int need_8bit_cte) +enum date_mode dmode,int need_8bit_cte, +struct reflog_walk_info *reflog_info) {unsigned long beginning_of_body;int indent =4 ;
@@ -911,7 +924,8 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,const char *encoding;if (fmt ==CMIT_FMT_USERFORMAT ) { -format_commit_message (commit, user_format, sb, dmode); +format_commit_message (commit, user_format, sb, dmode, + reflog_info);return ; }
reflog-walk.c +16 -0
@@ -265,6 +265,22 @@ void get_reflog_selector(struct strbuf *sb,strbuf_addch (sb,'}' ); } +void get_reflog_message (struct strbuf *sb, +struct reflog_walk_info *reflog_info) +{ +struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog; +struct reflog_info *info; + +if (!commit_reflog) +return ; + + info = &commit_reflog->reflogs->items[commit_reflog->recno+1 ]; +size_t len =strlen (info->message); +if (len >0 ) + len--; +strbuf_add (sb, info->message, len); +} +void show_reflog_message (struct reflog_walk_info *reflog_info,int oneline,enum date_mode dmode) {
reflog-walk.h +7 -0
@@ -3,6 +3,8 @@#include "cache.h" +struct reflog_walk_info ; +extern void init_reflog_walk (struct reflog_walk_info ** info);extern int add_reflog_for_walk (struct reflog_walk_info *info,struct commit *commit,const char *name);
@@ -10,5 +12,10 @@ extern void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit);extern void show_reflog_message (struct reflog_walk_info *info,int ,enum date_mode ); +extern void get_reflog_message (struct strbuf *sb, +struct reflog_walk_info *reflog_info); +extern void get_reflog_selector (struct strbuf *sb, +struct reflog_walk_info *reflog_info, +enum date_mode dmode);#endif
Signature · 1 line
1.6.5.64.g01287
Re: [RFC PATCH 2/5] Introduce new pretty formats %g and %G for reflog information
Quoted 4 lines · Thomas Rast
Unfortunately, we also need to pass down the
reflog_walk_infofromshow_log(), so this commit touches a lot of (unrelated) callers topretty_print_commit()andformat_commit_message()to accomodate the extra argument.
A while back I wanted to add a feature to pretty-printing, and I ran into the same situation (though my feature never made it to the list). We really end up passing around the same arguments over and over. Maybe it makes sense instead of adding another argument to refactor into a "pretty_print_context" struct that contains all of the arguments and current state.
It would be an even more invasive patch, but I think it would make things more readable, and make future changes much easier to see.
-Peff
Re: [RFC PATCH 2/5] Introduce new pretty formats %g and %G for reflog information
Quoted 14 lines · Jeff King
Quoted 4 lines · Thomas Rast
Unfortunately, we also need to pass down the
reflog_walk_infofromshow_log(), so this commit touches a lot of (unrelated) callers topretty_print_commit()andformat_commit_message()to accomodate the extra argument.A while back I wanted to add a feature to pretty-printing, and I ran into the same situation (though my feature never made it to the list). We really end up passing around the same arguments over and over. Maybe it makes sense instead of adding another argument to refactor into a "
pretty_print_context" struct that contains all of the arguments and current state.
Quoted 2 lines
It would be an even more invasive patch, but I think it would make things more readable, and make future changes much easier to see.
Ok, I'll try for the next round.
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chRe: [RFC PATCH 2/5] Introduce new pretty formats %g and %G for reflog information
In reply to Thomas RastSquash this patch on top, as
cc1: warnings being treated as errors
reflog-walk.c: In function 'get_reflog_message':
reflog-walk.c:278: error: ISO C90 forbids mixed declarations and code
---
reflog-walk.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
reflog-walk.c +2 -1
@@ -270,12 +270,13 @@ void get_reflog_message(struct strbuf *sb, {struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog;struct reflog_info *info; +size_t len;if (!commit_reflog)return ; info = &commit_reflog->reflogs->items[commit_reflog->recno+1 ]; -size_t len =strlen (info->message); + len =strlen (info->message);if (len >0 ) len--;strbuf_add (sb, info->message, len);
Re: [RFC PATCH 0/5] Pretty formats for reflog data
In reply to Thomas RastQuoted 7 lines · Thomas Rast
Quoted 3 lines
Stash listing is internally just "git log -g refs/stash", so you can pass any formatting or limiting arguments you want there (see the git log documentation for ideas). If no arguments are given, we pass "-10".
This seems fairly arbitrary, doesn't it? My own working theory is that Nanako put it in because the git-log|sed construct inherently bars any way to a pager, so it needs to be cut short.
Yes, it's arbitrary, though it is probably a reasonable estimate for the intended use of stash. It's a stack, so you generally are only interested in the last couple of entries.
What's much worse though is that the logic is not "if you told me how many to show, show that; otherwise, show 10". Instead it is "if you gave me no options, default the size of the list. But if you gave me any options, even if they have nothing whatsoever to do with limiting the size of the list, then show all".
So something like "git stash list --date=relative" suddenly shows many more stashes than just "git stash list". It would be nice to fix that.
Quoted 2 lines
So suppose we could somehow get rid of the |sed... like if we had --pretty specifiers for the reflog information.
I'm not sure if people will like having a longer list in a pager than a shorter list without one (I personally can't remember ever using "git stash list", so I have no strong opinion).
But certainly the idea of adding pretty format specifiers to access reflog data seems like a good idea on its own.
-Peff
Re: [RFC PATCH 0/5] Pretty formats for reflog data
Quoted 4 lines · Jeff King
I'm not sure if people will like having a longer [stash] list in a pager than a shorter list without one (I personally can't remember ever using "git stash list", so I have no strong opinion).
True. Then again we patched git-stash(1) to recommend stash/pop over stash/apply, so we should actively show the user that s/he has a long stash list and may want to apply them somewhere.
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chRFC PATCH 3/5 stash: Use new %g/%G formats instead of sed
In reply to Thomas RastWith the new formats, we can rewrite 'git stash list' in terms of an appropriate pretty format, instead of hand-editing with sed. This has the advantage that it obeys the normal settings for git-log, notably the pager.
--- git-stash.sh | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
git-stash.sh +1 -2
@@ -205,8 +205,7 @@ have_stash () { list_stash () { have_stash || return 0 - git log --no-color --pretty=oneline -g "$@" $ref_stash -- | - sed -n -e 's/^[.0-9a-f]* refs\///p' + git log --format="%g: %G" -g "$@" $ref_stash } show_stash () {
Signature · 1 line
1.6.5.64.g01287
Re: [RFC PATCH 3/5] stash: Use new %g/%G formats instead of sed
git-stash.sh have_stash () { · line 208
Quoted 5 lines · Thomas Rast
list_stash() {git-stash.sh +1
-2have_stash || return 0 - git log --no-color --pretty=oneline -g "$@" $ref_stash -- | - sed -n -e 's/^[.0-9a-f]* refs\///p' + git log --format="%g: %G" -g "$@" $ref_stash
You dropped the trailing "--" which is needed for disambiguation.
-Peff
RFC PATCH 4/5 stash list: drop the default limit of 10 stashes
In reply to Thomas Rast'git stash list' had an undocumented limit of 10 stashes, unless other git-log arguments were specified. This surprised at least one user, but possibly served to cut the output below a screenful without using a pager.
Since the last commit, 'git stash list' will fire up a pager according to the same rules as the 'git log' it calls, so we can drop the limit.
--- git-stash.sh | 5 ----- 1 files changed, 0 insertions(+), 5 deletions(-)
git-stash.sh +0 -5
@@ -382,11 +382,6 @@ test -n "$seen_non_option" || set "save" "$@" case "$1" in list) shift - if test $# = 0 - then - set x -n 10 - shift - fi list_stash "$@" ;; show)
Signature · 1 line
1.6.5.64.g01287
Re: [RFC PATCH 4/5] stash list: drop the default limit of 10 stashes
Quoted 7 lines · Thomas Rast
'git stash list' had an undocumented limit of 10 stashes, unless other git-log arguments were specified. This surprised at least one user, but possibly served to cut the output below a screenful without using a pager.
Since the last commit, 'git stash list' will fire up a pager according to the same rules as the 'git log' it calls, so we can drop the limit.
Having slept on it, I think I agree that this is a good change. It fixes the ugly corner cases I mentioned, and it is easier to explain.
-Peff
RFC PATCH 5/5 stash: change built-in ref to 'stash' instead of 'refs/stash'
In reply to Thomas Rast'git stash list' now always shows 'refs/stash@{...}' instead of 'stash@{...}', because that's what we specify for the ref.
Since git checks .git/$ref, .git/refs/$ref and only then .git/refs/{branches,tags,remotes}, we can drop the prefix. This only affects people who have .git/stash, who were never able to refer to their stashes by stash@{...}. (Sadly, now they won't be able to use git-stash anymore at all.)
--- git-stash.sh | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
git-stash.sh +1 -1
@@ -19,7 +19,7 @@ cd_to_toplevel TMP="$GIT_DIR/.git-stash.$$" trap 'rm -f "$TMP-*"' 0 -ref_stash=refs/stash +ref_stash=stash if git config --get-colorbool color.interactive; then help_color="$(git config --get-color color.interactive.help 'red bold')"
Signature · 1 line
1.6.5.64.g01287
Re: [RFC PATCH 5/5] stash: change built-in ref to 'stash' instead of 'refs/stash'
Quoted 8 lines · Thomas Rast
'git stash list' now always shows 'refs/stash@{...}' instead of 'stash@{...}', because that's what we specify for the ref.
Since git checks .git/$ref, .git/refs/$ref and only then .git/refs/{branches,tags,remotes}, we can drop the prefix. This only affects people who have .git/stash, who were never able to refer to their stashes by stash@{...}. (Sadly, now they won't be able to use git-stash anymore at all.)
Maybe a better solution would be a "short name" variant for pretty format specifiers. We already have %(refname) and %(refname:short) in for-each-ref, where the latter cuts off "refs/heads/", "refs/tags", or "refs/remotes/" from the beginning. I'm not sure if it does just "refs/", but probably it should. It may even check for ambiguity, but I'd have to double-check the code.
The tricky part would be deciding on a syntax. This seems to come up a fair bit. I think there is room for somebody to suggest a more expansive --format syntax that can handle arbitrary arguments being given to expansions (I think there was some discussion recently in a related thread about body indentation, but I haven't been following it too closely).
-Peff
v2 cover Pretty formats for reflog data
Quoted 4 lines · Jeff King
Maybe a better solution would be a "short name" variant for pretty format specifiers. We already have %(refname) and %(refname:short) [...] The tricky part would be deciding on a syntax. This seems to come up a fair bit.
Ok, I settled for %g[dDs] for now to save on letters. I'm saving the syntax question for a later series while we discuss this one ;-)
I think going for %(...) wouldn't be too bad since we already have that in for-each-ref, and it can be backwards compatible. So we would have different sets of short and long specifiers, e.g.
%ae = %(authoremail)
%aE = %(authoremail:mailmap)
We can then pass arguments via some yet-to-be decided syntax, say, %(body:indent(10)).
Other changes in this version include:
* I followed your struct suggestion, which is the new 1/5.
* Since the shortening can be handled by %gd, the old 5/5 (change from refs/stash to only stash) is no longer needed.
* I fixed the warning that Junio found (and finally found the right combination of -W flags, though I cannot compile with -Werror myself because of *other* warnings...)
I also added tests and docs to the main patch (now 3/5).
Thomas Rast (5):
Refactor pretty_print_commit arguments into a struct
reflog-walk: refactor the branch@{num} formatting Introduce new pretty formats %g[sdD] for reflog information stash list: use new %g formats instead of sed stash list: drop the default limit of 10 stashes
Documentation/pretty-formats.txt | 3 + builtin-branch.c | 3 +- builtin-checkout.c | 3 +- builtin-log.c | 3 +- builtin-merge.c | 7 ++- builtin-rev-list.c | 7 ++- builtin-shortlog.c | 9 +++- builtin-show-branch.c | 4 +- commit.h | 20 ++++++--- git-stash.sh | 8 +--- log-tree.c | 21 +++++---- pretty.c | 44 ++++++++++++++------ reflog-walk.c | 85 ++++++++++++++++++++++++++++---------- reflog-walk.h | 8 ++++ t/t1411-reflog-show.sh | 12 +++++ 15 files changed, 166 insertions(+), 71 deletions(-)
PATCH v2 1/5 Refactor pretty_print_commit arguments into a struct
pretty_print_commit() has a bunch of rarely-used arguments, and introducing more of them requires yet another update of all the call sites. Refactor most of them into a struct to make future extensions easier.
The ones that stay "plain" arguments were chosen on the grounds that all callers put real arguments there, whereas some callers have 0/NULL for all arguments that were factored into the struct.
We declare the struct 'const' to ensure none of the callers are bitten by the changed (no longer call-by-value) semantics.
--- builtin-branch.c | 3 ++- builtin-checkout.c | 3 ++- builtin-log.c | 3 ++- builtin-merge.c | 7 +++++-- builtin-rev-list.c | 7 ++++--- builtin-shortlog.c | 9 ++++++--- builtin-show-branch.c | 4 ++-- commit.h | 19 +++++++++++++------ log-tree.c | 20 ++++++++++---------- pretty.c | 27 ++++++++++++++------------- 10 files changed, 60 insertions(+), 42 deletions(-)
builtin-branch.c +2 -1
@@ -387,8 +387,9 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose, commit = item->commit;if (commit && !parse_commit (commit)) { +struct pretty_print_context ctx = {0 };pretty_print_commit (CMIT_FMT_ONELINE , commit, - &subject,0 ,NULL ,NULL ,0 ,0 ); + &subject, &ctx); sub = subject.buf; }
builtin-checkout.c +2 -1
@@ -302,8 +302,9 @@ static void show_local_changes(struct object *head)static void describe_detached_head (char *msg,struct commit *commit) {struct strbuf sb =STRBUF_INIT ; +struct pretty_print_context ctx = {0 };parse_commit (commit); -pretty_print_commit (CMIT_FMT_ONELINE , commit, &sb,0 ,NULL ,NULL ,0 ,0 ); +pretty_print_commit (CMIT_FMT_ONELINE , commit, &sb, &ctx);fprintf (stderr,"%s %s... %s\n" , msg,find_unique_abbrev (commit->object.sha1,DEFAULT_ABBREV ), sb.buf);strbuf_release (&sb);
builtin-log.c +2 -1
@@ -1304,8 +1304,9 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)if (verbose) {struct strbuf buf =STRBUF_INIT ; +struct pretty_print_context ctx = {0 };pretty_print_commit (CMIT_FMT_ONELINE , commit, - &buf,0 ,NULL ,NULL ,0 ,0 ); + &buf, &ctx);printf ("%c %s %s\n" , sign,sha1_to_hex (commit->object.sha1), buf.buf);strbuf_release (&buf);
builtin-merge.c +5 -2
@@ -264,6 +264,7 @@ static void squash_message(void)struct strbuf out =STRBUF_INIT ;struct commit_list *j;int fd; +struct pretty_print_context ctx = {0 };printf ("Squash commit -- not updating HEAD\n" ); fd =open (git_path ("SQUASH_MSG" ),O_WRONLY |O_CREAT ,0666 );
@@ -285,13 +286,15 @@ static void squash_message(void)if (prepare_revision_walk (&rev))die ("revision walk setup failed" ); + ctx.abbrev = rev.abbrev; + ctx.date_mode = rev.date_mode; +strbuf_addstr (&out,"Squashed commit of the following:\n" );while ((commit =get_revision (&rev)) !=NULL ) {strbuf_addch (&out,'\n' );strbuf_addf (&out,"commit %s\n" ,sha1_to_hex (commit->object.sha1)); -pretty_print_commit (rev.commit_format, commit, &out, rev.abbrev, -NULL ,NULL , rev.date_mode,0 ); +pretty_print_commit (rev.commit_format, commit, &out, &ctx); }if (write (fd, out.buf, out.len) <0 )die_errno ("Writing SQUASH_MSG" );
builtin-rev-list.c +4 -3
@@ -96,9 +96,10 @@ static void show_commit(struct commit *commit, void *data)if (revs->verbose_header && commit->buffer) {struct strbuf buf =STRBUF_INIT ; -pretty_print_commit (revs->commit_format, commit, - &buf, revs->abbrev,NULL ,NULL , - revs->date_mode,0 ); +struct pretty_print_context ctx = {0 }; + ctx.abbrev = revs->abbrev; + ctx.date_mode = revs->date_mode; +pretty_print_commit (revs->commit_format, commit, &buf, &ctx);if (revs->graph) {if (buf.len) {if (revs->commit_format !=CMIT_FMT_ONELINE )
builtin-shortlog.c +6 -3
@@ -158,9 +158,12 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit) sha1_to_hex(commit->object.sha1));if (log->user_format) {struct strbuf buf =STRBUF_INIT ; - -pretty_print_commit (CMIT_FMT_USERFORMAT , commit, &buf, -DEFAULT_ABBREV ,"" ,"" ,DATE_NORMAL ,0 ); +struct pretty_print_context ctx = {0 }; + ctx.abbrev =DEFAULT_ABBREV ; + ctx.subject ="" ; + ctx.after_subject ="" ; + ctx.date_mode =DATE_NORMAL ; +pretty_print_commit (CMIT_FMT_USERFORMAT , commit, &buf, &ctx);insert_one_record (log, author, buf.buf);strbuf_release (&buf);return ;
builtin-show-branch.c +2 -2
@@ -293,8 +293,8 @@ static void show_one_commit(struct commit *commit, int no_name)struct commit_name *name = commit->util;if (commit->object.parsed) { -pretty_print_commit (CMIT_FMT_ONELINE , commit, - &pretty,0 ,NULL ,NULL ,0 ,0 ); +struct pretty_print_context ctx = {0 }; +pretty_print_commit (CMIT_FMT_ONELINE , commit, &pretty, &ctx); pretty_str = pretty.buf; }if (!prefixcmp (pretty_str,"[PATCH] " ))
commit.h +13 -6
@@ -63,6 +63,15 @@ enum cmit_fmt { CMIT_FMT_UNSPECIFIED, }; +struct pretty_print_context +{ +int abbrev; +const char *subject; +const char *after_subject; +enum date_mode date_mode; +int need_8bit_cte; +}; +extern int non_ascii (int );extern int has_non_ascii (const char *text);struct rev_info ;/* in revision.h, it circularly uses enum cmit_fmt */
@@ -71,12 +80,10 @@ enum cmit_fmt {extern void get_commit_format (const char *arg,struct rev_info *);extern void format_commit_message (const struct commit *commit,const void *format,struct strbuf *sb, -enum date_mode dmode); -extern void pretty_print_commit (enum cmit_fmt fmt,const struct commit *, -struct strbuf *, -int abbrev,const char *subject, -const char *after_subject,enum date_mode , -int need_8bit_cte); +const struct pretty_print_context *context); +extern void pretty_print_commit (enum cmit_fmt fmt,const struct commit *commit, +struct strbuf *sb, +const struct pretty_print_context *context);void pp_user_info (const char *what,enum cmit_fmt fmt,struct strbuf *sb,const char *line,enum date_mode dmode,const char *encoding);
log-tree.c +10 -10
@@ -277,10 +277,9 @@ void show_log(struct rev_info *opt)struct strbuf msgbuf =STRBUF_INIT ;struct log_info *log = opt->loginfo;struct commit *commit = log->commit, *parent = log->parent; -int abbrev = opt->diffopt.abbrev;int abbrev_commit = opt->abbrev_commit ? opt->abbrev :40 ; -const char *subject =NULL , *extra_headers = opt->extra_headers; -int need_8bit_cte =0 ; +const char *extra_headers = opt->extra_headers; +struct pretty_print_context ctx = {0 }; opt->loginfo =NULL ;if (!opt->verbose_header) {
@@ -347,8 +346,8 @@ void show_log(struct rev_info *opt)*/ if (opt->commit_format ==CMIT_FMT_EMAIL ) { -log_write_email_headers (opt, commit, &subject, &extra_headers, - &need_8bit_cte); +log_write_email_headers (opt, commit, &ctx.subject, &extra_headers, + &ctx.need_8bit_cte); }else if (opt->commit_format !=CMIT_FMT_USERFORMAT ) {fputs (diff_get_color_opt (&opt->diffopt,DIFF_COMMIT ), stdout);if (opt->commit_format !=CMIT_FMT_ONELINE )
@@ -405,11 +404,12 @@ void show_log(struct rev_info *opt)/* * And then the pretty-printed message itself */ -if (need_8bit_cte >=0 ) - need_8bit_cte =has_non_ascii (opt->add_signoff); -pretty_print_commit (opt->commit_format, commit, &msgbuf, - abbrev, subject, extra_headers, opt->date_mode, - need_8bit_cte); +if (ctx.need_8bit_cte >=0 ) + ctx.need_8bit_cte =has_non_ascii (opt->add_signoff); + ctx.date_mode = opt->date_mode; + ctx.abbrev = opt->diffopt.abbrev; + ctx.after_subject = extra_headers; +pretty_print_commit (opt->commit_format, commit, &msgbuf, &ctx);if (opt->add_signoff)append_signoff (&msgbuf, opt->add_signoff);
pretty.c +14 -13
@@ -442,7 +442,7 @@ struct chunk {struct format_commit_context {const struct commit *commit; -enum date_mode dmode; +const struct pretty_print_context *pretty_ctx;unsigned commit_header_parsed:1 ;unsigned commit_message_parsed:1 ;
@@ -711,11 +711,11 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,case 'a' :/* author ... */ return format_person_part (sb, placeholder[1 ], msg + c->author.off, c->author.len, - c->dmode); + c->pretty_ctx->date_mode);case 'c' :/* committer ... */ return format_person_part (sb, placeholder[1 ], msg + c->committer.off, c->committer.len, - c->dmode); + c->pretty_ctx->date_mode);case 'e' :/* encoding */ strbuf_add (sb, msg + c->encoding.off, c->encoding.len);return 1 ;
@@ -741,13 +741,13 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,void format_commit_message (const struct commit *commit,const void *format,struct strbuf *sb, -enum date_mode dmode) +const struct pretty_print_context *pretty_ctx) {struct format_commit_context context;memset (&context,0 ,sizeof (context)); context.commit = commit; - context.dmode = dmode; + context.pretty_ctx = pretty_ctx;strbuf_expand (sb, format, format_commit_item, &context); }
@@ -900,18 +900,18 @@ void pp_remainder(enum cmit_fmt fmt, }void pretty_print_commit (enum cmit_fmt fmt,const struct commit *commit, -struct strbuf *sb,int abbrev, -const char *subject,const char *after_subject, -enum date_mode dmode,int need_8bit_cte) +struct strbuf *sb, +const struct pretty_print_context *context) {unsigned long beginning_of_body;int indent =4 ;const char *msg = commit->buffer;char *reencoded;const char *encoding; +int need_8bit_cte = context->need_8bit_cte;if (fmt ==CMIT_FMT_USERFORMAT ) { -format_commit_message (commit, user_format, sb, dmode); +format_commit_message (commit, user_format, sb, context);return ; }
@@ -946,8 +946,9 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit, } } -pp_header (fmt, abbrev, dmode, encoding, commit, &msg, sb); -if (fmt !=CMIT_FMT_ONELINE && !subject) { +pp_header (fmt, context->abbrev, context->date_mode, encoding, + commit, &msg, sb); +if (fmt !=CMIT_FMT_ONELINE && !context->subject) {strbuf_addch (sb,'\n' ); }
@@ -956,8 +957,8 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,/* These formats treat the title line specially. */ if (fmt ==CMIT_FMT_ONELINE || fmt ==CMIT_FMT_EMAIL ) -pp_title_line (fmt, &msg, sb, subject, - after_subject, encoding, need_8bit_cte); +pp_title_line (fmt, &msg, sb, context->subject, + context->after_subject, encoding, need_8bit_cte); beginning_of_body = sb->len;if (fmt !=CMIT_FMT_ONELINE )
Signature · 1 line
1.6.5.18.g9f87a.dirty
PATCH v2 2/5 reflog-walk: refactor the branch@{num} formatting
In reply to Thomas RastWe'll use the same output in an upcoming commit, so refactor its formatting (which was duplicated anyway) into a separate function.
--- reflog-walk.c | 54 ++++++++++++++++++++++++++++++++---------------------- 1 files changed, 32 insertions(+), 22 deletions(-)
reflog-walk.c +32 -22
@@ -241,36 +241,46 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit) commit->object.flags &= ~(ADDED |SEEN |SHOWN ); } -void show_reflog_message (struct reflog_walk_info *info,int oneline, +void get_reflog_selector (struct strbuf *sb, +struct reflog_walk_info *reflog_info, +enum date_mode dmode) +{ +struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog; +struct reflog_info *info; + +if (!commit_reflog) +return ; + +strbuf_addf (sb,"%s@{" , commit_reflog->reflogs->ref); +if (commit_reflog->flag || dmode) { + info = &commit_reflog->reflogs->items[commit_reflog->recno+1 ]; +strbuf_addstr (sb,show_date (info->timestamp, info->tz, dmode)); + }else { +strbuf_addf (sb,"%d" , commit_reflog->reflogs->nr + -2 - commit_reflog->recno); + } + +strbuf_addch (sb,'}' ); +} + +void show_reflog_message (struct reflog_walk_info *reflog_info,int oneline,enum date_mode dmode) { -if (info && info->last_commit_reflog) { -struct commit_reflog *commit_reflog = info->last_commit_reflog; +if (reflog_info && reflog_info->last_commit_reflog) { +struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog;struct reflog_info *info; +struct strbuf selector =STRBUF_INIT ; info = &commit_reflog->reflogs->items[commit_reflog->recno+1 ]; +get_reflog_selector (&selector, reflog_info, dmode);if (oneline) { -printf ("%s@{" , commit_reflog->reflogs->ref); -if (commit_reflog->flag || dmode) -printf ("%s" ,show_date (info->timestamp, - info->tz, - dmode)); -else -printf ("%d" , commit_reflog->reflogs->nr - -2 - commit_reflog->recno); -printf ("}: %s" , info->message); +printf ("%s: %s" , selector.buf, info->message); }else { -printf ("Reflog: %s@{" , commit_reflog->reflogs->ref); -if (commit_reflog->flag || dmode) -printf ("%s" ,show_date (info->timestamp, - info->tz, - dmode)); -else -printf ("%d" , commit_reflog->reflogs->nr - -2 - commit_reflog->recno); -printf ("} (%s)\nReflog message: %s" , - info->email, info->message); +printf ("Reflog: %s (%s)\nReflog message: %s" , + selector.buf, info->email, info->message); } + +strbuf_release (&selector); } }
Signature · 1 line
1.6.5.18.g9f87a.dirty
Re: [PATCH v2 0/5] Pretty formats for reflog data
In reply to Thomas RastQuoted 8 lines · Thomas Rast
Quoted 4 lines · Jeff King
Maybe a better solution would be a "short name" variant for pretty format specifiers. We already have %(refname) and %(refname:short) [...] The tricky part would be deciding on a syntax. This seems to come up a fair bit.
Ok, I settled for %g[dDs] for now to save on letters. I'm saving the syntax question for a later series while we discuss this one ;-)
:) That is probably sensible. Your %g[dD] doesn't support selecting between the numbered version and the "date" version, which is something we might want, but certainly it is no worse than the status quo (and doing something like that probably _would_ want an extended syntax, as you now have two orthogonal arguments: shorten and date/numbered).
Quoted 9 lines
I think going for %(...) wouldn't be too bad since we already have that in for-each-ref, and it can be backwards compatible. So we would have different sets of short and long specifiers, e.g.
%ae = %(authoremail)
%aE = %(authoremail:mailmap)We can then pass arguments via some yet-to-be decided syntax, say, %(body:indent(10)).
That seems reasonable to me, though if we can limit ourselves to one argument per specifier (I suspect most specifiers would simply be boolean, but a few may take numbers or strings), then something like %(body:indent=10) might be a little more readable.
It would also be nice to have some sort of conditional inclusion, which could deal with your extra ": " in patch 3. Either something like:
%(reflog:short)%(reflog:+: )
or even
%(reflog:short:prefix=\: )
and note that allowing arbitrary arguments means we get to deal with quoting.
But that is all for another potential series.
Quoted 3 lines
Other changes in this version include:
* I followed your struct suggestion, which is the new 1/5.
Thanks. It looks like it didn't turn out to be too invasive, and I think some of the callsites are a bit more readable.
Quoted 3 lines
* I fixed the warning that Junio found (and finally found the right combination of -W flags, though I cannot compile with -Werror myself because of *other* warnings...)
I always compile with -Wall -Werror (including testing your series); what warnings are you getting?
Quoted 6 lines
Thomas Rast (5):
Refactorpretty_print_commitarguments into a struct
reflog-walk: refactor the branch@{num} formatting Introduce new pretty formats %g[sdD] for reflog information stash list: use new %g formats instead of sed stash list: drop the default limit of 10 stashes
Thanks, this series looks really good to me. I have a few comments on patch 3 which I'll send separately.
-Peff
Re: [PATCH v2 0/5] Pretty formats for reflog data
Quoted 22 lines · Jeff King
Quoted 9 lines · Thomas Rast
I think going for %(...) wouldn't be too bad since we already have that in for-each-ref, and it can be backwards compatible. So we would have different sets of short and long specifiers, e.g.
%ae = %(authoremail)
%aE = %(authoremail:mailmap)We can then pass arguments via some yet-to-be decided syntax, say, %(body:indent(10)).
That seems reasonable to me, though if we can limit ourselves to one argument per specifier (I suspect most specifiers would simply be boolean, but a few may take numbers or strings), then something like %(body:indent=10) might be a little more readable.
It would also be nice to have some sort of conditional inclusion, which could deal with your extra ": " in patch 3. Either something like:
%(reflog:short)%(reflog:+: )
Quoted 8 lines
or even
%(reflog:short:prefix=\: )
and note that allowing arbitrary arguments means we get to deal with quoting.
But that is all for another potential series.
Or we could go the whole nine miles, and implement some subset of advanced shell syntax,
%(parameter:-word)
%(parameter:=word)
%(parameter:?word)
%(parameter:+word)
RPM spec syntax,
%(?parameter) # expand if exists
%(!?parameter) # expand if does not exists
%(?parameter:literal)
%(!?parameter:literal)
or RPM queryformat
%10(parameter)
%-30(parameter)
[ %(messagebody)\n] # messagebody is list of lines
[%(=param) %(list)\n] # param is not a list; repeat it
%|parameter?{present}:{missing}|
%(parameter:date)
%(parameter:shescape)
Signature · 3 lines
Jakub Narebski Poland ShadeHawk on #git
PATCH v2 3/5 Introduce new pretty formats %g[sdD] for reflog information
In reply to Thomas RastAdd three new --pretty=format escapes:
%gD long reflog descriptor (e.g. refs/stash@{0})
%gd short reflog descriptor (e.g. stash@{0})
%gs reflog messageThis is achieved by passing down the reflog info, if any, inside the pretty_print_context struct.
We use the newly refactored get_reflog_selector(), and give it some extra functionality to extract a shortened ref. The shortening has a very simple 1-element cache, since it will usually be called with the same ref every time. Add another helper get_reflog_message() for the message extraction.
Note that the --format="%h %gD: %gs" tests may not work in real repositories, as the --pretty formatter doesn't know to leave away the ": " on the last commit in an incomplete (because git-gc removed the old part) reflog. This equivalence is nevertheless the main goal of this patch.
--- Documentation/pretty-formats.txt | 3 +++ commit.h | 1 + log-tree.c | 1 + pretty.c | 17 +++++++++++++++++ reflog-walk.c | 37 ++++++++++++++++++++++++++++++++++--- reflog-walk.h | 8 ++++++++ t/t1411-reflog-show.sh | 12 ++++++++++++ 7 files changed, 76 insertions(+), 3 deletions(-)
Documentation/pretty-formats.txt +3 -0
@@ -123,6 +123,9 @@ The placeholders are: - '%s': subject - '%f': sanitized subject line, suitable for a filename - '%b': body +- '%gD': reflog selector, e.g., `refs/stash@{1}` +- '%gd': shortened reflog selector, e.g., `stash@{1}` +- '%gs': reflog subject - '%Cred': switch color to red - '%Cgreen': switch color to green - '%Cblue': switch color to blue
commit.h +1 -0
@@ -70,6 +70,7 @@ struct pretty_print_contextconst char *after_subject;enum date_mode date_mode;int need_8bit_cte; +struct reflog_walk_info *reflog_info; };extern int non_ascii (int );
log-tree.c +1 -0
@@ -409,6 +409,7 @@ void show_log(struct rev_info *opt) ctx.date_mode = opt->date_mode; ctx.abbrev = opt->diffopt.abbrev; ctx.after_subject = extra_headers; + ctx.reflog_info = opt->reflog_info;pretty_print_commit (opt->commit_format, commit, &msgbuf, &ctx);if (opt->add_signoff)
pretty.c +17 -0
@@ -7,6 +7,7 @@#include "mailmap.h" #include "log-tree.h" #include "color.h" +#include "reflog-walk.h" static char *user_format;
@@ -701,6 +702,22 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,case 'd' :format_decoration (sb, commit);return 1 ; +case 'g' :/* reflog info */ +switch (placeholder[1 ]) { +case 'd' :/* reflog selector */ +case 'D' : +if (c->pretty_ctx->reflog_info) +get_reflog_selector (sb, + c->pretty_ctx->reflog_info, + c->pretty_ctx->date_mode, + (placeholder[1 ] =='d' )); +return 2 ; +case 's' :/* reflog message */ +if (c->pretty_ctx->reflog_info) +get_reflog_message (sb, c->pretty_ctx->reflog_info); +return 2 ; + } +return 0 ;/* unknown %g placeholder */ }/* For the rest we have to parse the commit header. */
reflog-walk.c +34 -3
@@ -243,15 +243,29 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit)void get_reflog_selector (struct strbuf *sb,struct reflog_walk_info *reflog_info, -enum date_mode dmode) +enum date_mode dmode, +int shorten) {struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog;struct reflog_info *info; +static const char *last_ref =NULL ; +static char *last_short_ref =NULL ; +const char *printed_ref;if (!commit_reflog)return ; -strbuf_addf (sb,"%s@{" , commit_reflog->reflogs->ref); +if (shorten) { +if (last_ref != commit_reflog->reflogs->ref) { +free (last_short_ref); + last_short_ref =shorten_unambiguous_ref (commit_reflog->reflogs->ref,0 ); + } + printed_ref = last_short_ref; + }else { + printed_ref = commit_reflog->reflogs->ref; + } + +strbuf_addf (sb,"%s@{" , printed_ref);if (commit_reflog->flag || dmode) { info = &commit_reflog->reflogs->items[commit_reflog->recno+1 ];strbuf_addstr (sb,show_date (info->timestamp, info->tz, dmode));
@@ -263,6 +277,23 @@ void get_reflog_selector(struct strbuf *sb,strbuf_addch (sb,'}' ); } +void get_reflog_message (struct strbuf *sb, +struct reflog_walk_info *reflog_info) +{ +struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog; +struct reflog_info *info; +size_t len; + +if (!commit_reflog) +return ; + + info = &commit_reflog->reflogs->items[commit_reflog->recno+1 ]; + len =strlen (info->message); +if (len >0 ) + len--;/* strip away trailing newline */ +strbuf_add (sb, info->message, len); +} +void show_reflog_message (struct reflog_walk_info *reflog_info,int oneline,enum date_mode dmode) {
@@ -272,7 +303,7 @@ void show_reflog_message(struct reflog_walk_info *reflog_info, int oneline,struct strbuf selector =STRBUF_INIT ; info = &commit_reflog->reflogs->items[commit_reflog->recno+1 ]; -get_reflog_selector (&selector, reflog_info, dmode); +get_reflog_selector (&selector, reflog_info, dmode,0 );if (oneline) {printf ("%s: %s" , selector.buf, info->message); }
reflog-walk.h +8 -0
@@ -3,6 +3,8 @@#include "cache.h" +struct reflog_walk_info ; +extern void init_reflog_walk (struct reflog_walk_info ** info);extern int add_reflog_for_walk (struct reflog_walk_info *info,struct commit *commit,const char *name);
@@ -10,5 +12,11 @@ extern void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit);extern void show_reflog_message (struct reflog_walk_info *info,int ,enum date_mode ); +extern void get_reflog_message (struct strbuf *sb, +struct reflog_walk_info *reflog_info); +extern void get_reflog_selector (struct strbuf *sb, +struct reflog_walk_info *reflog_info, +enum date_mode dmode, +int shorten);#endif
t/t1411-reflog-show.sh +12 -0
@@ -64,4 +64,16 @@ test_expect_success 'using --date= shows reflog date (oneline)' ' test_cmp expect actual ' +test_expect_success '--format="%h %gD: %gs" is same as git-reflog' ' + git reflog >expect && + git log -g --format="%h %gD: %gs" >actual && + test_cmp expect actual +' + +test_expect_success '--format="%h %gD: %gs" is same as git-reflog (with date)' ' + git reflog --date=raw >expect && + git log -g --format="%h %gD: %gs" --date=raw >actual && + test_cmp expect actual +' + test_done
Signature · 1 line
1.6.5.18.g9f87a.dirty
Re: [PATCH v2 3/5] Introduce new pretty formats %g[sdD] for reflog information
Quoted 5 lines · Thomas Rast
Note that the --format="%h %gD: %gs" tests may not work in real repositories, as the --pretty formatter doesn't know to leave away the ": " on the last commit in an incomplete (because git-gc removed the old part) reflog. This equivalence is nevertheless the main goal of this patch.
Yeah, I see what you are talking about in my git.git repo. I am tempted to suggest cutting it out of both formats, as it is somewhat confusing, but it does actually convey a slight bit of information (even if information that is extremely unlikely to be of use).
I am also fine with leaving it, and if we one day invent the "conditionally include the ': '" syntax, using it then.
Quoted 5 lines
Documentation/pretty-formats.txt +0
-0
Documentation/pretty-formats.txt The placeholders are: · line 131
Quoted 9 lines
Documentation/pretty-formats.txt +3
-0@@ -123,6 +123,9 @@ The placeholders are: - '%s': subject - '%f': sanitized subject line, suitable for a filename - '%b': body +- '%gD': reflog selector, e.g., `refs/stash@{1}` +- '%gd': shortened reflog selector, e.g., `stash@{1}` +- '%gs': reflog subject - '%Cred': switch color to red - '%Cgreen': switch color to green - '%Cblue': switch color to blue
Should we give a note that these do nothing if "-g" was not given?
Documentation/pretty-formats.txt
Quoted 6 lines
Documentation/pretty-formats.txt +6
-0+ if (shorten) { + if (last_ref != commit_reflog->reflogs->ref) { + free(last_short_ref); + last_short_ref = shorten_unambiguous_ref(commit_reflog->reflogs->ref, 0); + } + printed_ref = last_short_ref;
Clever. I hadn't considered caching, but you are right that shorten_unambiguous_ref is a bit heavyweight to be calling for every entry.
Quoted 9 lines
t/t1411-reflog-show.sh +1
-0@@ -64,4 +64,16 @@ test_expect_success 'using --date= shows reflog date (oneline)' ' test_cmp expect actual ' +test_expect_success '--format="%h %gD: %gs" is same as git-reflog' '
t/t1411-reflog-show.sh test_expect_success 'using --date= shows reflog date (oneline)' ' · line 77
Quoted 10 lines
t/t1411-reflog-show.sh +10
-0+ git reflog >expect && + git log -g --format="%h %gD: %gs" >actual && + test_cmp expect actual +' + +test_expect_success '--format="%h %gD: %gs" is same as git-reflog (with date)' ' + git reflog --date=raw >expect && + git log -g --format="%h %gD: %gs" --date=raw >actual && + test_cmp expect actual +'
A test for '%gd' would be nice. A squashable one is below. I am tempted to test all three forms in t6006, since the intent of that script is to test all format specifiers. However, those tests would be somewhat redundant with your t1411 tests.
---
t/t6006-rev-list-format.sh +6 -0
@@ -162,4 +162,10 @@ test_expect_success 'empty email' ' } ' +test_expect_success '%gd shortens ref name' ' + echo "master@{0}" >expect.gd-short && + git log -g -1 --format=%gd refs/heads/master >actual.gd-short && + test_cmp expect.gd-short actual.gd-short +' + test_done
Re: [PATCH v2 3/5] Introduce new pretty formats %g[sdD] for reflog information
Quoted 10 lines · Jeff King
Review
Quoted 6 lines
(quoted diff) +6
-0+ if (shorten) { + if (last_ref != commit_reflog->reflogs->ref) { + free(last_short_ref); + last_short_ref = shorten_unambiguous_ref(commit_reflog->reflogs->ref, 0); + } + printed_ref = last_short_ref;Clever. I hadn't considered caching, but you are right that
shorten_unambiguous_refis a bit heavyweight to be calling for every entry.
I had a slightly better idea today: We can just put an extra member into the complete_reflogs struct, i.e., a short_ref to go along with the ref. It'll take a bit of auditing to verify that all allocations are zeroed, but since the struct is local to the file that shouldn't be so hard.
Quoted 4 lines
A test for '%gd' would be nice. A squashable one is below. I am tempted to test all three forms in t6006, since the intent of that script is to test all format specifiers. However, those tests would be somewhat redundant with your t1411 tests.
Ah, yeah, I looked for "reflog" instead of something about pretty, so I ended up with t1411. t6006 is a better fit. Thanks for the extra test!
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chv3 cover Pretty formats for reflog data
In reply to Jeff KingNext round :-)
I only changed 3/5, as per your comments:
Quoted 6 lines · Jeff King
Quoted 3 lines · Thomas Rast
+- '%gD': reflog selector, e.g., `refs/stash@{1}` +- '%gd': shortened reflog selector, e.g., `stash@{1}` +- '%gs': reflog subjectShould we give a note that these do nothing if "-g" was not given?
I tried for some time, but all attempts at interrupting the lists ended up terminating it again, so that the %g family list would not line up with the rest of the parameters. Having the note there would be nice, but I think keeping the list together optically is more important. However, AFAICS it really is the first character that only works with certain options (%m makes little sense without A...B, but still expands to >).
Looking at it did make me notice that @{1} is invalid asciidoc and needs to be spelled @\{1\} though :-)
Quoted 4 lines
A test for '%gd' would be nice. A squashable one is below. I am tempted to test all three forms in t6006, since the intent of that script is to test all format specifiers. However, those tests would be somewhat redundant with your t1411 tests.
I added yours and moved my tests to t6006 too, as indicated in the other mail.
I also changed the caching, as outlined earlier:
Quoted 5 lines · I wrote:
I had a slightly better idea today: We can just put an extra member into the
complete_reflogsstruct, i.e., ashort_refto go along with the ref. It'll take a bit of auditing to verify that all allocations are zeroed, but since the struct is local to the file that shouldn't be so hard.
There's in fact only a single allocation (with xcalloc).
Thomas Rast (5):
Refactor pretty_print_commit arguments into a struct
reflog-walk: refactor the branch@{num} formatting Introduce new pretty formats %g[sdD] for reflog information stash list: use new %g formats instead of sed stash list: drop the default limit of 10 stashes
Documentation/pretty-formats.txt | 3 + builtin-branch.c | 3 +- builtin-checkout.c | 3 +- builtin-log.c | 3 +- builtin-merge.c | 7 ++- builtin-rev-list.c | 7 ++- builtin-shortlog.c | 9 +++- builtin-show-branch.c | 4 +- commit.h | 20 ++++++--- git-stash.sh | 8 +--- log-tree.c | 21 +++++----- pretty.c | 44 ++++++++++++++------ reflog-walk.c | 83 ++++++++++++++++++++++++++++---------- reflog-walk.h | 8 ++++ t/t6006-rev-list-format.sh | 18 ++++++++ 15 files changed, 170 insertions(+), 71 deletions(-)
PATCH v3 1/5 Refactor pretty_print_commit arguments into a struct
pretty_print_commit() has a bunch of rarely-used arguments, and introducing more of them requires yet another update of all the call sites. Refactor most of them into a struct to make future extensions easier.
The ones that stay "plain" arguments were chosen on the grounds that all callers put real arguments there, whereas some callers have 0/NULL for all arguments that were factored into the struct.
We declare the struct 'const' to ensure none of the callers are bitten by the changed (no longer call-by-value) semantics.
--- builtin-branch.c | 3 ++- builtin-checkout.c | 3 ++- builtin-log.c | 3 ++- builtin-merge.c | 7 +++++-- builtin-rev-list.c | 7 ++++--- builtin-shortlog.c | 9 ++++++--- builtin-show-branch.c | 4 ++-- commit.h | 19 +++++++++++++------ log-tree.c | 20 ++++++++++---------- pretty.c | 27 ++++++++++++++------------- 10 files changed, 60 insertions(+), 42 deletions(-)
builtin-branch.c +2 -1
@@ -387,8 +387,9 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose, commit = item->commit;if (commit && !parse_commit (commit)) { +struct pretty_print_context ctx = {0 };pretty_print_commit (CMIT_FMT_ONELINE , commit, - &subject,0 ,NULL ,NULL ,0 ,0 ); + &subject, &ctx); sub = subject.buf; }
builtin-checkout.c +2 -1
@@ -302,8 +302,9 @@ static void show_local_changes(struct object *head)static void describe_detached_head (char *msg,struct commit *commit) {struct strbuf sb =STRBUF_INIT ; +struct pretty_print_context ctx = {0 };parse_commit (commit); -pretty_print_commit (CMIT_FMT_ONELINE , commit, &sb,0 ,NULL ,NULL ,0 ,0 ); +pretty_print_commit (CMIT_FMT_ONELINE , commit, &sb, &ctx);fprintf (stderr,"%s %s... %s\n" , msg,find_unique_abbrev (commit->object.sha1,DEFAULT_ABBREV ), sb.buf);strbuf_release (&sb);
builtin-log.c +2 -1
@@ -1304,8 +1304,9 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)if (verbose) {struct strbuf buf =STRBUF_INIT ; +struct pretty_print_context ctx = {0 };pretty_print_commit (CMIT_FMT_ONELINE , commit, - &buf,0 ,NULL ,NULL ,0 ,0 ); + &buf, &ctx);printf ("%c %s %s\n" , sign,sha1_to_hex (commit->object.sha1), buf.buf);strbuf_release (&buf);
builtin-merge.c +5 -2
@@ -264,6 +264,7 @@ static void squash_message(void)struct strbuf out =STRBUF_INIT ;struct commit_list *j;int fd; +struct pretty_print_context ctx = {0 };printf ("Squash commit -- not updating HEAD\n" ); fd =open (git_path ("SQUASH_MSG" ),O_WRONLY |O_CREAT ,0666 );
@@ -285,13 +286,15 @@ static void squash_message(void)if (prepare_revision_walk (&rev))die ("revision walk setup failed" ); + ctx.abbrev = rev.abbrev; + ctx.date_mode = rev.date_mode; +strbuf_addstr (&out,"Squashed commit of the following:\n" );while ((commit =get_revision (&rev)) !=NULL ) {strbuf_addch (&out,'\n' );strbuf_addf (&out,"commit %s\n" ,sha1_to_hex (commit->object.sha1)); -pretty_print_commit (rev.commit_format, commit, &out, rev.abbrev, -NULL ,NULL , rev.date_mode,0 ); +pretty_print_commit (rev.commit_format, commit, &out, &ctx); }if (write (fd, out.buf, out.len) <0 )die_errno ("Writing SQUASH_MSG" );
builtin-rev-list.c +4 -3
@@ -96,9 +96,10 @@ static void show_commit(struct commit *commit, void *data)if (revs->verbose_header && commit->buffer) {struct strbuf buf =STRBUF_INIT ; -pretty_print_commit (revs->commit_format, commit, - &buf, revs->abbrev,NULL ,NULL , - revs->date_mode,0 ); +struct pretty_print_context ctx = {0 }; + ctx.abbrev = revs->abbrev; + ctx.date_mode = revs->date_mode; +pretty_print_commit (revs->commit_format, commit, &buf, &ctx);if (revs->graph) {if (buf.len) {if (revs->commit_format !=CMIT_FMT_ONELINE )
builtin-shortlog.c +6 -3
@@ -158,9 +158,12 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit) sha1_to_hex(commit->object.sha1));if (log->user_format) {struct strbuf buf =STRBUF_INIT ; - -pretty_print_commit (CMIT_FMT_USERFORMAT , commit, &buf, -DEFAULT_ABBREV ,"" ,"" ,DATE_NORMAL ,0 ); +struct pretty_print_context ctx = {0 }; + ctx.abbrev =DEFAULT_ABBREV ; + ctx.subject ="" ; + ctx.after_subject ="" ; + ctx.date_mode =DATE_NORMAL ; +pretty_print_commit (CMIT_FMT_USERFORMAT , commit, &buf, &ctx);insert_one_record (log, author, buf.buf);strbuf_release (&buf);return ;
builtin-show-branch.c +2 -2
@@ -293,8 +293,8 @@ static void show_one_commit(struct commit *commit, int no_name)struct commit_name *name = commit->util;if (commit->object.parsed) { -pretty_print_commit (CMIT_FMT_ONELINE , commit, - &pretty,0 ,NULL ,NULL ,0 ,0 ); +struct pretty_print_context ctx = {0 }; +pretty_print_commit (CMIT_FMT_ONELINE , commit, &pretty, &ctx); pretty_str = pretty.buf; }if (!prefixcmp (pretty_str,"[PATCH] " ))
commit.h +13 -6
@@ -63,6 +63,15 @@ enum cmit_fmt { CMIT_FMT_UNSPECIFIED, }; +struct pretty_print_context +{ +int abbrev; +const char *subject; +const char *after_subject; +enum date_mode date_mode; +int need_8bit_cte; +}; +extern int non_ascii (int );extern int has_non_ascii (const char *text);struct rev_info ;/* in revision.h, it circularly uses enum cmit_fmt */
@@ -71,12 +80,10 @@ enum cmit_fmt {extern void get_commit_format (const char *arg,struct rev_info *);extern void format_commit_message (const struct commit *commit,const void *format,struct strbuf *sb, -enum date_mode dmode); -extern void pretty_print_commit (enum cmit_fmt fmt,const struct commit *, -struct strbuf *, -int abbrev,const char *subject, -const char *after_subject,enum date_mode , -int need_8bit_cte); +const struct pretty_print_context *context); +extern void pretty_print_commit (enum cmit_fmt fmt,const struct commit *commit, +struct strbuf *sb, +const struct pretty_print_context *context);void pp_user_info (const char *what,enum cmit_fmt fmt,struct strbuf *sb,const char *line,enum date_mode dmode,const char *encoding);
log-tree.c +10 -10
@@ -277,10 +277,9 @@ void show_log(struct rev_info *opt)struct strbuf msgbuf =STRBUF_INIT ;struct log_info *log = opt->loginfo;struct commit *commit = log->commit, *parent = log->parent; -int abbrev = opt->diffopt.abbrev;int abbrev_commit = opt->abbrev_commit ? opt->abbrev :40 ; -const char *subject =NULL , *extra_headers = opt->extra_headers; -int need_8bit_cte =0 ; +const char *extra_headers = opt->extra_headers; +struct pretty_print_context ctx = {0 }; opt->loginfo =NULL ;if (!opt->verbose_header) {
@@ -347,8 +346,8 @@ void show_log(struct rev_info *opt)*/ if (opt->commit_format ==CMIT_FMT_EMAIL ) { -log_write_email_headers (opt, commit, &subject, &extra_headers, - &need_8bit_cte); +log_write_email_headers (opt, commit, &ctx.subject, &extra_headers, + &ctx.need_8bit_cte); }else if (opt->commit_format !=CMIT_FMT_USERFORMAT ) {fputs (diff_get_color_opt (&opt->diffopt,DIFF_COMMIT ), stdout);if (opt->commit_format !=CMIT_FMT_ONELINE )
@@ -405,11 +404,12 @@ void show_log(struct rev_info *opt)/* * And then the pretty-printed message itself */ -if (need_8bit_cte >=0 ) - need_8bit_cte =has_non_ascii (opt->add_signoff); -pretty_print_commit (opt->commit_format, commit, &msgbuf, - abbrev, subject, extra_headers, opt->date_mode, - need_8bit_cte); +if (ctx.need_8bit_cte >=0 ) + ctx.need_8bit_cte =has_non_ascii (opt->add_signoff); + ctx.date_mode = opt->date_mode; + ctx.abbrev = opt->diffopt.abbrev; + ctx.after_subject = extra_headers; +pretty_print_commit (opt->commit_format, commit, &msgbuf, &ctx);if (opt->add_signoff)append_signoff (&msgbuf, opt->add_signoff);
pretty.c +14 -13
@@ -442,7 +442,7 @@ struct chunk {struct format_commit_context {const struct commit *commit; -enum date_mode dmode; +const struct pretty_print_context *pretty_ctx;unsigned commit_header_parsed:1 ;unsigned commit_message_parsed:1 ;
@@ -711,11 +711,11 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,case 'a' :/* author ... */ return format_person_part (sb, placeholder[1 ], msg + c->author.off, c->author.len, - c->dmode); + c->pretty_ctx->date_mode);case 'c' :/* committer ... */ return format_person_part (sb, placeholder[1 ], msg + c->committer.off, c->committer.len, - c->dmode); + c->pretty_ctx->date_mode);case 'e' :/* encoding */ strbuf_add (sb, msg + c->encoding.off, c->encoding.len);return 1 ;
@@ -741,13 +741,13 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,void format_commit_message (const struct commit *commit,const void *format,struct strbuf *sb, -enum date_mode dmode) +const struct pretty_print_context *pretty_ctx) {struct format_commit_context context;memset (&context,0 ,sizeof (context)); context.commit = commit; - context.dmode = dmode; + context.pretty_ctx = pretty_ctx;strbuf_expand (sb, format, format_commit_item, &context); }
@@ -900,18 +900,18 @@ void pp_remainder(enum cmit_fmt fmt, }void pretty_print_commit (enum cmit_fmt fmt,const struct commit *commit, -struct strbuf *sb,int abbrev, -const char *subject,const char *after_subject, -enum date_mode dmode,int need_8bit_cte) +struct strbuf *sb, +const struct pretty_print_context *context) {unsigned long beginning_of_body;int indent =4 ;const char *msg = commit->buffer;char *reencoded;const char *encoding; +int need_8bit_cte = context->need_8bit_cte;if (fmt ==CMIT_FMT_USERFORMAT ) { -format_commit_message (commit, user_format, sb, dmode); +format_commit_message (commit, user_format, sb, context);return ; }
@@ -946,8 +946,9 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit, } } -pp_header (fmt, abbrev, dmode, encoding, commit, &msg, sb); -if (fmt !=CMIT_FMT_ONELINE && !subject) { +pp_header (fmt, context->abbrev, context->date_mode, encoding, + commit, &msg, sb); +if (fmt !=CMIT_FMT_ONELINE && !context->subject) {strbuf_addch (sb,'\n' ); }
@@ -956,8 +957,8 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,/* These formats treat the title line specially. */ if (fmt ==CMIT_FMT_ONELINE || fmt ==CMIT_FMT_EMAIL ) -pp_title_line (fmt, &msg, sb, subject, - after_subject, encoding, need_8bit_cte); +pp_title_line (fmt, &msg, sb, context->subject, + context->after_subject, encoding, need_8bit_cte); beginning_of_body = sb->len;if (fmt !=CMIT_FMT_ONELINE )
Signature · 1 line
1.6.5.116.gfe4b9
Re: [PATCH v3 1/5] Refactor pretty_print_commit arguments into a struct
Quoted 5 lines · Thomas Rast
pretty_print_commit()has a bunch of rarely-used arguments, and introducing more of them requires yet another update of all the call sites. Refactor most of them into a struct to make future extensions easier.
Quoted 8 lines
The ones that stay "plain" arguments were chosen on the grounds that all callers put real arguments there, whereas some callers have 0/NULL for all arguments that were factored into the struct.
We declare the struct 'const' to ensure none of the callers are bitten by the changed (no longer call-by-value) semantics.
Signed-off-by Thomas Rast <[email protected]>
Good idea, a slightly sloppy/careless execution.
The existing calls to format_commit_message() often take DATE_NORMAL to its "enum date_mode dmode" argument, and you replaced it with a pointer to a struct. DATE_NORMAL happens to be "0" and the compiler does not catch calls you forgot to convert in this patch.
Re: [PATCH v3 1/5] Refactor pretty_print_commit arguments into a struct
Quoted 4 lines · Junio C Hamano
The existing calls to
format_commit_message()often takeDATE_NORMALto its "enumdate_modedmode" argument, and you replaced it with a pointer to a struct.DATE_NORMALhappens to be "0" and the compiler does not catch calls you forgot to convert in this patch.
Hmph, that's embarrassing. Apparently I was way too focused on pretty_print_commit...
I can devise a test that would have detected this. Should I include it in the reroll, or is that something we do not guard against?
Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.chRe: [PATCH v3 1/5] Refactor pretty_print_commit arguments into a struct
Quoted 8 lines · Thomas Rast
Quoted 4 lines · Junio C Hamano
The existing calls to
format_commit_message()often takeDATE_NORMALto its "enumdate_modedmode" argument, and you replaced it with a pointer to a struct.DATE_NORMALhappens to be "0" and the compiler does not catch calls you forgot to convert in this patch.Hmph, that's embarrassing. Apparently I was way too focused on
pretty_print_commit...
This is nothing to be embarrassed about. I did not notice it when I queued the series either, and I noticed it only when I tried to look at interactions with js/diff-verbose-submodule topic(the other series does not hardcode the style to be DATE_NORMAL).
One solution to help the compiler catch this kind of semantic crash upon merging or applying code based on the old format_commit_message() would have been to change its function signature (or even the name), so that it would not go unnoticed that DATE_NORMAL that happens to be "0" is silently interpreted as (void *)0 == NULL.
v4 cover Pretty formats for reflog data
Quoted 6 lines · Junio C Hamano
One solution to help the compiler catch this kind of semantic crash upon merging or applying code based on the old
format_commit_message()would have been to change its function signature (or even the name), so that it would not go unnoticed thatDATE_NORMALthat happens to be "0" is silently interpreted as (void *)0 == NULL.
Indeed, that would have been a good idea. (I still don't fully see the use of allowing an enum value as a pointer, but apparently the standard's that way.)
I fixed the calls to format_commit_message(), but without changing the function signature compared to the last patch. I also decided not to put in the test case; the easiest I could come up with was the following:
-- 8< --
t/t5001-archive-attr.sh +1 -1
@@ -4,7 +4,7 @@ test_description='git archive attribute tests' . ./test-lib.sh -SUBSTFORMAT=%H%n +SUBSTFORMAT=%H%ad%n test_expect_exists() { test_expect_success " $1 exists" "test -e $1"
-- >8 --
which immediately fails most tests in the file because of segfaults with the buggy series. However, it still wouldn't catch other broken callers, if there were any, so I left it out.
Compared to v3, I also rebased the series on current master, which conflicted with 7f98ebc (format_commit_message(): fix function signature, 2009-10-15) so you now need that commit to apply it.
Finally, I squashed a revert of 0a0c342 (git-stash documentation:
mention default options for 'list', 2009-10-12) into 5/5 since there are no more default options after my patch.
Thomas Rast (5):
Refactor pretty_print_commit arguments into a struct
reflog-walk: refactor the branch@{num} formatting Introduce new pretty formats %g[sdD] for reflog information stash list: use new %g formats instead of sed stash list: drop the default limit of 10 stashes
Documentation/git-stash.txt | 3 +- Documentation/pretty-formats.txt | 9 ++++ archive.c | 4 +- builtin-branch.c | 3 +- builtin-checkout.c | 3 +- builtin-commit.c | 8 +++- builtin-log.c | 3 +- builtin-merge.c | 7 ++- builtin-rev-list.c | 7 ++- builtin-shortlog.c | 9 +++- builtin-show-branch.c | 4 +- commit.h | 20 ++++++--- git-stash.sh | 8 +--- log-tree.c | 25 ++++++----- pretty.c | 44 ++++++++++++++------ reflog-walk.c | 83 ++++++++++++++++++++++++++++---------- reflog-walk.h | 8 ++++ t/t6006-rev-list-format.sh | 18 ++++++++ 18 files changed, 189 insertions(+), 77 deletions(-)
PATCH v4 1/5 Refactor pretty_print_commit arguments into a struct
pretty_print_commit() has a bunch of rarely-used arguments, and introducing more of them requires yet another update of all the call sites. Refactor most of them into a struct to make future extensions easier.
The ones that stay "plain" arguments were chosen on the grounds that all callers put real arguments there, whereas some callers have 0/NULL for all arguments that were factored into the struct.
We declare the struct 'const' to ensure none of the callers are bitten by the changed (no longer call-by-value) semantics.
--- archive.c | 4 +++- builtin-branch.c | 3 ++- builtin-checkout.c | 3 ++- builtin-commit.c | 8 ++++++-- builtin-log.c | 3 ++- builtin-merge.c | 7 +++++-- builtin-rev-list.c | 7 ++++--- builtin-shortlog.c | 9 ++++++--- builtin-show-branch.c | 4 ++-- commit.h | 19 +++++++++++++------ log-tree.c | 24 +++++++++++++----------- pretty.c | 27 ++++++++++++++------------- 12 files changed, 72 insertions(+), 46 deletions(-)
archive.c +3 -1
@@ -31,6 +31,8 @@ static void format_subst(const struct commit *commit, {char *to_free =NULL ;struct strbuf fmt =STRBUF_INIT ; +struct pretty_print_context ctx = {0 }; + ctx.date_mode =DATE_NORMAL ;if (src == buf->buf) to_free =strbuf_detach (buf,NULL );
@@ -48,7 +50,7 @@ static void format_subst(const struct commit *commit,strbuf_add (&fmt, b +8 , c - b -8 );strbuf_add (buf, src, b - src); -format_commit_message (commit, fmt.buf, buf,DATE_NORMAL ); +format_commit_message (commit, fmt.buf, buf, &ctx); len -= c +1 - src; src = c +1 ; }
builtin-branch.c +2 -1
@@ -387,8 +387,9 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose, commit = item->commit;if (commit && !parse_commit (commit)) { +struct pretty_print_context ctx = {0 };pretty_print_commit (CMIT_FMT_ONELINE , commit, - &subject,0 ,NULL ,NULL ,0 ,0 ); + &subject, &ctx); sub = subject.buf; }
builtin-checkout.c +2 -1
@@ -302,8 +302,9 @@ static void show_local_changes(struct object *head)static void describe_detached_head (char *msg,struct commit *commit) {struct strbuf sb =STRBUF_INIT ; +struct pretty_print_context ctx = {0 };parse_commit (commit); -pretty_print_commit (CMIT_FMT_ONELINE , commit, &sb,0 ,NULL ,NULL ,0 ,0 ); +pretty_print_commit (CMIT_FMT_ONELINE , commit, &sb, &ctx);fprintf (stderr,"%s %s... %s\n" , msg,find_unique_abbrev (commit->object.sha1,DEFAULT_ABBREV ), sb.buf);strbuf_release (&sb);
builtin-commit.c +6 -2
@@ -684,8 +684,10 @@ static int message_is_empty(struct strbuf *sb)prepare_revision_walk (&revs); commit =get_revision (&revs);if (commit) { +struct pretty_print_context ctx = {0 }; + ctx.date_mode =DATE_NORMAL ;strbuf_release (&buf); -format_commit_message (commit,"%an <%ae>" , &buf,DATE_NORMAL ); +format_commit_message (commit,"%an <%ae>" , &buf, &ctx);return strbuf_detach (&buf,NULL ); }die ("No existing author found with '%s'" , name);
@@ -942,8 +944,10 @@ static void print_summary(const char *prefix, const unsigned char *sha1) initial_commit ? " (root-commit)" : "");if (!log_tree_commit (&rev, commit)) { +struct pretty_print_context ctx = {0 }; + ctx.date_mode =DATE_NORMAL ;struct strbuf buf =STRBUF_INIT ; -format_commit_message (commit, format +7 , &buf,DATE_NORMAL ); +format_commit_message (commit, format +7 , &buf, &ctx);printf ("%s\n" , buf.buf);strbuf_release (&buf); }
builtin-log.c +2 -1
@@ -1304,8 +1304,9 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)if (verbose) {struct strbuf buf =STRBUF_INIT ; +struct pretty_print_context ctx = {0 };pretty_print_commit (CMIT_FMT_ONELINE , commit, - &buf,0 ,NULL ,NULL ,0 ,0 ); + &buf, &ctx);printf ("%c %s %s\n" , sign,sha1_to_hex (commit->object.sha1), buf.buf);strbuf_release (&buf);
builtin-merge.c +5 -2
@@ -264,6 +264,7 @@ static void squash_message(void)struct strbuf out =STRBUF_INIT ;struct commit_list *j;int fd; +struct pretty_print_context ctx = {0 };printf ("Squash commit -- not updating HEAD\n" ); fd =open (git_path ("SQUASH_MSG" ),O_WRONLY |O_CREAT ,0666 );
@@ -285,13 +286,15 @@ static void squash_message(void)if (prepare_revision_walk (&rev))die ("revision walk setup failed" ); + ctx.abbrev = rev.abbrev; + ctx.date_mode = rev.date_mode; +strbuf_addstr (&out,"Squashed commit of the following:\n" );while ((commit =get_revision (&rev)) !=NULL ) {strbuf_addch (&out,'\n' );strbuf_addf (&out,"commit %s\n" ,sha1_to_hex (commit->object.sha1)); -pretty_print_commit (rev.commit_format, commit, &out, rev.abbrev, -NULL ,NULL , rev.date_mode,0 ); +pretty_print_commit (rev.commit_format, commit, &out, &ctx); }if (write (fd, out.buf, out.len) <0 )die_errno ("Writing SQUASH_MSG" );
builtin-rev-list.c +4 -3
@@ -96,9 +96,10 @@ static void show_commit(struct commit *commit, void *data)if (revs->verbose_header && commit->buffer) {struct strbuf buf =STRBUF_INIT ; -pretty_print_commit (revs->commit_format, commit, - &buf, revs->abbrev,NULL ,NULL , - revs->date_mode,0 ); +struct pretty_print_context ctx = {0 }; + ctx.abbrev = revs->abbrev; + ctx.date_mode = revs->date_mode; +pretty_print_commit (revs->commit_format, commit, &buf, &ctx);if (revs->graph) {if (buf.len) {if (revs->commit_format !=CMIT_FMT_ONELINE )
builtin-shortlog.c +6 -3
@@ -158,9 +158,12 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit) sha1_to_hex(commit->object.sha1));if (log->user_format) {struct strbuf buf =STRBUF_INIT ; - -pretty_print_commit (CMIT_FMT_USERFORMAT , commit, &buf, -DEFAULT_ABBREV ,"" ,"" ,DATE_NORMAL ,0 ); +struct pretty_print_context ctx = {0 }; + ctx.abbrev =DEFAULT_ABBREV ; + ctx.subject ="" ; + ctx.after_subject ="" ; + ctx.date_mode =DATE_NORMAL ; +pretty_print_commit (CMIT_FMT_USERFORMAT , commit, &buf, &ctx);insert_one_record (log, author, buf.buf);strbuf_release (&buf);return ;
builtin-show-branch.c +2 -2
@@ -293,8 +293,8 @@ static void show_one_commit(struct commit *commit, int no_name)struct commit_name *name = commit->util;if (commit->object.parsed) { -pretty_print_commit (CMIT_FMT_ONELINE , commit, - &pretty,0 ,NULL ,NULL ,0 ,0 ); +struct pretty_print_context ctx = {0 }; +pretty_print_commit (CMIT_FMT_ONELINE , commit, &pretty, &ctx); pretty_str = pretty.buf; }if (!prefixcmp (pretty_str,"[PATCH] " ))
commit.h +13 -6
@@ -63,6 +63,15 @@ enum cmit_fmt { CMIT_FMT_UNSPECIFIED, }; +struct pretty_print_context +{ +int abbrev; +const char *subject; +const char *after_subject; +enum date_mode date_mode; +int need_8bit_cte; +}; +extern int non_ascii (int );extern int has_non_ascii (const char *text);struct rev_info ;/* in revision.h, it circularly uses enum cmit_fmt */
@@ -71,12 +80,10 @@ enum cmit_fmt {extern void get_commit_format (const char *arg,struct rev_info *);extern void format_commit_message (const struct commit *commit,const char *format,struct strbuf *sb, -enum date_mode dmode); -extern void pretty_print_commit (enum cmit_fmt fmt,const struct commit *, -struct strbuf *, -int abbrev,const char *subject, -const char *after_subject,enum date_mode , -int need_8bit_cte); +const struct pretty_print_context *context); +extern void pretty_print_commit (enum cmit_fmt fmt,const struct commit *commit, +struct strbuf *sb, +const struct pretty_print_context *context);void pp_user_info (const char *what,enum cmit_fmt fmt,struct strbuf *sb,const char *line,enum date_mode dmode,const char *encoding);
log-tree.c +13 -11
@@ -179,8 +179,10 @@ void get_patch_filename(struct commit *commit, int nr, const char *suffix,strbuf_addf (buf, commit ?"%04d-" :"%d" , nr);if (commit) {int max_len = start_len +FORMAT_PATCH_NAME_MAX - suffix_len; +struct pretty_print_context ctx = {0 }; + ctx.date_mode =DATE_NORMAL ; -format_commit_message (commit,"%f" , buf,DATE_NORMAL ); +format_commit_message (commit,"%f" , buf, &ctx);if (max_len < buf->len)strbuf_setlen (buf, max_len);strbuf_addstr (buf, suffix);
@@ -277,10 +279,9 @@ void show_log(struct rev_info *opt)struct strbuf msgbuf =STRBUF_INIT ;struct log_info *log = opt->loginfo;struct commit *commit = log->commit, *parent = log->parent; -int abbrev = opt->diffopt.abbrev;int abbrev_commit = opt->abbrev_commit ? opt->abbrev :40 ; -const char *subject =NULL , *extra_headers = opt->extra_headers; -int need_8bit_cte =0 ; +const char *extra_headers = opt->extra_headers; +struct pretty_print_context ctx = {0 }; opt->loginfo =NULL ;if (!opt->verbose_header) {
@@ -347,8 +348,8 @@ void show_log(struct rev_info *opt)*/ if (opt->commit_format ==CMIT_FMT_EMAIL ) { -log_write_email_headers (opt, commit, &subject, &extra_headers, - &need_8bit_cte); +log_write_email_headers (opt, commit, &ctx.subject, &extra_headers, + &ctx.need_8bit_cte); }else if (opt->commit_format !=CMIT_FMT_USERFORMAT ) {fputs (diff_get_color_opt (&opt->diffopt,DIFF_COMMIT ), stdout);if (opt->commit_format !=CMIT_FMT_ONELINE )
@@ -405,11 +406,12 @@ void show_log(struct rev_info *opt)/* * And then the pretty-printed message itself */ -if (need_8bit_cte >=0 ) - need_8bit_cte =has_non_ascii (opt->add_signoff); -pretty_print_commit (opt->commit_format, commit, &msgbuf, - abbrev, subject, extra_headers, opt->date_mode, - need_8bit_cte); +if (ctx.need_8bit_cte >=0 ) + ctx.need_8bit_cte =has_non_ascii (opt->add_signoff); + ctx.date_mode = opt->date_mode; + ctx.abbrev = opt->diffopt.abbrev; + ctx.after_subject = extra_headers; +pretty_print_commit (opt->commit_format, commit, &msgbuf, &ctx);if (opt->add_signoff)append_signoff (&msgbuf, opt->add_signoff);
pretty.c +14 -13
@@ -442,7 +442,7 @@ struct chunk {struct format_commit_context {const struct commit *commit; -enum date_mode dmode; +const struct pretty_print_context *pretty_ctx;unsigned commit_header_parsed:1 ;unsigned commit_message_parsed:1 ;
@@ -711,11 +711,11 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,case 'a' :/* author ... */ return format_person_part (sb, placeholder[1 ], msg + c->author.off, c->author.len, - c->dmode); + c->pretty_ctx->date_mode);case 'c' :/* committer ... */ return format_person_part (sb, placeholder[1 ], msg + c->committer.off, c->committer.len, - c->dmode); + c->pretty_ctx->date_mode);case 'e' :/* encoding */ strbuf_add (sb, msg + c->encoding.off, c->encoding.len);return 1 ;
@@ -741,13 +741,13 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,void format_commit_message (const struct commit *commit,const char *format,struct strbuf *sb, -enum date_mode dmode) +const struct pretty_print_context *pretty_ctx) {struct format_commit_context context;memset (&context,0 ,sizeof (context)); context.commit = commit; - context.dmode = dmode; + context.pretty_ctx = pretty_ctx;strbuf_expand (sb, format, format_commit_item, &context); }
@@ -900,18 +900,18 @@ void pp_remainder(enum cmit_fmt fmt, }void pretty_print_commit (enum cmit_fmt fmt,const struct commit *commit, -struct strbuf *sb,int abbrev, -const char *subject,const char *after_subject, -enum date_mode dmode,int need_8bit_cte) +struct strbuf *sb, +const struct pretty_print_context *context) {unsigned long beginning_of_body;int indent =4 ;const char *msg = commit->buffer;char *reencoded;const char *encoding; +int need_8bit_cte = context->need_8bit_cte;if (fmt ==CMIT_FMT_USERFORMAT ) { -format_commit_message (commit, user_format, sb, dmode); +format_commit_message (commit, user_format, sb, context);return ; }
@@ -946,8 +946,9 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit, } } -pp_header (fmt, abbrev, dmode, encoding, commit, &msg, sb); -if (fmt !=CMIT_FMT_ONELINE && !subject) { +pp_header (fmt, context->abbrev, context->date_mode, encoding, + commit, &msg, sb); +if (fmt !=CMIT_FMT_ONELINE && !context->subject) {strbuf_addch (sb,'\n' ); }
@@ -956,8 +957,8 @@ void pretty_print_commit(enum cmit_fmt fmt, const struct commit *commit,/* These formats treat the title line specially. */ if (fmt ==CMIT_FMT_ONELINE || fmt ==CMIT_FMT_EMAIL ) -pp_title_line (fmt, &msg, sb, subject, - after_subject, encoding, need_8bit_cte); +pp_title_line (fmt, &msg, sb, context->subject, + context->after_subject, encoding, need_8bit_cte); beginning_of_body = sb->len;if (fmt !=CMIT_FMT_ONELINE )
Signature · 1 line
1.6.5.1.137.gefbc6
PATCH v4 2/5 reflog-walk: refactor the branch@{num} formatting
In reply to Thomas RastWe'll use the same output in an upcoming commit, so refactor its formatting (which was duplicated anyway) into a separate function.
--- reflog-walk.c | 54 ++++++++++++++++++++++++++++++++---------------------- 1 files changed, 32 insertions(+), 22 deletions(-)
reflog-walk.c +32 -22
@@ -241,36 +241,46 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit) commit->object.flags &= ~(ADDED |SEEN |SHOWN ); } -void show_reflog_message (struct reflog_walk_info *info,int oneline, +void get_reflog_selector (struct strbuf *sb, +struct reflog_walk_info *reflog_info, +enum date_mode dmode) +{ +struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog; +struct reflog_info *info; + +if (!commit_reflog) +return ; + +strbuf_addf (sb,"%s@{" , commit_reflog->reflogs->ref); +if (commit_reflog->flag || dmode) { + info = &commit_reflog->reflogs->items[commit_reflog->recno+1 ]; +strbuf_addstr (sb,show_date (info->timestamp, info->tz, dmode)); + }else { +strbuf_addf (sb,"%d" , commit_reflog->reflogs->nr + -2 - commit_reflog->recno); + } + +strbuf_addch (sb,'}' ); +} + +void show_reflog_message (struct reflog_walk_info *reflog_info,int oneline,enum date_mode dmode) { -if (info && info->last_commit_reflog) { -struct commit_reflog *commit_reflog = info->last_commit_reflog; +if (reflog_info && reflog_info->last_commit_reflog) { +struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog;struct reflog_info *info; +struct strbuf selector =STRBUF_INIT ; info = &commit_reflog->reflogs->items[commit_reflog->recno+1 ]; +get_reflog_selector (&selector, reflog_info, dmode);if (oneline) { -printf ("%s@{" , commit_reflog->reflogs->ref); -if (commit_reflog->flag || dmode) -printf ("%s" ,show_date (info->timestamp, - info->tz, - dmode)); -else -printf ("%d" , commit_reflog->reflogs->nr - -2 - commit_reflog->recno); -printf ("}: %s" , info->message); +printf ("%s: %s" , selector.buf, info->message); }else { -printf ("Reflog: %s@{" , commit_reflog->reflogs->ref); -if (commit_reflog->flag || dmode) -printf ("%s" ,show_date (info->timestamp, - info->tz, - dmode)); -else -printf ("%d" , commit_reflog->reflogs->nr - -2 - commit_reflog->recno); -printf ("} (%s)\nReflog message: %s" , - info->email, info->message); +printf ("Reflog: %s (%s)\nReflog message: %s" , + selector.buf, info->email, info->message); } + +strbuf_release (&selector); } }
Signature · 1 line
1.6.5.1.137.gefbc6
PATCH v4 3/5 Introduce new pretty formats %g[sdD] for reflog information
In reply to Thomas RastAdd three new --pretty=format escapes:
%gD long reflog descriptor (e.g. refs/stash@{0})
%gd short reflog descriptor (e.g. stash@{0})
%gs reflog messageThis is achieved by passing down the reflog info, if any, inside the pretty_print_context struct.
We use the newly refactored get_reflog_selector(), and give it some extra functionality to extract a shortened ref. The shortening is cached inside the commit_reflogs struct; the only allocation of it happens in read_complete_reflog(), where it is initialised to 0. Also add another helper get_reflog_message() for the message extraction.
Note that the --format="%h %gD: %gs" tests may not work in real repositories, as the --pretty formatter doesn't know to leave away the ": " on the last commit in an incomplete (because git-gc removed the old part) reflog. This equivalence is nevertheless the main goal of this patch.
Thanks to Jeff King for reviews, the %gd testcase and documentation.
--- Documentation/pretty-formats.txt | 9 +++++++++ commit.h | 1 + log-tree.c | 1 + pretty.c | 17 +++++++++++++++++ reflog-walk.c | 35 ++++++++++++++++++++++++++++++++--- reflog-walk.h | 8 ++++++++ t/t6006-rev-list-format.sh | 18 ++++++++++++++++++ 7 files changed, 86 insertions(+), 3 deletions(-)
Documentation/pretty-formats.txt +9 -0
@@ -123,6 +123,9 @@ The placeholders are: - '%s': subject - '%f': sanitized subject line, suitable for a filename - '%b': body +- '%gD': reflog selector, e.g., `refs/stash@\{1\}` +- '%gd': shortened reflog selector, e.g., `stash@\{1\}` +- '%gs': reflog subject - '%Cred': switch color to red - '%Cgreen': switch color to green - '%Cblue': switch color to blue
@@ -132,6 +135,12 @@ The placeholders are: - '%n': newline - '%x00': print a byte from a hex code +NOTE: Some placeholders may depend on other options given to the +revision traversal engine. For example, the `%g*` reflog options will +insert an empty string unless we are traversing reflog entries (e.g., by +`git log -g`). The `%d` placeholder will use the "short" decoration +format if `--decorate` was not already provided on the command line. + * 'tformat:' + The 'tformat:' format works exactly like 'format:', except that it
commit.h +1 -0
@@ -70,6 +70,7 @@ struct pretty_print_contextconst char *after_subject;enum date_mode date_mode;int need_8bit_cte; +struct reflog_walk_info *reflog_info; };extern int non_ascii (int );
log-tree.c +1 -0
@@ -411,6 +411,7 @@ void show_log(struct rev_info *opt) ctx.date_mode = opt->date_mode; ctx.abbrev = opt->diffopt.abbrev; ctx.after_subject = extra_headers; + ctx.reflog_info = opt->reflog_info;pretty_print_commit (opt->commit_format, commit, &msgbuf, &ctx);if (opt->add_signoff)
pretty.c +17 -0
@@ -7,6 +7,7 @@#include "mailmap.h" #include "log-tree.h" #include "color.h" +#include "reflog-walk.h" static char *user_format;
@@ -701,6 +702,22 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,case 'd' :format_decoration (sb, commit);return 1 ; +case 'g' :/* reflog info */ +switch (placeholder[1 ]) { +case 'd' :/* reflog selector */ +case 'D' : +if (c->pretty_ctx->reflog_info) +get_reflog_selector (sb, + c->pretty_ctx->reflog_info, + c->pretty_ctx->date_mode, + (placeholder[1 ] =='d' )); +return 2 ; +case 's' :/* reflog message */ +if (c->pretty_ctx->reflog_info) +get_reflog_message (sb, c->pretty_ctx->reflog_info); +return 2 ; + } +return 0 ;/* unknown %g placeholder */ }/* For the rest we have to parse the commit header. */
reflog-walk.c +32 -3
@@ -8,6 +8,7 @@struct complete_reflogs {char *ref; +const char *short_ref;struct reflog_info {unsigned char osha1[20 ], nsha1[20 ];char *email;
@@ -243,15 +244,26 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit)void get_reflog_selector (struct strbuf *sb,struct reflog_walk_info *reflog_info, -enum date_mode dmode) +enum date_mode dmode, +int shorten) {struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog;struct reflog_info *info; +const char *printed_ref;if (!commit_reflog)return ; -strbuf_addf (sb,"%s@{" , commit_reflog->reflogs->ref); +if (shorten) { +if (!commit_reflog->reflogs->short_ref) + commit_reflog->reflogs->short_ref + =shorten_unambiguous_ref (commit_reflog->reflogs->ref,0 ); + printed_ref = commit_reflog->reflogs->short_ref; + }else { + printed_ref = commit_reflog->reflogs->ref; + } + +strbuf_addf (sb,"%s@{" , printed_ref);if (commit_reflog->flag || dmode) { info = &commit_reflog->reflogs->items[commit_reflog->recno+1 ];strbuf_addstr (sb,show_date (info->timestamp, info->tz, dmode));
@@ -263,6 +275,23 @@ void get_reflog_selector(struct strbuf *sb,strbuf_addch (sb,'}' ); } +void get_reflog_message (struct strbuf *sb, +struct reflog_walk_info *reflog_info) +{ +struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog; +struct reflog_info *info; +size_t len; + +if (!commit_reflog) +return ; + + info = &commit_reflog->reflogs->items[commit_reflog->recno+1 ]; + len =strlen (info->message); +if (len >0 ) + len--;/* strip away trailing newline */ +strbuf_add (sb, info->message, len); +} +void show_reflog_message (struct reflog_walk_info *reflog_info,int oneline,enum date_mode dmode) {
@@ -272,7 +301,7 @@ void show_reflog_message(struct reflog_walk_info *reflog_info, int oneline,struct strbuf selector =STRBUF_INIT ; info = &commit_reflog->reflogs->items[commit_reflog->recno+1 ]; -get_reflog_selector (&selector, reflog_info, dmode); +get_reflog_selector (&selector, reflog_info, dmode,0 );if (oneline) {printf ("%s: %s" , selector.buf, info->message); }
reflog-walk.h +8 -0
@@ -3,6 +3,8 @@#include "cache.h" +struct reflog_walk_info ; +extern void init_reflog_walk (struct reflog_walk_info ** info);extern int add_reflog_for_walk (struct reflog_walk_info *info,struct commit *commit,const char *name);
@@ -10,5 +12,11 @@ extern void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit);extern void show_reflog_message (struct reflog_walk_info *info,int ,enum date_mode ); +extern void get_reflog_message (struct strbuf *sb, +struct reflog_walk_info *reflog_info); +extern void get_reflog_selector (struct strbuf *sb, +struct reflog_walk_info *reflog_info, +enum date_mode dmode, +int shorten);#endif
t/t6006-rev-list-format.sh +18 -0
@@ -162,4 +162,22 @@ test_expect_success 'empty email' ' } ' +test_expect_success '"%h %gD: %gs" is same as git-reflog' ' + git reflog >expect && + git log -g --format="%h %gD: %gs" >actual && + test_cmp expect actual +' + +test_expect_success '"%h %gD: %gs" is same as git-reflog (with date)' ' + git reflog --date=raw >expect && + git log -g --format="%h %gD: %gs" --date=raw >actual && + test_cmp expect actual +' + +test_expect_success '%gd shortens ref name' ' + echo "master@{0}" >expect.gd-short && + git log -g -1 --format=%gd refs/heads/master >actual.gd-short && + test_cmp expect.gd-short actual.gd-short +' + test_done
Signature · 1 line
1.6.5.1.137.gefbc6
PATCH v4 4/5 stash list: use new %g formats instead of sed
In reply to Thomas RastWith the new formats, we can rewrite 'git stash list' in terms of an appropriate pretty format, instead of hand-editing with sed. This has the advantage that it obeys the normal settings for git-log, notably the pager.
--- git-stash.sh | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
git-stash.sh +1 -2
@@ -205,8 +205,7 @@ have_stash () { list_stash () { have_stash || return 0 - git log --no-color --pretty=oneline -g "$@" $ref_stash -- | - sed -n -e 's/^[.0-9a-f]* refs\///p' + git log --format="%gd: %gs" -g "$@" $ref_stash -- } show_stash () {
Signature · 1 line
1.6.5.1.137.gefbc6
PATCH v4 5/5 stash list: drop the default limit of 10 stashes
In reply to Thomas Rast'git stash list' had an undocumented limit of 10 stashes, unless other git-log arguments were specified. This surprised at least one user, but possibly served to cut the output below a screenful without using a pager.
Since the last commit, 'git stash list' will fire up a pager according to the same rules as the 'git log' it calls, so we can drop the limit.
--- Documentation/git-stash.txt | 3 +-- git-stash.sh | 5 ----- 2 files changed, 1 insertions(+), 7 deletions(-)
Documentation/git-stash.txt +1 -2
@@ -78,8 +78,7 @@ stash@{1}: On master: 9cc0589... Add git-stash ---------------------------------------------------------------- + The command takes options applicable to the 'git-log' -command to control what is shown and how. If no options are set, the -default is `-n 10`. See linkgit:git-log[1]. +command to control what is shown and how. See linkgit:git-log[1]. show [<stash>]::
git-stash.sh +0 -5
@@ -382,11 +382,6 @@ test -n "$seen_non_option" || set "save" "$@" case "$1" in list) shift - if test $# = 0 - then - set x -n 10 - shift - fi list_stash "$@" ;; show)
Signature · 1 line
1.6.5.1.137.gefbc6
Re: [PATCH v3 0/5] Pretty formats for reflog data
In reply to Thomas RastQuoted 7 lines · Thomas Rast
I tried for some time, but all attempts at interrupting the lists ended up terminating it again, so that the %g family list would not line up with the rest of the parameters. Having the note there would be nice, but I think keeping the list together optically is more important. However, AFAICS it really is the first character that only works with certain options (%m makes little sense without A...B, but still expands to >).
Another example is "%d", but there we load decorations on the fly the first time it is used. I don't think that's a good idea here, since using "%gd" shouldn't automatically imply "-g", which drastically changes the nature of the command.
The "%m" behavior does what I would expect. If you haven't done any limiting, then there can be no "left" or "boundary" entries.
I am tempted to do a note like the one below, but maybe the behavior is obvious enough to users that it isn't necessary.
Quoted 2 lines
Looking at it did make me notice that @{1} is invalid asciidoc and needs to be spelled @\{1\} though :-)
Thanks. I am often very guilty of not actually building documentation when reviewing patches, because it is so tedious to build and examine.
---
Documentation/pretty-formats.txt +6 -0
@@ -135,6 +135,12 @@ The placeholders are: - '%n': newline - '%x00': print a byte from a hex code +NOTE: Some placeholders may depend on other options given to the +revision traversal engine. For example, the `%g*` reflog options will +insert an empty string unless we are traversing reflog entries (e.g., by +`git log -g`). The `%d` placeholder will use the "short" decoration +format if `--decorate` was not already provided on the command line. + * 'tformat:' + The 'tformat:' format works exactly like 'format:', except that it
PATCH v3 2/5 reflog-walk: refactor the branch@{num} formatting
In reply to Thomas RastWe'll use the same output in an upcoming commit, so refactor its formatting (which was duplicated anyway) into a separate function.
--- reflog-walk.c | 54 ++++++++++++++++++++++++++++++++---------------------- 1 files changed, 32 insertions(+), 22 deletions(-)
reflog-walk.c +32 -22
@@ -241,36 +241,46 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit) commit->object.flags &= ~(ADDED |SEEN |SHOWN ); } -void show_reflog_message (struct reflog_walk_info *info,int oneline, +void get_reflog_selector (struct strbuf *sb, +struct reflog_walk_info *reflog_info, +enum date_mode dmode) +{ +struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog; +struct reflog_info *info; + +if (!commit_reflog) +return ; + +strbuf_addf (sb,"%s@{" , commit_reflog->reflogs->ref); +if (commit_reflog->flag || dmode) { + info = &commit_reflog->reflogs->items[commit_reflog->recno+1 ]; +strbuf_addstr (sb,show_date (info->timestamp, info->tz, dmode)); + }else { +strbuf_addf (sb,"%d" , commit_reflog->reflogs->nr + -2 - commit_reflog->recno); + } + +strbuf_addch (sb,'}' ); +} + +void show_reflog_message (struct reflog_walk_info *reflog_info,int oneline,enum date_mode dmode) { -if (info && info->last_commit_reflog) { -struct commit_reflog *commit_reflog = info->last_commit_reflog; +if (reflog_info && reflog_info->last_commit_reflog) { +struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog;struct reflog_info *info; +struct strbuf selector =STRBUF_INIT ; info = &commit_reflog->reflogs->items[commit_reflog->recno+1 ]; +get_reflog_selector (&selector, reflog_info, dmode);if (oneline) { -printf ("%s@{" , commit_reflog->reflogs->ref); -if (commit_reflog->flag || dmode) -printf ("%s" ,show_date (info->timestamp, - info->tz, - dmode)); -else -printf ("%d" , commit_reflog->reflogs->nr - -2 - commit_reflog->recno); -printf ("}: %s" , info->message); +printf ("%s: %s" , selector.buf, info->message); }else { -printf ("Reflog: %s@{" , commit_reflog->reflogs->ref); -if (commit_reflog->flag || dmode) -printf ("%s" ,show_date (info->timestamp, - info->tz, - dmode)); -else -printf ("%d" , commit_reflog->reflogs->nr - -2 - commit_reflog->recno); -printf ("} (%s)\nReflog message: %s" , - info->email, info->message); +printf ("Reflog: %s (%s)\nReflog message: %s" , + selector.buf, info->email, info->message); } + +strbuf_release (&selector); } }
Signature · 1 line
1.6.5.116.gfe4b9
Re: [PATCH v3 0/5] Pretty formats for reflog data
In reply to Thomas RastQuoted 1 line · Thomas Rast
Next round :-)
Very nicely done; I like it.
Thanks.
PATCH v3 3/5 Introduce new pretty formats %g[sdD] for reflog information
In reply to Thomas RastAdd three new --pretty=format escapes:
%gD long reflog descriptor (e.g. refs/stash@{0})
%gd short reflog descriptor (e.g. stash@{0})
%gs reflog messageThis is achieved by passing down the reflog info, if any, inside the pretty_print_context struct.
We use the newly refactored get_reflog_selector(), and give it some extra functionality to extract a shortened ref. The shortening is cached inside the commit_reflogs struct; the only allocation of it happens in read_complete_reflog(), where it is initialised to 0. Also add another helper get_reflog_message() for the message extraction.
Note that the --format="%h %gD: %gs" tests may not work in real repositories, as the --pretty formatter doesn't know to leave away the ": " on the last commit in an incomplete (because git-gc removed the old part) reflog. This equivalence is nevertheless the main goal of this patch.
Thanks to Jeff King for reviews and the %gd testcase.
--- Documentation/pretty-formats.txt | 3 +++ commit.h | 1 + log-tree.c | 1 + pretty.c | 17 +++++++++++++++++ reflog-walk.c | 35 ++++++++++++++++++++++++++++++++--- reflog-walk.h | 8 ++++++++ t/t6006-rev-list-format.sh | 18 ++++++++++++++++++ 7 files changed, 80 insertions(+), 3 deletions(-)
Documentation/pretty-formats.txt +3 -0
@@ -123,6 +123,9 @@ The placeholders are: - '%s': subject - '%f': sanitized subject line, suitable for a filename - '%b': body +- '%gD': reflog selector, e.g., `refs/stash@\{1\}` +- '%gd': shortened reflog selector, e.g., `stash@\{1\}` +- '%gs': reflog subject - '%Cred': switch color to red - '%Cgreen': switch color to green - '%Cblue': switch color to blue
commit.h +1 -0
@@ -70,6 +70,7 @@ struct pretty_print_contextconst char *after_subject;enum date_mode date_mode;int need_8bit_cte; +struct reflog_walk_info *reflog_info; };extern int non_ascii (int );
log-tree.c +1 -0
@@ -409,6 +409,7 @@ void show_log(struct rev_info *opt) ctx.date_mode = opt->date_mode; ctx.abbrev = opt->diffopt.abbrev; ctx.after_subject = extra_headers; + ctx.reflog_info = opt->reflog_info;pretty_print_commit (opt->commit_format, commit, &msgbuf, &ctx);if (opt->add_signoff)
pretty.c +17 -0
@@ -7,6 +7,7 @@#include "mailmap.h" #include "log-tree.h" #include "color.h" +#include "reflog-walk.h" static char *user_format;
@@ -701,6 +702,22 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,case 'd' :format_decoration (sb, commit);return 1 ; +case 'g' :/* reflog info */ +switch (placeholder[1 ]) { +case 'd' :/* reflog selector */ +case 'D' : +if (c->pretty_ctx->reflog_info) +get_reflog_selector (sb, + c->pretty_ctx->reflog_info, + c->pretty_ctx->date_mode, + (placeholder[1 ] =='d' )); +return 2 ; +case 's' :/* reflog message */ +if (c->pretty_ctx->reflog_info) +get_reflog_message (sb, c->pretty_ctx->reflog_info); +return 2 ; + } +return 0 ;/* unknown %g placeholder */ }/* For the rest we have to parse the commit header. */
reflog-walk.c +32 -3
@@ -8,6 +8,7 @@struct complete_reflogs {char *ref; +const char *short_ref;struct reflog_info {unsigned char osha1[20 ], nsha1[20 ];char *email;
@@ -243,15 +244,26 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit)void get_reflog_selector (struct strbuf *sb,struct reflog_walk_info *reflog_info, -enum date_mode dmode) +enum date_mode dmode, +int shorten) {struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog;struct reflog_info *info; +const char *printed_ref;if (!commit_reflog)return ; -strbuf_addf (sb,"%s@{" , commit_reflog->reflogs->ref); +if (shorten) { +if (!commit_reflog->reflogs->short_ref) + commit_reflog->reflogs->short_ref + =shorten_unambiguous_ref (commit_reflog->reflogs->ref,0 ); + printed_ref = commit_reflog->reflogs->short_ref; + }else { + printed_ref = commit_reflog->reflogs->ref; + } + +strbuf_addf (sb,"%s@{" , printed_ref);if (commit_reflog->flag || dmode) { info = &commit_reflog->reflogs->items[commit_reflog->recno+1 ];strbuf_addstr (sb,show_date (info->timestamp, info->tz, dmode));
@@ -263,6 +275,23 @@ void get_reflog_selector(struct strbuf *sb,strbuf_addch (sb,'}' ); } +void get_reflog_message (struct strbuf *sb, +struct reflog_walk_info *reflog_info) +{ +struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog; +struct reflog_info *info; +size_t len; + +if (!commit_reflog) +return ; + + info = &commit_reflog->reflogs->items[commit_reflog->recno+1 ]; + len =strlen (info->message); +if (len >0 ) + len--;/* strip away trailing newline */ +strbuf_add (sb, info->message, len); +} +void show_reflog_message (struct reflog_walk_info *reflog_info,int oneline,enum date_mode dmode) {
@@ -272,7 +301,7 @@ void show_reflog_message(struct reflog_walk_info *reflog_info, int oneline,struct strbuf selector =STRBUF_INIT ; info = &commit_reflog->reflogs->items[commit_reflog->recno+1 ]; -get_reflog_selector (&selector, reflog_info, dmode); +get_reflog_selector (&selector, reflog_info, dmode,0 );if (oneline) {printf ("%s: %s" , selector.buf, info->message); }
reflog-walk.h +8 -0
@@ -3,6 +3,8 @@#include "cache.h" +struct reflog_walk_info ; +extern void init_reflog_walk (struct reflog_walk_info ** info);extern int add_reflog_for_walk (struct reflog_walk_info *info,struct commit *commit,const char *name);
@@ -10,5 +12,11 @@ extern void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit);extern void show_reflog_message (struct reflog_walk_info *info,int ,enum date_mode ); +extern void get_reflog_message (struct strbuf *sb, +struct reflog_walk_info *reflog_info); +extern void get_reflog_selector (struct strbuf *sb, +struct reflog_walk_info *reflog_info, +enum date_mode dmode, +int shorten);#endif
t/t6006-rev-list-format.sh +18 -0
@@ -162,4 +162,22 @@ test_expect_success 'empty email' ' } ' +test_expect_success '"%h %gD: %gs" is same as git-reflog' ' + git reflog >expect && + git log -g --format="%h %gD: %gs" >actual && + test_cmp expect actual +' + +test_expect_success '"%h %gD: %gs" is same as git-reflog (with date)' ' + git reflog --date=raw >expect && + git log -g --format="%h %gD: %gs" --date=raw >actual && + test_cmp expect actual +' + +test_expect_success '%gd shortens ref name' ' + echo "master@{0}" >expect.gd-short && + git log -g -1 --format=%gd refs/heads/master >actual.gd-short && + test_cmp expect.gd-short actual.gd-short +' + test_done
Signature · 1 line
1.6.5.116.gfe4b9
PATCH 3/5 Introduce new pretty formats %g[sdD] for reflog information
Add three new --pretty=format escapes:
%gD long reflog descriptor (e.g. refs/stash@{0})
%gd short reflog descriptor (e.g. stash@{0})
%gs reflog messageThis is achieved by passing down the reflog info, if any, inside the pretty_print_context struct.
We use the newly refactored get_reflog_selector(), and give it some extra functionality to extract a shortened ref. The shortening is cached inside the commit_reflogs struct; the only allocation of it happens in read_complete_reflog(), where it is initialised to 0. Also add another helper get_reflog_message() for the message extraction.
Note that the --format="%h %gD: %gs" tests may not work in real repositories, as the --pretty formatter doesn't know to leave away the ": " on the last commit in an incomplete (because git-gc removed the old part) reflog. This equivalence is nevertheless the main goal of this patch.
Thanks to Jeff King for reviews, the %gd testcase and documentation.
---
Quoted 2 lines · I wrote:
[Tacking this on the corresponding v3 patch, but the text below is from <[email protected]>.]
This sadly backfired, as I forgot to snip out the in-reply-to in the mail itself and git-send-email apparently trusted that more. Sorry for the confusion.
Quoted 2 lines · Jeff King
I am tempted to do a note like the one below, but maybe the behavior is obvious enough to users that it isn't necessary.
[...]
Review
Quoted 5 lines
(quoted diff) +5
-0+NOTE: Some placeholders may depend on other options given to the +revision traversal engine. For example, the `%g*` reflog options will +insert an empty string unless we are traversing reflog entries (e.g., by +`git log -g`). The `%d` placeholder will use the "short" decoration +format if `--decorate` was not already provided on the command line.
Sure. I figured it was obvious enough, but since you already went to the lengths of documenting the exact behaviour of %d, I squashed it and adjusted the acknowledgement in the commit message accordingly.
Documentation/pretty-formats.txt | 9 +++++++++ commit.h | 1 + log-tree.c | 1 + pretty.c | 17 +++++++++++++++++ reflog-walk.c | 35 ++++++++++++++++++++++++++++++++--- reflog-walk.h | 8 ++++++++ t/t6006-rev-list-format.sh | 18 ++++++++++++++++++ 7 files changed, 86 insertions(+), 3 deletions(-)
Documentation/pretty-formats.txt +9 -0
@@ -123,6 +123,9 @@ The placeholders are: - '%s': subject - '%f': sanitized subject line, suitable for a filename - '%b': body +- '%gD': reflog selector, e.g., `refs/stash@\{1\}` +- '%gd': shortened reflog selector, e.g., `stash@\{1\}` +- '%gs': reflog subject - '%Cred': switch color to red - '%Cgreen': switch color to green - '%Cblue': switch color to blue
@@ -132,6 +135,12 @@ The placeholders are: - '%n': newline - '%x00': print a byte from a hex code +NOTE: Some placeholders may depend on other options given to the +revision traversal engine. For example, the `%g*` reflog options will +insert an empty string unless we are traversing reflog entries (e.g., by +`git log -g`). The `%d` placeholder will use the "short" decoration +format if `--decorate` was not already provided on the command line. + * 'tformat:' + The 'tformat:' format works exactly like 'format:', except that it
commit.h +1 -0
@@ -70,6 +70,7 @@ struct pretty_print_contextconst char *after_subject;enum date_mode date_mode;int need_8bit_cte; +struct reflog_walk_info *reflog_info; };extern int non_ascii (int );
log-tree.c +1 -0
@@ -409,6 +409,7 @@ void show_log(struct rev_info *opt) ctx.date_mode = opt->date_mode; ctx.abbrev = opt->diffopt.abbrev; ctx.after_subject = extra_headers; + ctx.reflog_info = opt->reflog_info;pretty_print_commit (opt->commit_format, commit, &msgbuf, &ctx);if (opt->add_signoff)
pretty.c +17 -0
@@ -7,6 +7,7 @@#include "mailmap.h" #include "log-tree.h" #include "color.h" +#include "reflog-walk.h" static char *user_format;
@@ -701,6 +702,22 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,case 'd' :format_decoration (sb, commit);return 1 ; +case 'g' :/* reflog info */ +switch (placeholder[1 ]) { +case 'd' :/* reflog selector */ +case 'D' : +if (c->pretty_ctx->reflog_info) +get_reflog_selector (sb, + c->pretty_ctx->reflog_info, + c->pretty_ctx->date_mode, + (placeholder[1 ] =='d' )); +return 2 ; +case 's' :/* reflog message */ +if (c->pretty_ctx->reflog_info) +get_reflog_message (sb, c->pretty_ctx->reflog_info); +return 2 ; + } +return 0 ;/* unknown %g placeholder */ }/* For the rest we have to parse the commit header. */
reflog-walk.c +32 -3
@@ -8,6 +8,7 @@struct complete_reflogs {char *ref; +const char *short_ref;struct reflog_info {unsigned char osha1[20 ], nsha1[20 ];char *email;
@@ -243,15 +244,26 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit)void get_reflog_selector (struct strbuf *sb,struct reflog_walk_info *reflog_info, -enum date_mode dmode) +enum date_mode dmode, +int shorten) {struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog;struct reflog_info *info; +const char *printed_ref;if (!commit_reflog)return ; -strbuf_addf (sb,"%s@{" , commit_reflog->reflogs->ref); +if (shorten) { +if (!commit_reflog->reflogs->short_ref) + commit_reflog->reflogs->short_ref + =shorten_unambiguous_ref (commit_reflog->reflogs->ref,0 ); + printed_ref = commit_reflog->reflogs->short_ref; + }else { + printed_ref = commit_reflog->reflogs->ref; + } + +strbuf_addf (sb,"%s@{" , printed_ref);if (commit_reflog->flag || dmode) { info = &commit_reflog->reflogs->items[commit_reflog->recno+1 ];strbuf_addstr (sb,show_date (info->timestamp, info->tz, dmode));
@@ -263,6 +275,23 @@ void get_reflog_selector(struct strbuf *sb,strbuf_addch (sb,'}' ); } +void get_reflog_message (struct strbuf *sb, +struct reflog_walk_info *reflog_info) +{ +struct commit_reflog *commit_reflog = reflog_info->last_commit_reflog; +struct reflog_info *info; +size_t len; + +if (!commit_reflog) +return ; + + info = &commit_reflog->reflogs->items[commit_reflog->recno+1 ]; + len =strlen (info->message); +if (len >0 ) + len--;/* strip away trailing newline */ +strbuf_add (sb, info->message, len); +} +void show_reflog_message (struct reflog_walk_info *reflog_info,int oneline,enum date_mode dmode) {
@@ -272,7 +301,7 @@ void show_reflog_message(struct reflog_walk_info *reflog_info, int oneline,struct strbuf selector =STRBUF_INIT ; info = &commit_reflog->reflogs->items[commit_reflog->recno+1 ]; -get_reflog_selector (&selector, reflog_info, dmode); +get_reflog_selector (&selector, reflog_info, dmode,0 );if (oneline) {printf ("%s: %s" , selector.buf, info->message); }
reflog-walk.h +8 -0
@@ -3,6 +3,8 @@#include "cache.h" +struct reflog_walk_info ; +extern void init_reflog_walk (struct reflog_walk_info ** info);extern int add_reflog_for_walk (struct reflog_walk_info *info,struct commit *commit,const char *name);
@@ -10,5 +12,11 @@ extern void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit);extern void show_reflog_message (struct reflog_walk_info *info,int ,enum date_mode ); +extern void get_reflog_message (struct strbuf *sb, +struct reflog_walk_info *reflog_info); +extern void get_reflog_selector (struct strbuf *sb, +struct reflog_walk_info *reflog_info, +enum date_mode dmode, +int shorten);#endif
t/t6006-rev-list-format.sh +18 -0
@@ -162,4 +162,22 @@ test_expect_success 'empty email' ' } ' +test_expect_success '"%h %gD: %gs" is same as git-reflog' ' + git reflog >expect && + git log -g --format="%h %gD: %gs" >actual && + test_cmp expect actual +' + +test_expect_success '"%h %gD: %gs" is same as git-reflog (with date)' ' + git reflog --date=raw >expect && + git log -g --format="%h %gD: %gs" --date=raw >actual && + test_cmp expect actual +' + +test_expect_success '%gd shortens ref name' ' + echo "master@{0}" >expect.gd-short && + git log -g -1 --format=%gd refs/heads/master >actual.gd-short && + test_cmp expect.gd-short actual.gd-short +' + test_done
Signature · 1 line
1.6.5.116.g4aaa3
Re: [PATCH v3.1 3/5] Introduce new pretty formats %g[sdD] for reflog information
Quoted 9 lines · Thomas Rast
Documentation/pretty-formats.txt The placeholders are: · line 142
Quoted 5 lines
Documentation/pretty-formats.txt +5
-0+NOTE: Some placeholders may depend on other options given to the +revision traversal engine. For example, the `%g*` reflog options will +insert an empty string unless we are traversing reflog entries (e.g., by +`git log -g`). The `%d` placeholder will use the "short" decoration +format if `--decorate` was not already provided on the command line.Sure. I figured it was obvious enough, but since you already went to the lengths of documenting the exact behaviour of %d, I squashed it and adjusted the acknowledgement in the commit message accordingly.
If the consensus (or Junio's decision when applying) is that we don't need it, I don't mind if my suggestion is scrapped (or reworded).
-Peff
Re: [PATCH v3.1 3/5] Introduce new pretty formats %g[sdD] for reflog information
Quoting Jeff King <[email protected]>
Quoted 12 lines · Thomas Rast
Quoted 10 lines
Documentation/pretty-formats.txt The placeholders are: · line 142
Quoted 6 lines
Documentation/pretty-formats.txt +5
-0+NOTE: Some placeholders may depend on other options given to the +revision traversal engine. For example, the `%g*` reflog options will +insert an empty string unless we are traversing reflog entries (e.g., by +`git log -g`). The `%d` placeholder will use the "short" decoration +format if `--decorate` was not already provided on the command line.Sure. I figured it was obvious enough, but since you already went to the lengths of documenting the exact behaviour of %d, I squashed it and adjusted the acknowledgement in the commit message accordingly.
Quoted 2 lines
If the consensus (or Junio's decision when applying) is that we don't need it, I don't mind if my suggestion is scrapped (or reworded).
I think your clarification is a good addition.
Signature · 2 lines
Nanako Shiraishi http://ivory.ap.teacup.com/nanako3/
Re: [PATCH v3.1 3/5] Introduce new pretty formats %g[sdD] for reflog information
In reply to Thomas RastQuoted 5 lines · Thomas Rast
Note that the --format="%h %gD: %gs" tests may not work in real repositories, as the --pretty formatter doesn't know to leave away the ": " on the last commit in an incomplete (because git-gc removed the old part) reflog. This equivalence is nevertheless the main goal of this patch.
Perhaps just-introduced grouping syntax would help there? You could for example write
--format="%h%[all() %gD: %gs%]"
which would expand nested group if _all_ placeholders within it have expansion. Perhaps %[ ... %], or %[? ... %], or %[* ... %] could be shorter versions...
Signature · 3 lines
Jakub Narebski Poland ShadeHawk on #git
PATCH v3 4/5 stash list: use new %g formats instead of sed
In reply to Thomas RastWith the new formats, we can rewrite 'git stash list' in terms of an appropriate pretty format, instead of hand-editing with sed. This has the advantage that it obeys the normal settings for git-log, notably the pager.
--- git-stash.sh | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
git-stash.sh +1 -2
@@ -205,8 +205,7 @@ have_stash () { list_stash () { have_stash || return 0 - git log --no-color --pretty=oneline -g "$@" $ref_stash -- | - sed -n -e 's/^[.0-9a-f]* refs\///p' + git log --format="%gd: %gs" -g "$@" $ref_stash -- } show_stash () {
Signature · 1 line
1.6.5.116.gfe4b9
PATCH v3 5/5 stash list: drop the default limit of 10 stashes
In reply to Thomas Rast'git stash list' had an undocumented limit of 10 stashes, unless other git-log arguments were specified. This surprised at least one user, but possibly served to cut the output below a screenful without using a pager.
Since the last commit, 'git stash list' will fire up a pager according to the same rules as the 'git log' it calls, so we can drop the limit.
--- git-stash.sh | 5 ----- 1 files changed, 0 insertions(+), 5 deletions(-)
git-stash.sh +0 -5
@@ -382,11 +382,6 @@ test -n "$seen_non_option" || set "save" "$@" case "$1" in list) shift - if test $# = 0 - then - set x -n 10 - shift - fi list_stash "$@" ;; show)
Signature · 1 line
1.6.5.116.gfe4b9
PATCH v2 4/5 stash list: use new %g formats instead of sed
In reply to Thomas RastWith the new formats, we can rewrite 'git stash list' in terms of an appropriate pretty format, instead of hand-editing with sed. This has the advantage that it obeys the normal settings for git-log, notably the pager.
--- git-stash.sh | 3 +-- 1 files changed, 1 insertions(+), 2 deletions(-)
git-stash.sh +1 -2
@@ -205,8 +205,7 @@ have_stash () { list_stash () { have_stash || return 0 - git log --no-color --pretty=oneline -g "$@" $ref_stash -- | - sed -n -e 's/^[.0-9a-f]* refs\///p' + git log --format="%gd: %gs" -g "$@" $ref_stash -- } show_stash () {
Signature · 1 line
1.6.5.18.g9f87a.dirty
PATCH v2 5/5 stash list: drop the default limit of 10 stashes
In reply to Thomas Rast'git stash list' had an undocumented limit of 10 stashes, unless other git-log arguments were specified. This surprised at least one user, but possibly served to cut the output below a screenful without using a pager.
Since the last commit, 'git stash list' will fire up a pager according to the same rules as the 'git log' it calls, so we can drop the limit.
--- git-stash.sh | 5 ----- 1 files changed, 0 insertions(+), 5 deletions(-)
git-stash.sh +0 -5
@@ -382,11 +382,6 @@ test -n "$seen_non_option" || set "save" "$@" case "$1" in list) shift - if test $# = 0 - then - set x -n 10 - shift - fi list_stash "$@" ;; show)
Signature · 1 line
1.6.5.18.g9f87a.dirty