# [RFC PATCH 1/5] reflog-walk: refactor the branch@{num} formatting

14 messages from 2009-10-12 to 2009-10-14. Participants: Thomas Rast, Jeff King, Junio C Hamano.
Thread: https://gitlist.dev/t/21218

## Thomas Rast, 2009-10-12 21:06

Subject: [RFC PATCH 0/5] Pretty formats for reflog data
Message-ID: <cover.1255380039.git.trast@student.ethz.ch>
URL: https://gitlist.dev/e/cover.1255380039.git.trast%40student.ethz.ch
In-Reply-To: <20091012175201.GA10263@coredump.intra.peff.net>

```
[I forgot to address the list on the first batch, sorry for the spam.]

Jeff King wrote:
> On Mon, Oct 12, 2009 at 05:47:34PM +0200, Jef Driesen wrote:
> 
> > 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(-)

```

## Thomas Rast, 2009-10-12 21:06

Subject: [RFC PATCH 1/5] reflog-walk: refactor the branch@{num} formatting
Message-ID: <1c524798bde29912429d400f0c48591acadad6d7.1255380039.git.trast@student.ethz.ch>
URL: https://gitlist.dev/e/1c524798bde29912429d400f0c48591acadad6d7.1255380039.git.trast%40student.ethz.ch
In-Reply-To: <cover.1255380039.git.trast@student.ethz.ch>

```
We'll use the same output in an upcoming commit, so refactor its
formatting (which was duplicated anyway) into a separate function.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
 reflog-walk.c |   56 ++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 34 insertions(+), 22 deletions(-)

diff --git a/reflog-walk.c b/reflog-walk.c
index 5623ea6..9478dbc 100644
--- a/reflog-walk.c
+++ b/reflog-walk.c
@@ -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);
 	}
 }
-- 
1.6.5.64.g01287

```

## Thomas Rast, 2009-10-12 21:06

Subject: [RFC PATCH 2/5] Introduce new pretty formats %g and %G for reflog information
Message-ID: <e0321a8af8d702d24ace33510daff22d02f4e116.1255380039.git.trast@student.ethz.ch>
URL: https://gitlist.dev/e/e0321a8af8d702d24ace33510daff22d02f4e116.1255380039.git.trast%40student.ethz.ch
In-Reply-To: <cover.1255380039.git.trast@student.ethz.ch>

```
Add 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.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
 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(-)

diff --git a/archive.c b/archive.c
index 0cc79d2..d325ce3 100644
--- a/archive.c
+++ b/archive.c
@@ -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;
 	}
diff --git a/builtin-branch.c b/builtin-branch.c
index 9f57992..d90bfaf 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -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;
 		}
 
diff --git a/builtin-checkout.c b/builtin-checkout.c
index d050c37..b6b9c45 100644
--- a/builtin-checkout.c
+++ b/builtin-checkout.c
@@ -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);
diff --git a/builtin-commit.c b/builtin-commit.c
index 200ffda..d63d467 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -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);
 	}
diff --git a/builtin-log.c b/builtin-log.c
index 25e21ed..57df76e 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -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);
diff --git a/builtin-merge.c b/builtin-merge.c
index b6b8428..70f1488 100644
--- a/builtin-merge.c
+++ b/builtin-merge.c
@@ -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");
diff --git a/builtin-rev-list.c b/builtin-rev-list.c
index 4ba1c12..78659c8 100644
--- a/builtin-rev-list.c
+++ b/builtin-rev-list.c
@@ -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)
diff --git a/builtin-shortlog.c b/builtin-shortlog.c
index 4d4a3c8..128b382 100644
--- a/builtin-shortlog.c
+++ b/builtin-shortlog.c
@@ -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;
diff --git a/builtin-show-branch.c b/builtin-show-branch.c
index be95930..73ea7ce 100644
--- a/builtin-show-branch.c
+++ b/builtin-show-branch.c
@@ -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] "))
diff --git a/commit.h b/commit.h
index f4fc5c5..93efeeb 100644
--- a/commit.h
+++ b/commit.h
@@ -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);
diff --git a/log-tree.c b/log-tree.c
index 1618f3c..e75f953 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -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);
diff --git a/pretty.c b/pretty.c
index f5983f8..0b67580 100644
--- a/pretty.c
+++ b/pretty.c
@@ -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;
 	}
 
diff --git a/reflog-walk.c b/reflog-walk.c
index 9478dbc..929f025 100644
--- a/reflog-walk.c
+++ b/reflog-walk.c
@@ -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)
 {
diff --git a/reflog-walk.h b/reflog-walk.h
index 74c9096..986121f 100644
--- a/reflog-walk.h
+++ b/reflog-walk.h
@@ -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
-- 
1.6.5.64.g01287

```

## Thomas Rast, 2009-10-12 21:06

Subject: [RFC PATCH 3/5] stash: Use new %g/%G formats instead of sed
Message-ID: <77e591b80021efc265fea1a101ce6b7124ea832e.1255380039.git.trast@student.ethz.ch>
URL: https://gitlist.dev/e/77e591b80021efc265fea1a101ce6b7124ea832e.1255380039.git.trast%40student.ethz.ch
In-Reply-To: <cover.1255380039.git.trast@student.ethz.ch>

```
With 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.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
 git-stash.sh |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/git-stash.sh b/git-stash.sh
index 4febbbf..8fbf10a 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -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 () {
-- 
1.6.5.64.g01287

```

## Thomas Rast, 2009-10-12 21:06

Subject: [RFC PATCH 4/5] stash list: drop the default limit of 10 stashes
Message-ID: <137df1f7295576345f5aefe46c882399e107c321.1255380039.git.trast@student.ethz.ch>
URL: https://gitlist.dev/e/137df1f7295576345f5aefe46c882399e107c321.1255380039.git.trast%40student.ethz.ch
In-Reply-To: <cover.1255380039.git.trast@student.ethz.ch>

```
'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.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
 git-stash.sh |    5 -----
 1 files changed, 0 insertions(+), 5 deletions(-)

diff --git a/git-stash.sh b/git-stash.sh
index 8fbf10a..08a7669 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -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)
-- 
1.6.5.64.g01287

```

## Thomas Rast, 2009-10-12 21:06

Subject: [RFC PATCH 5/5] stash: change built-in ref to 'stash' instead of 'refs/stash'
Message-ID: <548bc3a41c03a049e782d5d04a34c3b26c0897d2.1255380039.git.trast@student.ethz.ch>
URL: https://gitlist.dev/e/548bc3a41c03a049e782d5d04a34c3b26c0897d2.1255380039.git.trast%40student.ethz.ch
In-Reply-To: <cover.1255380039.git.trast@student.ethz.ch>

```
'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.)

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
 git-stash.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/git-stash.sh b/git-stash.sh
index 08a7669..8bf464b 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -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')"
-- 
1.6.5.64.g01287

```

## Jeff King, 2009-10-12 21:37

Subject: Re: [RFC PATCH 0/5] Pretty formats for reflog data
Message-ID: <20091012213756.GA12166@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20091012213756.GA12166%40coredump.intra.peff.net
In-Reply-To: <cover.1255380039.git.trast@student.ethz.ch>

```
On Mon, Oct 12, 2009 at 11:02:29PM +0200, Thomas Rast wrote:

> > 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.

> 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

```

## Thomas Rast, 2009-10-12 21:52

Subject: Re: [RFC PATCH 0/5] Pretty formats for reflog data
Message-ID: <200910122352.25658.trast@student.ethz.ch>
URL: https://gitlist.dev/e/200910122352.25658.trast%40student.ethz.ch
In-Reply-To: <20091012213756.GA12166@coredump.intra.peff.net>

```
Jeff King wrote:
> 
> 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.

-- 
Thomas Rast
trast@{inf,student}.ethz.ch

```

## Jeff King, 2009-10-14 04:59

Subject: Re: [RFC PATCH 2/5] Introduce new pretty formats %g and %G for reflog information
Message-ID: <20091014045918.GA31810@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20091014045918.GA31810%40coredump.intra.peff.net
In-Reply-To: <e0321a8af8d702d24ace33510daff22d02f4e116.1255380039.git.trast@student.ethz.ch>

```
On Mon, Oct 12, 2009 at 11:06:04PM +0200, Thomas Rast wrote:

> 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.

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

```

## Jeff King, 2009-10-14 05:00

Subject: Re: [RFC PATCH 3/5] stash: Use new %g/%G formats instead of sed
Message-ID: <20091014050038.GB31810@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20091014050038.GB31810%40coredump.intra.peff.net
In-Reply-To: <77e591b80021efc265fea1a101ce6b7124ea832e.1255380039.git.trast@student.ethz.ch>

```
On Mon, Oct 12, 2009 at 11:06:05PM +0200, Thomas Rast wrote:

>  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

You dropped the trailing "--" which is needed for disambiguation.

-Peff

```

## Jeff King, 2009-10-14 05:02

Subject: Re: [RFC PATCH 4/5] stash list: drop the default limit of 10 stashes
Message-ID: <20091014050248.GC31810@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20091014050248.GC31810%40coredump.intra.peff.net
In-Reply-To: <137df1f7295576345f5aefe46c882399e107c321.1255380039.git.trast@student.ethz.ch>

```
On Mon, Oct 12, 2009 at 11:06:06PM +0200, Thomas Rast wrote:

> '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

```

## Jeff King, 2009-10-14 05:06

Subject: Re: [RFC PATCH 5/5] stash: change built-in ref to 'stash' instead of 'refs/stash'
Message-ID: <20091014050645.GD31810@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20091014050645.GD31810%40coredump.intra.peff.net
In-Reply-To: <548bc3a41c03a049e782d5d04a34c3b26c0897d2.1255380039.git.trast@student.ethz.ch>

```
On Mon, Oct 12, 2009 at 11:06:07PM +0200, Thomas Rast wrote:

> '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

```

## Junio C Hamano, 2009-10-14 09:13

Subject: Re: [RFC PATCH 2/5] Introduce new pretty formats %g and %G for reflog information
Message-ID: <7vd44qfidi.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vd44qfidi.fsf%40alter.siamese.dyndns.org
In-Reply-To: <e0321a8af8d702d24ace33510daff22d02f4e116.1255380039.git.trast@student.ethz.ch>

```
Squash 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(-)

diff --git a/reflog-walk.c b/reflog-walk.c
index 929f025..5cbcb1a 100644
--- a/reflog-walk.c
+++ b/reflog-walk.c
@@ -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);

```

## Thomas Rast, 2009-10-14 09:58

Subject: Re: [RFC PATCH 2/5] Introduce new pretty formats %g and %G for reflog information
Message-ID: <200910141158.35050.trast@student.ethz.ch>
URL: https://gitlist.dev/e/200910141158.35050.trast%40student.ethz.ch
In-Reply-To: <20091014045918.GA31810@coredump.intra.peff.net>

```
Jeff King wrote:
> On Mon, Oct 12, 2009 at 11:06:04PM +0200, Thomas Rast wrote:
> 
> > 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.
> 
> 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.

Ok, I'll try for the next round.

-- 
Thomas Rast
trast@{inf,student}.ethz.ch

```
