* [PATCH 0/3] Add -v and -w options to git-branch @ 2006-10-22 11:30 Lars Hjemli [not found] ` <5245bfe3982f5c23841229af9f548f982b9c60c3.1161516129.git.hjemli@gmail.com> 0 siblings, 1 reply; 7+ messages in thread From: Lars Hjemli @ 2006-10-22 11:30 UTC (permalink / raw) To: git 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(-) ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <5245bfe3982f5c23841229af9f548f982b9c60c3.1161516129.git.hjemli@gmail.com>]
* [PATCH 1/3] Fix usagestring for git-branch [not found] ` <5245bfe3982f5c23841229af9f548f982b9c60c3.1161516129.git.hjemli@gmail.com> @ 2006-10-22 11:30 ` Lars Hjemli [not found] ` <00a2e5d38382cea6ff991f60c42923092e1d4dfc.1161516129.git.hjemli@gmail.com> [not found] ` <18d62bea290e360a4b5b44df9f23265c5e77964e.1161516129.git.hjemli@gmail.com> 2 siblings, 0 replies; 7+ messages in thread From: Lars Hjemli @ 2006-10-22 11:30 UTC (permalink / raw) To: git Signed-off-by: Lars Hjemli <hjemli@gmail.com> --- git-branch.sh | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/git-branch.sh b/git-branch.sh index 4379a07..b80bcda 100755 --- a/git-branch.sh +++ b/git-branch.sh @@ -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>.' -- 1.4.3.1.g1688 ^ permalink raw reply related [flat|nested] 7+ messages in thread
[parent not found: <00a2e5d38382cea6ff991f60c42923092e1d4dfc.1161516129.git.hjemli@gmail.com>]
* [PATCH 2/3] Refactor git-branch [not found] ` <00a2e5d38382cea6ff991f60c42923092e1d4dfc.1161516129.git.hjemli@gmail.com> @ 2006-10-22 11:30 ` Lars Hjemli 0 siblings, 0 replies; 7+ messages in thread From: Lars Hjemli @ 2006-10-22 11:30 UTC (permalink / raw) To: git This moves the code used to display local branches into a separate function. Signed-off-by: Lars Hjemli <hjemli@gmail.com> --- git-branch.sh | 28 ++++++++++++++++------------ 1 files changed, 16 insertions(+), 12 deletions(-) diff --git a/git-branch.sh b/git-branch.sh index b80bcda..1f628a4 100755 --- a/git-branch.sh +++ b/git-branch.sh @@ -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 ;; -- 1.4.3.1.g1688 ^ permalink raw reply related [flat|nested] 7+ messages in thread
[parent not found: <18d62bea290e360a4b5b44df9f23265c5e77964e.1161516129.git.hjemli@gmail.com>]
* [PATCH 3/3] Teach git-branch -v and -w options [not found] ` <18d62bea290e360a4b5b44df9f23265c5e77964e.1161516129.git.hjemli@gmail.com> @ 2006-10-22 11:30 ` Lars Hjemli 2006-10-22 19:35 ` Junio C Hamano 0 siblings, 1 reply; 7+ messages in thread From: Lars Hjemli @ 2006-10-22 11:30 UTC (permalink / raw) To: git 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 <hjemli@gmail.com> --- Documentation/git-branch.txt | 8 ++++++- git-branch.sh | 47 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/Documentation/git-branch.txt b/Documentation/git-branch.txt index d43ef1d..efbab61 100644 --- a/Documentation/git-branch.txt +++ b/Documentation/git-branch.txt @@ -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 diff --git a/git-branch.sh b/git-branch.sh index 1f628a4..73839b4 100755 --- a/git-branch.sh +++ b/git-branch.sh @@ -1,6 +1,6 @@ #!/bin/sh -USAGE=' [-l] [-f] <branchname> [<start-point>] | (-d | -D) <branchname> | [-r]' +USAGE=' [-l] [-f] <branchname> [<start-point>] | (-d | -D) <branchname> | [-r] [-v [-w width]]' 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>.' @@ -49,12 +49,26 @@ If you are sure you want to delete it, r } ls_remote_branches () { + verbose="$1" + width="$2" git-rev-parse --symbolic --all | sed -ne 's|^refs/\(remotes/\)|\1|p' | - sort + sort | + while read ref + do + if test "$verbose" = "yes" + then + log=$(git-log --pretty=oneline --max-count=1 "$ref") + printf "%-*s %s\n" "$width" "$ref" "$log" + else + echo "$ref" + fi + done } ls_local_branches () { + verbose="$1" + width="$2" git-rev-parse --symbolic --branches | sort | while read ref @@ -65,12 +79,22 @@ ls_local_branches () { else pfx=' ' fi - echo "$pfx $ref" + if test "$verbose" = "yes" + then + log=$(git-log --pretty=oneline --max-count=1 "$ref") + printf "%s %-*s %s\n" "$pfx" "$width" "$ref" "$log" + else + echo "$pfx $ref" + fi done } force= create_log= +remotes= +verbose= +width=20 + while case "$#,$1" in 0,*) break ;; *,-*) ;; *) break ;; esac do case "$1" in @@ -79,8 +103,14 @@ do exit ;; -r) - ls_remote_branches - exit + remotes="yes" + ;; + -v) + verbose="yes" + ;; + -w) + shift + width="$1" ;; -f) force="$1" @@ -101,7 +131,12 @@ done case "$#" in 0) - ls_local_branches + if test "$remotes" = "yes" + then + ls_remote_branches "$verbose" "$width" + else + ls_local_branches "$verbose" "$width" + fi exit 0 ;; 1) head=HEAD ;; -- 1.4.3.1.g1688 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] Teach git-branch -v and -w options 2006-10-22 11:30 ` [PATCH 3/3] Teach git-branch -v and -w options Lars Hjemli @ 2006-10-22 19:35 ` Junio C Hamano 2006-10-22 19:55 ` Lars Hjemli [not found] ` <8c5c35580610221254r7a5a009cg7ee9a9d5821f5e99@mail.gmail.com> 0 siblings, 2 replies; 7+ messages in thread From: Junio C Hamano @ 2006-10-22 19:35 UTC (permalink / raw) To: Lars Hjemli; +Cc: git Lars Hjemli <hjemli@gmail.com> writes: > 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 <hjemli@gmail.com> 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? ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] Teach git-branch -v and -w options 2006-10-22 19:35 ` Junio C Hamano @ 2006-10-22 19:55 ` Lars Hjemli [not found] ` <8c5c35580610221254r7a5a009cg7ee9a9d5821f5e99@mail.gmail.com> 1 sibling, 0 replies; 7+ messages in thread From: Lars Hjemli @ 2006-10-22 19:55 UTC (permalink / raw) To: git On 10/22/06, Junio C Hamano <junkio@cox.net> wrote: > 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 ^ permalink raw reply [flat|nested] 7+ messages in thread
[parent not found: <8c5c35580610221254r7a5a009cg7ee9a9d5821f5e99@mail.gmail.com>]
[parent not found: <7vy7r83x9f.fsf@assigned-by-dhcp.cox.net>]
* Re: [PATCH 3/3] Teach git-branch -v and -w options [not found] ` <7vy7r83x9f.fsf@assigned-by-dhcp.cox.net> @ 2006-10-22 20:50 ` Lars Hjemli 0 siblings, 0 replies; 7+ messages in thread From: Lars Hjemli @ 2006-10-22 20:50 UTC (permalink / raw) To: Junio C Hamano; +Cc: git [the gitlist fell off my first reply, so I've put it back...] On 10/22/06, Junio C Hamano <junkio@cox.net> wrote: > 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 :-) > 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.sh > means 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. -- larsh ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2006-10-22 20:50 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2006-10-22 11:30 [PATCH 0/3] Add -v and -w options to git-branch Lars Hjemli [not found] ` <5245bfe3982f5c23841229af9f548f982b9c60c3.1161516129.git.hjemli@gmail.com> 2006-10-22 11:30 ` [PATCH 1/3] Fix usagestring for git-branch Lars Hjemli [not found] ` <00a2e5d38382cea6ff991f60c42923092e1d4dfc.1161516129.git.hjemli@gmail.com> 2006-10-22 11:30 ` [PATCH 2/3] Refactor git-branch Lars Hjemli [not found] ` <18d62bea290e360a4b5b44df9f23265c5e77964e.1161516129.git.hjemli@gmail.com> 2006-10-22 11:30 ` [PATCH 3/3] Teach git-branch -v and -w options Lars Hjemli 2006-10-22 19:35 ` Junio C Hamano 2006-10-22 19:55 ` Lars Hjemli [not found] ` <8c5c35580610221254r7a5a009cg7ee9a9d5821f5e99@mail.gmail.com> [not found] ` <7vy7r83x9f.fsf@assigned-by-dhcp.cox.net> 2006-10-22 20:50 ` Lars Hjemli
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).