git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Brian Gernhardt <benji@silverinsanity.com>,
	Russ Dill <russ.dill@gmail.com>,
	Stephen Sinclair <radarsat1@gmail.com>,
	git@vger.kernel.org
Subject: Re: branch description
Date: Tue, 15 Apr 2008 18:37:16 -0400	[thread overview]
Message-ID: <20080415223716.GA1891@sigill.intra.peff.net> (raw)
In-Reply-To: <20080415191930.GC31395@sigill.intra.peff.net>

On Tue, Apr 15, 2008 at 03:19:30PM -0400, Jeff King wrote:

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

  reply	other threads:[~2008-04-15 22:38 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-15 16:51 branch description Stephen Sinclair
2008-04-15 17:31 ` Russ Dill
2008-04-15 18:01   ` Brian Gernhardt
2008-04-15 19:12     ` Junio C Hamano
2008-04-15 19:19       ` Jeff King
2008-04-15 22:37         ` Jeff King [this message]
2008-04-15 22:56           ` Junio C Hamano
2008-04-15 20:53       ` Stephen Sinclair
2008-04-15 21:04         ` Brian Gernhardt
2008-04-16  1:33       ` Jakub Narebski
2008-04-16  2:55         ` Jeff King
2008-04-16  3:28         ` Stephen Sinclair
2008-04-16  5:55           ` Mike Hommey
2008-04-16  3:46         ` Matt Graham
2008-04-16  8:29           ` Johan Herland
2008-04-18 21:58             ` Jakub Narebski
2008-04-19  9:18               ` Johan Herland
2008-04-19 17:43                 ` Junio C Hamano
2008-04-19 18:09                   ` Johan Herland
2008-04-19 21:05                 ` Jakub Narebski
2008-04-16  5:27         ` Junio C Hamano
2008-04-16 19:56           ` Jakub Narebski
2008-04-15 18:36   ` Jakub Narebski
  -- strict thread matches above, loose matches on Subject: below --
2008-04-22 17:57 Michael Dressel
2008-04-22 18:46 ` Johan Herland
2008-04-22 18:59 ` Jakub Narebski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080415223716.GA1891@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=benji@silverinsanity.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=radarsat1@gmail.com \
    --cc=russ.dill@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).