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

Re: branch description

From
Jeff King <peff@peff.net>
Date
Apr 15, 2008, 22:37 UTC
Message-ID
<20080415223716.GA1891@sigill.intra.peff.net>
In-Reply-To
<20080415191930.GC31395@sigill.intra.peff.net>
On Tue, Apr 15, 2008 at 03:19:30PM -0400, Jeff King wrote:
Show 8 quoted lines
> > Not complicated at all.  Put that description in-tree in a known location
> > (say, "help-branch") in-tree and your propagation problem is solved.
> >
> > And have a scriptlet in $HOME/bin/git-help-branch to grep from that file.
> 
> It is perhaps a little slow if you want to do things like adding the
> help text to branch name decorations in log output. Maybe instead of a
> flat file, you could parallel the ref name hierarchy in a tree? I.e.,

It occurred to me that you actually meant "just stick it in a file in your actual work tree", not on a separate branch (for some reason, reading the name "help-branch" made me think you meant a ref).

So that is obviously the very simple solution. But for fun, and because maybe somebody could learn something, here is a script implementing my approach. I dunno if it is worth including in contrib.

-- >8 -- contrib: add git-refinfo

This is a cute hack to show one possible way of storing ref descriptions. It might be useful to somebody. It also serves as a relatively short and simple example of how to script git.

Signed-off-by: Jeff King <peff@peff.net>
---
 contrib/examples/git-refinfo.sh |   87 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 87 insertions(+), 0 deletions(-)
 create mode 100755 contrib/examples/git-refinfo.sh
diff --git a/contrib/examples/git-refinfo.sh b/contrib/examples/git-refinfo.sh
new file mode 100755
index 0000000..b79a20f
--- /dev/null
+++ b/contrib/examples/git-refinfo.sh
@@ -0,0 +1,87 @@
+#!/bin/sh
+#
+# git-refinfo: a ref-description mechanism
+#
+# git-refinfo maintains a mapping of refnames to descriptions;
+# it stores the mapping as a version-controlled tree. Each
+# path in the tree represents a ref name, and the contents of
+# that path are the description.
+#
+# That means you can either use git-refinfo to set or examine
+# ref descriptions, or you can simply "git checkout refinfo"
+# and view and edit the files directly.
+
+REFINFO=refs/heads/refinfo
+SUBDIRECTORY_OK=Yes
+USAGE='
+git-refinfo set [<ref>] <description>
+git-refinfo get [<ref> ...]'
+. git-sh-setup
+
+die_usage() {
+	echo >&2 "usage: $USAGE"
+	exit 1
+}
+
+full_ref() {
+	git show-ref "$1" | sed -e 's/^[^ ]* //' -e '1q'
+}
+
+heads() {
+	git show-ref --heads | sed 's/.*refs\/heads\///'
+}
+
+do_get() {
+	ref=`full_ref "$1"`
+	case "$ref" in
+	'') desc= ;;
+	 *) desc=`git cat-file blob "$REFINFO:$ref" 2>/dev/null` ;;
+	esac
+	printf '%s\t%s\n' "$1" "$desc"
+}
+
+do_set() {
+	ref=`full_ref "$1"`
+	case "$ref" in
+	'')
+		case "$1" in
+		refs/*) ref=$1 ;;
+		heads/*) ref=refs/$1 ;;
+		*) ref=refs/heads/* ;;
+		esac
+		;;
+	esac
+	GIT_INDEX_FILE=$GIT_DIR/refinfo-index; export GIT_INDEX_FILE
+	rm -f $GIT_INDEX
+	old=`git rev-parse --verify $REFINFO 2>/dev/null`
+	case "$old" in
+	'') parents= ;;
+	 *) parents="-p $old"; git read-tree $REFINFO ;;
+	esac
+	blob=`printf '%s\n' "$2" | git hash-object -w --stdin`
+	git update-index --add --cacheinfo 0644 $blob "$ref"
+	tree=`git write-tree`
+	commit=`echo "update $1" | git commit-tree $tree $parents`
+	git update-ref -m refinfo $REFINFO $commit $old
+}
+
+case "$1" in
+set)
+	shift
+	case "$#" in
+	1) do_set "`git symbolic-ref HEAD`" "$1" ;;
+	2) do_set "$1" "$2" ;;
+	*) die_usage ;;
+	esac
+	;;
+get)
+	shift
+	case "$#" in
+	0) for i in `heads`; do do_get "$i"; done ;;
+	*) for i in "$@"; do do_get "$i"; done ;;
+	esac
+	;;
+*)
+	die_usage
+esac
+exit 0
-- 
1.5.5.63.g4e41c
Previous: Jeff KingNext: Junio C Hamano
Message 6 of 23 in “branch description”
  1. Stephen SinclairApr 15, 2008
  2. Russ DillApr 15, 2008
  3. Brian GernhardtApr 15, 2008
  4. Junio C HamanoApr 15, 2008
  5. Jeff KingApr 15, 2008
  6. Jeff KingApr 15, 2008
  7. Junio C HamanoApr 15, 2008
  8. Stephen SinclairApr 15, 2008
  9. Brian GernhardtApr 15, 2008
  10. Jakub NarebskiApr 16, 2008
  11. Jeff KingApr 16, 2008
  12. Stephen SinclairApr 16, 2008
  13. Mike HommeyApr 16, 2008
  14. Matt GrahamApr 16, 2008
  15. Johan HerlandApr 16, 2008
  16. Jakub NarebskiApr 18, 2008
  17. Johan HerlandApr 19, 2008
  18. Junio C HamanoApr 19, 2008
  19. Johan HerlandApr 19, 2008
  20. Jakub NarebskiApr 19, 2008
  21. Junio C HamanoApr 16, 2008
  22. Jakub NarebskiApr 16, 2008
  23. Jakub NarebskiApr 15, 2008

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

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