{"thread":{"id":"20620","subject":"[PATCHv3 0/3] git-gui: more robust handling of fancy repos","startedAt":"2009-08-16T23:58:45Z","lastAt":"2009-12-06T13:43:47Z","messageCount":9,"participants":["Giuseppe Bilotta","Bert Wesarg","Shawn O. Pearce"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"120802","messageId":"1250467128-29839-1-git-send-email-giuseppe.bilotta@gmail.com","threadId":"20620","inReplyTo":null,"subject":"[PATCHv3 0/3] git-gui: more robust handling of fancy repos","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-08-16T23:58:45Z","receivedAt":"2009-08-16T23:58:45Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"As promised a long time ago (March 30), version 3 of the small patchset\nto improve handling of repositories in git gui. The most significant\nchange is the addition of the third patch.\n\nThe first patch allows git gui to work with respotiories for which\nthe worktree is not the parent of the gitdir.\n\nThe second patch refactors bare repository detection, improves the error\nmessage if the bare support feature is disabled, and disabled\ninapplicable menu entries.\n\nThe third patch allows git-gui to work properly when launched from the\n.git directory itself, solving the issue Markus Heidelberg was having in\nhttp://thread.gmane.org/gmane.comp.version-control.git/115044\n\nGiuseppe Bilotta (3):\n  git-gui: handle non-standard worktree locations\n  git-gui: handle bare repos correctly\n  git-gui: work from the .git dir\n\n git-gui/git-gui.sh |   88 +++++++++++++++++++++++++++++++++++++++++++---------\n 1 files changed, 73 insertions(+), 15 deletions(-)\n"},{"id":"120803","messageId":"1250467128-29839-2-git-send-email-giuseppe.bilotta@gmail.com","threadId":"20620","inReplyTo":"1250467128-29839-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv3 1/3] git-gui: handle non-standard worktree locations","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-08-16T23:58:46Z","receivedAt":"2009-08-16T23:58:46Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"Don't rely on the git worktree being the updir of the gitdir, since it\nmight not be. Instead, define (and use) a new _gitworktree global\nvariable, setting it to $GIT_WORK_TREE if present, falling back to\ncore.worktree if defined, and finally to whatever we guess the correct\nworktree is. Getting core.worktree requires the config from the alleged\ngit dir _gitdir to be loaded early.\n\nSupporting non-standard worktree locations also breaks the git-gui\nassumption (made when calling gitk) that the worktree was the dirname of\n$_gitdir and that, by consequence, the git dir could be set to the tail\nof $_gitdir once we changed to the worktree root directory. Therefore,\nwe need to export a GIT_DIR environment variable set to the full,\nnormalized path of $_gitdir instead. We also skip changing to the worktree\ndirectory if it's empty (i.e. if we're working on a bare repository).\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n git-gui/git-gui.sh |   37 ++++++++++++++++++++++++++++---------\n 1 files changed, 28 insertions(+), 9 deletions(-)\n\ndiff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh\nindex 14b92ba..229e94a 100755\n--- a/git-gui/git-gui.sh\n+++ b/git-gui/git-gui.sh\n@@ -121,6 +121,7 @@ unset oguimsg\n \n set _appname {Git Gui}\n set _gitdir {}\n+set _gitworktree {}\n set _gitexec {}\n set _githtmldir {}\n set _reponame {}\n@@ -1088,13 +1089,25 @@ if {![file isdirectory $_gitdir]} {\n \terror_popup [strcat [mc \"Git directory not found:\"] \"\\n\\n$_gitdir\"]\n \texit 1\n }\n+# _gitdir exists, so try loading the config\n+load_config 0\n+apply_config\n+# try to set work tree from environment, falling back to core.worktree\n+if {[catch { set _gitworktree $env(GIT_WORK_TREE) }]} {\n+\tset _gitworktree [get_config core.worktree]\n+}\n if {$_prefix ne {}} {\n-\tregsub -all {[^/]+/} $_prefix ../ cdup\n+\tif {$_gitworktree eq {}} {\n+\t\tregsub -all {[^/]+/} $_prefix ../ cdup\n+\t} else {\n+\t\tset cdup $_gitworktree\n+\t}\n \tif {[catch {cd $cdup} err]} {\n \t\tcatch {wm withdraw .}\n \t\terror_popup [strcat [mc \"Cannot move to top of working directory:\"] \"\\n\\n$err\"]\n \t\texit 1\n \t}\n+\tset _gitworktree [pwd]\n \tunset cdup\n } elseif {![is_enabled bare]} {\n \tif {[lindex [file split $_gitdir] end] ne {.git}} {\n@@ -1102,11 +1115,15 @@ if {$_prefix ne {}} {\n \t\terror_popup [strcat [mc \"Cannot use funny .git directory:\"] \"\\n\\n$_gitdir\"]\n \t\texit 1\n \t}\n-\tif {[catch {cd [file dirname $_gitdir]} err]} {\n+\tif {$_gitworktree eq {}} {\n+\t\tset _gitworktree [file dirname $_gitdir]\n+\t}\n+\tif {[catch {cd $_gitworktree} err]} {\n \t\tcatch {wm withdraw .}\n-\t\terror_popup [strcat [mc \"No working directory\"] \" [file dirname $_gitdir]:\\n\\n$err\"]\n+\t\terror_popup [strcat [mc \"No working directory\"] \" $_gitworktree:\\n\\n$err\"]\n \t\texit 1\n \t}\n+\tset _gitworktree [pwd]\n }\n set _reponame [file split [file normalize $_gitdir]]\n if {[lindex $_reponame end] eq {.git}} {\n@@ -1905,6 +1922,7 @@ proc incr_font_size {font {amt 1}} {\n set starting_gitk_msg [mc \"Starting gitk... please wait...\"]\n \n proc do_gitk {revs} {\n+\tglobal _gitworktree\n \t# -- Always start gitk through whatever we were loaded with.  This\n \t#    lets us bypass using shell process on Windows systems.\n \t#\n@@ -1922,8 +1940,10 @@ proc do_gitk {revs} {\n \t\t}\n \n \t\tset pwd [pwd]\n-\t\tcd [file dirname [gitdir]]\n-\t\tset env(GIT_DIR) [file tail [gitdir]]\n+\t\tif { $_gitworktree ne {} } {\n+\t\t\tcd $_gitworktree\n+\t\t}\n+\t\tset env(GIT_DIR) [file normalize [gitdir]]\n \n \t\teval exec $cmd $revs &\n \n@@ -1942,6 +1962,7 @@ proc do_gitk {revs} {\n }\n \n proc do_explore {} {\n+\tglobal _gitworktree\n \tset explorer {}\n \tif {[is_Cygwin] || [is_Windows]} {\n \t\tset explorer \"explorer.exe\"\n@@ -1951,7 +1972,7 @@ proc do_explore {} {\n \t\t# freedesktop.org-conforming system is our best shot\n \t\tset explorer \"xdg-open\"\n \t}\n-\teval exec $explorer [list [file nativename [file dirname [gitdir]]]] &\n+\teval exec $explorer $_gitworktree &\n }\n \n set is_quitting 0\n@@ -2297,8 +2318,6 @@ proc show_less_context {} {\n ##\n ## ui construction\n \n-load_config 0\n-apply_config\n set ui_comm {}\n \n # -- Menu Bar\n@@ -3328,7 +3347,7 @@ unset i\n set file_lists($ui_index) [list]\n set file_lists($ui_workdir) [list]\n \n-wm title . \"[appname] ([reponame]) [file normalize [file dirname [gitdir]]]\"\n+wm title . \"[appname] ([reponame]) [file normalize $_gitworktree]\"\n focus -force $ui_comm\n \n # -- Warn the user about environmental problems.  Cygwin's Tcl\n-- \n1.6.4.177.g695987\n"},{"id":"120805","messageId":"1250467128-29839-3-git-send-email-giuseppe.bilotta@gmail.com","threadId":"20620","inReplyTo":"1250467128-29839-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv3 2/3] git-gui: handle bare repos correctly","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-08-16T23:58:47Z","receivedAt":"2009-08-16T23:58:47Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"Refactor checking for a bare repository into its own proc, that relies\non git rev-parse --is-bare-repository if possible. For older versions of\ngit we fall back to a logic such that the repository is considered bare\nif:\n * either the core.bare setting is true\n * or the worktree is not set and the directory name ends with .git\nThe error message for the case of an unhandled bare repository is also\nupdated to reflect the fact that the problem is not the funny name but\nthe bareness.\n\nThe new refactored proc is also used to disable the menu entry to\nexplore the working copy, and to skip changing to the worktree before\nthe gitk invocation.\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n git-gui/git-gui.sh |   43 ++++++++++++++++++++++++++++++++++++-------\n 1 files changed, 36 insertions(+), 7 deletions(-)\n\ndiff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh\nindex 229e94a..38b11c1 100755\n--- a/git-gui/git-gui.sh\n+++ b/git-gui/git-gui.sh\n@@ -122,6 +122,7 @@ unset oguimsg\n set _appname {Git Gui}\n set _gitdir {}\n set _gitworktree {}\n+set _isbare {}\n set _gitexec {}\n set _githtmldir {}\n set _reponame {}\n@@ -277,6 +278,32 @@ proc get_config {name} {\n \t}\n }\n \n+proc is_bare {} {\n+\tglobal _isbare\n+\tglobal _gitdir\n+\tglobal _gitworktree\n+\n+\tif {$_isbare eq {}} {\n+\t\tif {[catch {\n+\t\t\tset _bare [git rev-parse --is-bare-repository]\n+\t\t\tswitch  -- $_bare {\n+\t\t\ttrue { set _isbare 1 }\n+\t\t\tfalse { set _isbare 0}\n+\t\t\tdefault { throw }\n+\t\t\t}\n+\t\t}]} {\n+\t\t\tif {[is_config_true core.bare]\n+\t\t\t\t|| ($_gitworktree eq {}\n+\t\t\t\t\t&& [lindex [file split $_gitdir] end] ne {.git})} {\n+\t\t\t\tset _isbare 1\n+\t\t\t} else {\n+\t\t\t\tset _isbare 0\n+\t\t\t}\n+\t\t}\n+\t}\n+\treturn $_isbare\n+}\n+\n ######################################################################\n ##\n ## handy utils\n@@ -1110,9 +1137,9 @@ if {$_prefix ne {}} {\n \tset _gitworktree [pwd]\n \tunset cdup\n } elseif {![is_enabled bare]} {\n-\tif {[lindex [file split $_gitdir] end] ne {.git}} {\n+\tif {[is_bare]} {\n \t\tcatch {wm withdraw .}\n-\t\terror_popup [strcat [mc \"Cannot use funny .git directory:\"] \"\\n\\n$_gitdir\"]\n+\t\terror_popup [strcat [mc \"Cannot use bare repository:\"] \"\\n\\n$_gitdir\"]\n \t\texit 1\n \t}\n \tif {$_gitworktree eq {}} {\n@@ -1940,7 +1967,7 @@ proc do_gitk {revs} {\n \t\t}\n \n \t\tset pwd [pwd]\n-\t\tif { $_gitworktree ne {} } {\n+\t\tif { ![is_bare] } {\n \t\t\tcd $_gitworktree\n \t\t}\n \t\tset env(GIT_DIR) [file normalize [gitdir]]\n@@ -2349,10 +2376,12 @@ if {[is_enabled multicommit] || [is_enabled singlecommit]} {\n #\n menu .mbar.repository\n \n-.mbar.repository add command \\\n-\t-label [mc \"Explore Working Copy\"] \\\n-\t-command {do_explore}\n-.mbar.repository add separator\n+if {![is_bare]} {\n+\t.mbar.repository add command \\\n+\t\t-label [mc \"Explore Working Copy\"] \\\n+\t\t-command {do_explore}\n+\t.mbar.repository add separator\n+}\n \n .mbar.repository add command \\\n \t-label [mc \"Browse Current Branch's Files\"] \\\n-- \n1.6.4.177.g695987\n"},{"id":"120804","messageId":"1250467128-29839-4-git-send-email-giuseppe.bilotta@gmail.com","threadId":"20620","inReplyTo":"1250467128-29839-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"[PATCHv3 3/3] git-gui: work from the .git dir","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-08-16T23:58:48Z","receivedAt":"2009-08-16T23:58:48Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"When git-gui is run from a .git dir, _gitdir would be set to \".\" by\nrev-parse, something that confuses the worktree detection.\n\nFix by expanding the value of _gitdir to pwd in this special case.\n\nSigned-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>\n---\n git-gui/git-gui.sh |   10 ++++++++++\n 1 files changed, 10 insertions(+), 0 deletions(-)\n\ndiff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh\nindex 38b11c1..fbad6fd 100755\n--- a/git-gui/git-gui.sh\n+++ b/git-gui/git-gui.sh\n@@ -1100,6 +1100,8 @@ if {[catch {\n \t\tset _prefix {}\n \t\t}]\n \t&& [catch {\n+\t\t# beware that from the .git dir this sets _gitdir to .\n+\t\t# and _prefix to the empty string\n \t\tset _gitdir [git rev-parse --git-dir]\n \t\tset _prefix [git rev-parse --show-prefix]\n \t} err]} {\n@@ -1108,6 +1110,14 @@ if {[catch {\n \tchoose_repository::pick\n \tset picked 1\n }\n+\n+# we expand the _gitdir when it's just a single dot (i.e. when we're being\n+# run from the .git dir itself) lest the routines to find the worktree\n+# get confused\n+if {$_gitdir eq \".\"} {\n+\tset _gitdir [pwd]\n+}\n+\n if {![file isdirectory $_gitdir] && [is_Cygwin]} {\n \tcatch {set _gitdir [exec cygpath --windows $_gitdir]}\n }\n-- \n1.6.4.177.g695987\n"},{"id":"126005","messageId":"36ca99e90910270435h69c1e983j78ff9ec49e7e8eae@mail.gmail.com","threadId":"20620","inReplyTo":"1250467128-29839-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"Re: [PATCHv3 0/3] git-gui: more robust handling of fancy repos","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2009-10-27T11:35:23Z","receivedAt":"2009-10-27T11:35:23Z","isPatch":false,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"On Mon, Aug 17, 2009 at 00:58, Giuseppe Bilotta\n<giuseppe.bilotta@gmail.com> wrote:\n> As promised a long time ago (March 30), version 3 of the small patchset\n> to improve handling of repositories in git gui. The most significant\n> change is the addition of the third patch.\n>\n> The first patch allows git gui to work with respotiories for which\n> the worktree is not the parent of the gitdir.\n>\n> The second patch refactors bare repository detection, improves the error\n> message if the bare support feature is disabled, and disabled\n> inapplicable menu entries.\n>\n> The third patch allows git-gui to work properly when launched from the\n> .git directory itself, solving the issue Markus Heidelberg was having in\n> http://thread.gmane.org/gmane.comp.version-control.git/115044\n>\n> Giuseppe Bilotta (3):\n>  git-gui: handle non-standard worktree locations\n>  git-gui: handle bare repos correctly\n>  git-gui: work from the .git dir\nWhat is the state of this patch, I can't find it applied.\n\nI would also suggest to always export GIT_DIR into the environment, so\nthat guitools can relay on this.\n\nRegards,\nBert\n"},{"id":"129294","messageId":"20091205221515.GH5610@spearce.org","threadId":"20620","inReplyTo":"1250467128-29839-1-git-send-email-giuseppe.bilotta@gmail.com","subject":"Re: [PATCHv3 0/3] git-gui: more robust handling of fancy repos","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2009-12-05T22:15:15Z","receivedAt":"2009-12-05T22:15:15Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Giuseppe Bilotta <giuseppe.bilotta@gmail.com> wrote:\n> As promised a long time ago (March 30), version 3 of the small patchset\n> to improve handling of repositories in git gui. The most significant\n> change is the addition of the third patch.\n...\n> Giuseppe Bilotta (3):\n>   git-gui: handle non-standard worktree locations\n>   git-gui: handle bare repos correctly\n>   git-gui: work from the .git dir\n> \n>  git-gui/git-gui.sh |   88 +++++++++++++++++++++++++++++++++++++++++++---------\n>  1 files changed, 73 insertions(+), 15 deletions(-)\n\nUnfortunately this series doesn't apply to my tree, and I don't\nhave the blobs which are recorded in the index line, so I can't\neasily 3-way merge it onto the current tip.\n\nWould you be able to rebase it?\n\n-- \nShawn.\n"},{"id":"129321","messageId":"cb7bb73a0912060014p548884e0g8c4510a5b562901b@mail.gmail.com","threadId":"20620","inReplyTo":"36ca99e90910270435h69c1e983j78ff9ec49e7e8eae@mail.gmail.com","subject":"Re: [PATCHv3 0/3] git-gui: more robust handling of fancy repos","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-12-06T08:14:10Z","receivedAt":"2009-12-06T08:14:10Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"On Tue, Oct 27, 2009 at 12:35 PM, Bert Wesarg\n<bert.wesarg@googlemail.com> wrote:\n>\n> I would also suggest to always export GIT_DIR into the environment, so\n> that guitools can relay on this.\n\nI'm sorry I couldn't reply to this email earlier. I have never used\nthis feature, but if you can provide some example guitools\nconfiguration I'll gladly move the environment export earlier and test\nit.\n\n-- \nGiuseppe \"Oblomov\" Bilotta\n"},{"id":"129324","messageId":"36ca99e90912060459u1073288bj2114f8ab56c7224b@mail.gmail.com","threadId":"20620","inReplyTo":"cb7bb73a0912060014p548884e0g8c4510a5b562901b@mail.gmail.com","subject":"Re: [PATCHv3 0/3] git-gui: more robust handling of fancy repos","fromName":"Bert Wesarg","fromEmail":"bert.wesarg@googlemail.com","sentAt":"2009-12-06T12:59:22Z","receivedAt":"2009-12-06T12:59:22Z","isPatch":false,"sender":{"key":"bert.wesarg@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/111934?v=4"},"body":"On Sun, Dec 6, 2009 at 09:14, Giuseppe Bilotta\n<giuseppe.bilotta@gmail.com> wrote:\n> On Tue, Oct 27, 2009 at 12:35 PM, Bert Wesarg\n> <bert.wesarg@googlemail.com> wrote:\n>>\n>> I would also suggest to always export GIT_DIR into the environment, so\n>> that guitools can relay on this.\n>\n> I'm sorry I couldn't reply to this email earlier. I have never used\n> this feature, but if you can provide some example guitools\n> configuration I'll gladly move the environment export earlier and test\n> it.\nHere it is:\n\n[guitool \"exclude/Ignore file\"]\n\tcmd = echo \\\"$FILENAME\\\" >> \\\"${GIT_DIR:=.git}/info/exclude\\\"\n\tnoconsole = yes\n\tneedsfile = yes\n\nThe purpose is simple: add the current file to the info/exclude file\nin the git dir As you can see, I have a workaround for not having\nGIT_DIR in the env, which should solve the issue. But it would be nice\nto rely on this.\n\nBert\n>\n> --\n> Giuseppe \"Oblomov\" Bilotta\n>\n"},{"id":"129326","messageId":"cb7bb73a0912060543x6e7b2d28xfcd9bef4db3af1b8@mail.gmail.com","threadId":"20620","inReplyTo":"36ca99e90912060459u1073288bj2114f8ab56c7224b@mail.gmail.com","subject":"Re: [PATCHv3 0/3] git-gui: more robust handling of fancy repos","fromName":"Giuseppe Bilotta","fromEmail":"giuseppe.bilotta@gmail.com","sentAt":"2009-12-06T13:43:47Z","receivedAt":"2009-12-06T13:43:47Z","isPatch":false,"sender":{"key":"giuseppe.bilotta@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1464?v=4"},"body":"On Sun, Dec 6, 2009 at 1:59 PM, Bert Wesarg <bert.wesarg@googlemail.com> wrote:\n> Here it is:\n>\n> [guitool \"exclude/Ignore file\"]\n>        cmd = echo \\\"$FILENAME\\\" >> \\\"${GIT_DIR:=.git}/info/exclude\\\"\n>        noconsole = yes\n>        needsfile = yes\n>\n> The purpose is simple: add the current file to the info/exclude file\n> in the git dir As you can see, I have a workaround for not having\n> GIT_DIR in the env, which should solve the issue. But it would be nice\n> to rely on this.\n\nYup. I'm thinking about setting both $GIT_DIR and $GIT_WORK_TREE once\nand for all at the end of the repo setup. This should also spare us\nsetting it up specifically for gitk (and then separately for the\ntools). The question is: should it be done the way it's done for gitk\n(i.e. normalizing the paths), or just use it as-is? In the latter\ncase, the question would be why is the path being normalized before\ngitk is invoked.\n\nIdeas?\n\n-- \nGiuseppe \"Oblomov\" Bilotta\n"}]}