Add -v and -w options to git-branch
cover Add -v and -w options to git-branch
This patch-series teaches git-branch to show sha1 and first line of commit message for each branch (and is a replacement for my previous patches)
Diffstat:
Documentation/git-branch.txt | 8 ++++- git-branch.sh | 71 ++++++++++++++++++++++++++++++++--------- 2 files changed, 62 insertions(+), 17 deletions(-)
PATCH 1/3 Fix usagestring for git-branch
--- git-branch.sh | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
git-branch.sh +1 -1
@@ -1,6 +1,6 @@ #!/bin/sh -USAGE='[-l] [(-d | -D) <branchname>] | [[-f] <branchname> [<start-point>]] | -r' +USAGE=' [-l] [-f] <branchname> [<start-point>] | (-d | -D) <branchname> | [-r]' LONG_USAGE='If no arguments, show available branches and mark current branch with a star. If one argument, create a new branch <branchname> based off of current HEAD. If two arguments, create a new branch <branchname> based off of <start-point>.'
Signature · 1 line
1.4.3.1.g1688
PATCH 2/3 Refactor git-branch
In reply to Lars HjemliThis moves the code used to display local branches into a separate function.
--- git-branch.sh | 28 ++++++++++++++++------------ 1 files changed, 16 insertions(+), 12 deletions(-)
git-branch.sh +16 -12
@@ -54,6 +54,21 @@ ls_remote_branches () { sort } +ls_local_branches () { + git-rev-parse --symbolic --branches | + sort | + while read ref + do + if test "$headref" = "$ref" + then + pfx='*' + else + pfx=' ' + fi + echo "$pfx $ref" + done +} + force= create_log= while case "$#,$1" in 0,*) break ;; *,-*) ;; *) break ;; esac
@@ -86,18 +101,7 @@ done case "$#" in 0) - git-rev-parse --symbolic --branches | - sort | - while read ref - do - if test "$headref" = "$ref" - then - pfx='*' - else - pfx=' ' - fi - echo "$pfx $ref" - done + ls_local_branches exit 0 ;; 1) head=HEAD ;;
Signature · 1 line
1.4.3.1.g1688
PATCH 3/3 Teach git-branch -v and -w options
In reply to Lars HjemliThis makes git-branch display sha1 and first line of commit message for each branch.
Additionaly, the -w option may be used to specify columnwidth for branchname (default is 20 characters)
--- Documentation/git-branch.txt | 8 ++++++- git-branch.sh | 47 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 7 deletions(-)
Documentation/git-branch.txt +7 -1
@@ -8,7 +8,7 @@ git-branch - List, create, or delete bra SYNOPSIS -------- [verse] -'git-branch' [-r] +'git-branch' [-r] [-v [-w width]] 'git-branch' [-l] [-f] <branchname> [<start-point>] 'git-branch' (-d | -D) <branchname>...
@@ -47,6 +47,12 @@ OPTIONS -r:: List only the "remote" branches. +-v:: + Show sha1 and first line of commit message for each branch + +-w <width>:: + Set columnwidth for branchname display + <branchname>:: The name of the branch to create or delete. The new branch name must pass all checks defined by
git-branch.sh +41 -6
86 lines not on this page · raw message
Signature · 1 line
1.4.3.1.g1688
Re: [PATCH 3/3] Teach git-branch -v and -w options
Quoted 7 lines · Lars Hjemli
This makes git-branch display sha1 and first line of commit message for each branch.
Additionaly, the -w option may be used to specify columnwidth for branchname (default is 20 characters)
Signed-off-by Lars Hjemli <[email protected]>
If you are going in this direction, probably you would want to refactor 2/3 a bit differently, so that you do not have to duplicate the same printf for local and remote cases?
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [PATCH 3/3] Teach git-branch -v and -w options
[the gitlist fell off my first reply, so I've put it back...]
Quoted 3 lines · Junio C Hamano
I was almost going to say that your patch saddened me because doing builtin-branch on top of Linus's packed-refs work (which means doing the series on top of "next") was part of my plan,
Heh, I don't want to compete with your c-skills :-)
Quoted 5 lines
If you are aware of Kristian's patch that is a good news. I do not have much objection to add optional frills to git-branch listing output, but I'd rather not see it done in the shell implementation. Doing anything on the current
git-branch.shmeans that would need to be re-done later.
Agreed. I'll try and come up with a builtin instead, and let you worry about more interesting stuff.
Signature · 1 line
larsh
Re: [PATCH 3/3] Teach git-branch -v and -w options
In reply to Junio C HamanoQuoted 4 lines · Junio C Hamano
If you are going in this direction, probably you would want to refactor 2/3 a bit differently, so that you do not have to duplicate the same printf for local and remote cases?
I actually did, but then abandoned it since it would change the output for remote branches (two spaces indent). I didn't want to cause any regressions :-)
But if that's ok, my abandoned patch contained this:
@@ -48,14 +48,35 @@ If you are sure you want to delete it, r
exit 0
}
-ls_remote_branches () {
- git-rev-parse --symbolic --all | - sed -ne 's|^refs/\(remotes/\)|\1|p' | - sort
-}
-+width=20
+sedmatch="^refs/heads/"
+sedsubst=
+verbose=
force=
create_log=
+
+ls_refs () {
+ git-rev-parse --symbolic --all | + sed -ne "s|$sedmatch|$sedsubst|p" | + sort | + while read ref + do
+ if test "$headref" = "$ref"
+ then
+ pfx='*'
+ else
+ pfx=' '
+ fi + if test "$verbose" = "yes" + then
+ log=$(git-log --max-count=1 --pretty=oneline $ref)
+ printf "%s %-*s %s\n" "$pfx" "$width" "$ref" "$log"
+ else
+ echo "$pfx $ref"
+ fi
+ done
+}
+
while case "$#,$1" in 0,*) break ;; *,-*) ;; *) break ;; esac do
case "$1" in
@@ -64,8 +85,8 @@ do
exit
;;
-r)
- ls_remote_branches
- exit
+ sedmatch="^refs/\(remotes/\)"
+ sedsubst="\1"
;;
-f)
force="$1"
@@ -73,6 +94,13 @@ do
-l)
create_log="yes"
;;+ -v)
+ verbose="yes"
+ ;;
+ -w)
+ shift
+ width=$1
+ ;;
--)
shift
break@@ -86,18 +114,7 @@ done
case "$#" in
0)
- git-rev-parse --symbolic --branches | - sort | - while read ref - do
- if test "$headref" = "$ref"
- then
- pfx='*'
- else
- pfx=' '
- fi
- echo "$pfx $ref"
- done
+ ls_refs
exit 0 ;;
1)
head=HEAD ;;And then I added -a and -t (for "all" and "tags", obviously), and felt I went over the top :-)
Btw: in the meantime, Kristian Høgsberg pointed me to an earlier thread regarding making git-branch a builtin, which I'm going to look at tonight.
So many options, so little time :-)
I'm open for suggestions/preferences etc...
--
larsh