{"thread":{"id":"3043","subject":"[PATCH] stgit: fix clone","startedAt":"2006-01-11T22:19:26Z","lastAt":"2006-01-13T05:24:33Z","messageCount":6,"participants":["Pavel Roskin","Chuck Lever","Catalin Marinas"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"14506","messageId":"1137017966.10975.8.camel@dv","threadId":"3043","inReplyTo":null,"subject":"[PATCH] stgit: fix clone","fromName":"Pavel Roskin","fromEmail":"proski@gnu.org","sentAt":"2006-01-11T22:19:26Z","receivedAt":"2006-01-11T22:19:26Z","isPatch":true,"sender":{"key":"proski@gnu.org","avatar":null},"body":"\"stg clone\" is currently broken:\n\n$ stg clone http://homepage.ntlworld.com/cmarinas/stgit.git    \nstg clone: git-rev-parse --git-dir failed\n\nThis happens with current git.  \"git-rev-parse --git-dir\" doesn't work\nin an empty directory.  The patch avoids running \"git-rev-parse\n--git-dir\" when the requested command doesn't assume existence of git\nrepository.\n\nSigned-off-by: Pavel Roskin <proski@gnu.org>\n\n---\nWarning: this is my first non-trivial patch to StGIT and the first patch\nto a Python program.\n\ndiff --git a/stgit/git.py b/stgit/git.py\nindex a7b1c3f..0e63f69 100644\n--- a/stgit/git.py\n+++ b/stgit/git.py\n@@ -82,13 +82,16 @@ __commits = dict()\n # Functions\n #\n \n-def get_base_dir():\n+def get_base_dir(assume_top = False):\n     \"\"\"Different start-up variables read from the environment\n     \"\"\"\n     if 'GIT_DIR' in os.environ:\n         return os.environ['GIT_DIR']\n     else:\n-        return _output_one_line('git-rev-parse --git-dir')\n+        if assume_top:\n+            return '.git'\n+        else:\n+            return _output_one_line('git-rev-parse --git-dir')\n \n def get_commit(id_hash):\n     \"\"\"Commit objects factory. Save/look-up them in the __commits\ndiff --git a/stgit/stack.py b/stgit/stack.py\nindex 8b7c296..1c080b3 100644\n--- a/stgit/stack.py\n+++ b/stgit/stack.py\n@@ -263,7 +263,7 @@ class Series:\n             self.__name = git.get_head_file()\n \n         if self.__name:\n-            base_dir = git.get_base_dir()\n+            base_dir = git.get_base_dir(assume_top = (name == 'master'))\n             self.__patch_dir = os.path.join(base_dir, 'patches',\n                                             self.__name)\n             self.__base_file = os.path.join(base_dir, 'refs', 'bases',\n\n\n-- \nRegards,\nPavel Roskin\n"},{"id":"14507","messageId":"43C58916.6030409@citi.umich.edu","threadId":"3043","inReplyTo":"1137017966.10975.8.camel@dv","subject":"Re: [PATCH] stgit: fix clone","fromName":"Chuck Lever","fromEmail":"cel@citi.umich.edu","sentAt":"2006-01-11T22:39:18Z","receivedAt":"2006-01-11T22:39:18Z","isPatch":true,"sender":{"key":"cel@citi.umich.edu","avatar":null},"body":"hi pavel-\n\nexactly where does the clone operation fail?  is it at the checkout step?\n\nseems to me the \"git clone\" script should create an environment where \n\"git-rev-parse --git-dir\" ought to work correctly.\n\nPavel Roskin wrote:\n> \"stg clone\" is currently broken:\n> \n> $ stg clone http://homepage.ntlworld.com/cmarinas/stgit.git    \n> stg clone: git-rev-parse --git-dir failed\n> \n> This happens with current git.  \"git-rev-parse --git-dir\" doesn't work\n> in an empty directory.  The patch avoids running \"git-rev-parse\n> --git-dir\" when the requested command doesn't assume existence of git\n> repository.\n> \n> Signed-off-by: Pavel Roskin <proski@gnu.org>\n> \n> ---\n> Warning: this is my first non-trivial patch to StGIT and the first patch\n> to a Python program.\n> \n> diff --git a/stgit/git.py b/stgit/git.py\n> index a7b1c3f..0e63f69 100644\n> --- a/stgit/git.py\n> +++ b/stgit/git.py\n> @@ -82,13 +82,16 @@ __commits = dict()\n>  # Functions\n>  #\n>  \n> -def get_base_dir():\n> +def get_base_dir(assume_top = False):\n>      \"\"\"Different start-up variables read from the environment\n>      \"\"\"\n>      if 'GIT_DIR' in os.environ:\n>          return os.environ['GIT_DIR']\n>      else:\n> -        return _output_one_line('git-rev-parse --git-dir')\n> +        if assume_top:\n> +            return '.git'\n> +        else:\n> +            return _output_one_line('git-rev-parse --git-dir')\n>  \n>  def get_commit(id_hash):\n>      \"\"\"Commit objects factory. Save/look-up them in the __commits\n> diff --git a/stgit/stack.py b/stgit/stack.py\n> index 8b7c296..1c080b3 100644\n> --- a/stgit/stack.py\n> +++ b/stgit/stack.py\n> @@ -263,7 +263,7 @@ class Series:\n>              self.__name = git.get_head_file()\n>  \n>          if self.__name:\n> -            base_dir = git.get_base_dir()\n> +            base_dir = git.get_base_dir(assume_top = (name == 'master'))\n>              self.__patch_dir = os.path.join(base_dir, 'patches',\n>                                              self.__name)\n>              self.__base_file = os.path.join(base_dir, 'refs', 'bases',\n> \n> \n\n\n\nbegin:vcard\nfn:Chuck Lever\nn:Lever;Charles\norg:Network Appliance, Incorporated;Open Source NFS Client Development\nadr:535 West William Street, Suite 3100;;Center for Information Technology Integration;Ann Arbor;MI;48103-4943;USA\nemail;internet:cel@citi.umich.edu\ntitle:Member of Technical Staff\ntel;work:+1 734 763-4415\ntel;fax:+1 734 763 4434\ntel;home:+1 734 668-1089\nx-mozilla-html:FALSE\nurl:http://troy.citi.umich.edu/u/cel/\nversion:2.1\nend:vcard\n\n"},{"id":"14508","messageId":"43C58AF3.10606@citi.umich.edu","threadId":"3043","inReplyTo":"43C58916.6030409@citi.umich.edu","subject":"Re: [PATCH] stgit: fix clone","fromName":"Chuck Lever","fromEmail":"cel@citi.umich.edu","sentAt":"2006-01-11T22:47:15Z","receivedAt":"2006-01-11T22:47:15Z","isPatch":true,"sender":{"key":"cel@citi.umich.edu","avatar":null},"body":"Chuck Lever wrote:\n> hi pavel-\n> \n> exactly where does the clone operation fail?  is it at the checkout step?\n> \n> seems to me the \"git clone\" script should create an environment where \n> \"git-rev-parse --git-dir\" ought to work correctly.\n\noops.  i see it now.\n\nstgit/main.py does a special stack.Series('master') just for the clone \ncommand.  it really shouldn't do this -- the crt_series.init() in the \nclone command ought to be fixed to do this properly.\n\ncatalin, do you agree?\n\n\nbegin:vcard\nfn:Chuck Lever\nn:Lever;Charles\norg:Network Appliance, Incorporated;Open Source NFS Client Development\nadr:535 West William Street, Suite 3100;;Center for Information Technology Integration;Ann Arbor;MI;48103-4943;USA\nemail;internet:cel@citi.umich.edu\ntitle:Member of Technical Staff\ntel;work:+1 734 763-4415\ntel;fax:+1 734 763 4434\ntel;home:+1 734 668-1089\nx-mozilla-html:FALSE\nurl:http://troy.citi.umich.edu/u/cel/\nversion:2.1\nend:vcard\n\n"},{"id":"14546","messageId":"b0943d9e0601120354u73489c74j@mail.gmail.com","threadId":"3043","inReplyTo":"43C58AF3.10606@citi.umich.edu","subject":"Re: [PATCH] stgit: fix clone","fromName":"Catalin Marinas","fromEmail":"catalin.marinas@gmail.com","sentAt":"2006-01-12T11:54:00Z","receivedAt":"2006-01-12T11:54:00Z","isPatch":true,"sender":{"key":"catalin.marinas@gmail.com","avatar":null},"body":"On 11/01/06, Chuck Lever <cel@citi.umich.edu> wrote:\n> Chuck Lever wrote:\n> > seems to me the \"git clone\" script should create an environment where\n> > \"git-rev-parse --git-dir\" ought to work correctly.\n>\n> stgit/main.py does a special stack.Series('master') just for the clone\n> command.  it really shouldn't do this -- the crt_series.init() in the\n> clone command ought to be fixed to do this properly.\n\nIf the stack.Series() doesn't get a parameter, it will try to get the\ndefault branch using 'git-symbolic-ref HEAD'. Any command run outside\na tree (and which doesn't have the -h option) would fail. The clone\ncommand is the only one allowed to run outside a tree and that's why I\npassed a default branch name. This is to avoid the creation of another\nstack.Series() object later when the git tree was cloned.\n\nSee the attached patch for a different fix and let me know if there\nare any issues with it. I should probably release 0.8.1 with the fixed\nbugs.\n\n--\nCatalin\n\n\nFix the clone command failure\n\nFrom: Catalin Marinas <catalin.marinas@gmail.com>\n\nThe clone command fails because there is no GIT tree available, which is\nwrong. The patch fixes the Series.__init__() function and also creates a\nnew Series object in clone.py once a GIT tree was initialised.\n\nSigned-off-by: Catalin Marinas <catalin.marinas@gmail.com>\n---\n\n stgit/commands/clone.py |    2 +-\n stgit/main.py           |   18 ++++++++----------\n stgit/stack.py          |   30 ++++++++++++++++--------------\n 3 files changed, 25 insertions(+), 25 deletions(-)\n\ndiff --git a/stgit/commands/clone.py b/stgit/commands/clone.py\nindex f4e3f6b..9ad76a6 100644\n--- a/stgit/commands/clone.py\n+++ b/stgit/commands/clone.py\n@@ -51,6 +51,6 @@ def func(parser, options, args):\n     os.chdir(local_dir)\n     git.checkout(tree_id = 'HEAD')\n \n-    crt_series.init()\n+    stack.Series().init()\n \n     print 'done'\ndiff --git a/stgit/main.py b/stgit/main.py\nindex b84d91d..2336a43 100644\n--- a/stgit/main.py\n+++ b/stgit/main.py\n@@ -150,16 +150,14 @@ def main():\n                           option_list = command.options)\n     options, args = parser.parse_args()\n     try:\n-        # 'clone' doesn't expect an already initialised GIT tree\n-        if cmd == 'clone':\n-            stgit.commands.common.crt_series = stack.Series('master')\n-        elif hasattr(options, 'branch') and options.branch:\n-            stgit.commands.common.crt_series = stack.Series(options.branch)\n-        else:\n-            stgit.commands.common.crt_series = stack.Series()\n-        # the line below is a simple way to avoid an exception when\n-        # stgit is run outside an initialised tree\n-        setattr(command, 'crt_series', stgit.commands.common.crt_series)\n+        # 'clone' doesn't expect an already initialised GIT tree. A Series\n+        # object will be created after the GIT tree is cloned\n+        if cmd != 'clone':\n+            if hasattr(options, 'branch') and options.branch:\n+                command.crt_series = stack.Series(options.branch)\n+            else:\n+                command.crt_series = stack.Series()\n+            stgit.commands.common.crt_series = command.crt_series\n \n         command.func(parser, options, args)\n     except (IOError, CmdException, stack.StackException, git.GitException), \\\ndiff --git a/stgit/stack.py b/stgit/stack.py\nindex 8b7c296..c2adeb9 100644\n--- a/stgit/stack.py\n+++ b/stgit/stack.py\n@@ -257,21 +257,23 @@ class Series:\n     def __init__(self, name = None):\n         \"\"\"Takes a series name as the parameter.\n         \"\"\"\n-        if name:\n-            self.__name = name\n-        else:\n-            self.__name = git.get_head_file()\n-\n-        if self.__name:\n+        try:\n+            if name:\n+                self.__name = name\n+            else:\n+                self.__name = git.get_head_file()\n             base_dir = git.get_base_dir()\n-            self.__patch_dir = os.path.join(base_dir, 'patches',\n-                                            self.__name)\n-            self.__base_file = os.path.join(base_dir, 'refs', 'bases',\n-                                            self.__name)\n-            self.__applied_file = os.path.join(self.__patch_dir, 'applied')\n-            self.__unapplied_file = os.path.join(self.__patch_dir, 'unapplied')\n-            self.__current_file = os.path.join(self.__patch_dir, 'current')\n-            self.__descr_file = os.path.join(self.__patch_dir, 'description')\n+        except git.GitException, ex:\n+            raise StackException, 'GIT tree not initialised: %s' % ex\n+\n+        self.__patch_dir = os.path.join(base_dir, 'patches',\n+                                        self.__name)\n+        self.__base_file = os.path.join(base_dir, 'refs', 'bases',\n+                                        self.__name)\n+        self.__applied_file = os.path.join(self.__patch_dir, 'applied')\n+        self.__unapplied_file = os.path.join(self.__patch_dir, 'unapplied')\n+        self.__current_file = os.path.join(self.__patch_dir, 'current')\n+        self.__descr_file = os.path.join(self.__patch_dir, 'description')\n \n     def get_branch(self):\n         \"\"\"Return the branch name for the Series object\n"},{"id":"14551","messageId":"43C66CE5.1050009@citi.umich.edu","threadId":"3043","inReplyTo":"b0943d9e0601120354u73489c74j@mail.gmail.com","subject":"Re: [PATCH] stgit: fix clone","fromName":"Chuck Lever","fromEmail":"cel@citi.umich.edu","sentAt":"2006-01-12T14:51:17Z","receivedAt":"2006-01-12T14:51:17Z","isPatch":true,"sender":{"key":"cel@citi.umich.edu","avatar":null},"body":"Catalin Marinas wrote:\n> On 11/01/06, Chuck Lever <cel@citi.umich.edu> wrote:\n> \n>>Chuck Lever wrote:\n>>\n>>>seems to me the \"git clone\" script should create an environment where\n>>>\"git-rev-parse --git-dir\" ought to work correctly.\n>>\n>>stgit/main.py does a special stack.Series('master') just for the clone\n>>command.  it really shouldn't do this -- the crt_series.init() in the\n>>clone command ought to be fixed to do this properly.\n> \n> \n> If the stack.Series() doesn't get a parameter, it will try to get the\n> default branch using 'git-symbolic-ref HEAD'. Any command run outside\n> a tree (and which doesn't have the -h option) would fail. The clone\n> command is the only one allowed to run outside a tree and that's why I\n> passed a default branch name. This is to avoid the creation of another\n> stack.Series() object later when the git tree was cloned.\n> \n> See the attached patch for a different fix and let me know if there\n> are any issues with it. I should probably release 0.8.1 with the fixed\n> bugs.\n\nlooked at the patch.  that's what i had in mind.  the extra exception \nprocessing in Series.__init__ is a nice touch.\n\n\nbegin:vcard\nfn:Chuck Lever\nn:Lever;Charles\norg:Network Appliance, Incorporated;Open Source NFS Client Development\nadr:535 West William Street, Suite 3100;;Center for Information Technology Integration;Ann Arbor;MI;48103-4943;USA\nemail;internet:cel@citi.umich.edu\ntitle:Member of Technical Staff\ntel;work:+1 734 763-4415\ntel;fax:+1 734 763 4434\ntel;home:+1 734 668-1089\nx-mozilla-html:FALSE\nurl:http://troy.citi.umich.edu/u/cel/\nversion:2.1\nend:vcard\n\n"},{"id":"14602","messageId":"1137129873.20073.72.camel@dv","threadId":"3043","inReplyTo":"b0943d9e0601120354u73489c74j@mail.gmail.com","subject":"Re: [PATCH] stgit: fix clone","fromName":"Pavel Roskin","fromEmail":"proski@gnu.org","sentAt":"2006-01-13T05:24:33Z","receivedAt":"2006-01-13T05:24:33Z","isPatch":true,"sender":{"key":"proski@gnu.org","avatar":null},"body":"On Thu, 2006-01-12 at 11:54 +0000, Catalin Marinas wrote:\n\n> See the attached patch for a different fix and let me know if there\n> are any issues with it. I should probably release 0.8.1 with the fixed\n> bugs.\n\nI see you have applied the fix already.  Current StGIT is working fine\nwhen it comes to cloning.  Thank you!\n\n-- \nRegards,\nPavel Roskin\n"}]}