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

Re: [PATCH 3/3] Teach git-branch -v and -w options

From
LHLars Hjemli <hjemli@gmail.com>
Date
Oct 22, 2006, 19:55 UTC
Message-ID
<8c5c35580610221255n521e84e2u8594016297c6cf87@mail.gmail.com>
In-Reply-To
<7vmz7o5eki.fsf@assigned-by-dhcp.cox.net>
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
Previous: Junio C HamanoNext: Lars Hjemli
Message 6 of 7 in “Add -v and -w options to git-branch”
  1. 0/3 Add -v and -w options to git-branchLars Hjemli, Oct 22, 2006
  2. 1/3 Fix usagestring for git-branchLars Hjemli, Oct 22, 2006
  3. 2/3 Refactor git-branchLars Hjemli, Oct 22, 2006
  4. 3/3 Teach git-branch -v and -w optionsLars Hjemli, Oct 22, 2006
  5. Junio C HamanoOct 22, 2006
  6. Lars HjemliOct 22, 2006
  7. Lars HjemliOct 22, 2006

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.