git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [StGit PATCH 0/2] Fix stg breakage with nweer gits
@ 2008-04-12 15:47 Karl Hasselström
  2008-04-12 15:47 ` [StGit PATCH 1/2] Don't both change directory and set GIT_WORK_TREE Karl Hasselström
  2008-04-12 15:47 ` [StGit PATCH 2/2] Log environment and cwd as well as the actual command Karl Hasselström
  0 siblings, 2 replies; 3+ messages in thread
From: Karl Hasselström @ 2008-04-12 15:47 UTC (permalink / raw)
  To: Catalin Marinas; +Cc: git, Erik Sandberg

The new-infrastructure commands stopped working with newer gits, due
to git merge-recursive starting to heed GIT_WORK_TREE. Patch 1/2 fixes
this issue; patch 2/2 is some debugging stuff I built while tracking
down the bug.

Erik, this fixes your bug.

---

Karl Hasselström (2):
      Log environment and cwd as well as the actual command
      Don't both change directory and set GIT_WORK_TREE


 stgit/lib/git.py |   14 +++++++++-----
 stgit/run.py     |    6 ++++++
 2 files changed, 15 insertions(+), 5 deletions(-)

-- 
Karl Hasselström, kha@treskal.com
      www.treskal.com/kalle

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [StGit PATCH 1/2] Don't both change directory and set GIT_WORK_TREE
  2008-04-12 15:47 [StGit PATCH 0/2] Fix stg breakage with nweer gits Karl Hasselström
@ 2008-04-12 15:47 ` Karl Hasselström
  2008-04-12 15:47 ` [StGit PATCH 2/2] Log environment and cwd as well as the actual command Karl Hasselström
  1 sibling, 0 replies; 3+ messages in thread
From: Karl Hasselström @ 2008-04-12 15:47 UTC (permalink / raw)
  To: Catalin Marinas; +Cc: git, Erik Sandberg

We used to both change the working directory and set GIT_WORK_TREE
when calling git merge-recursive. This works with older versions of
git (up to and including 1.5.4.x, or thereabouts) because
merge-recursive ignores GIT_WORK_TREE. It stopped doing that sometime
just before 1.5.5, which broke StGit. (Given both GIT_WORK_TREE=".."
and cwd "..", it assumed the work tree was at "../..", instead of just
".." like we intended. This made t2800 fail.)

Just dropping the cd would solve the problem for new gits, but would
break StGit with older gits. But it works in both cases if we keep the
cd, and unconditionally set GIT_WORK_TREE=".". So this patch does
precisely that.

(git read-tree -u -m is also called from IndexAndWorktree, and it
 seems to always ignore GIT_WORK_TREE just like merge-recursive used
 to do. The patch fixes all calls made from IndexAndWorktree, so we're
 good if read-tree starts heeding GIT_WORK_TREE in the future.)

Signed-off-by: Karl Hasselström <kha@treskal.com>

---

 stgit/lib/git.py |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)


diff --git a/stgit/lib/git.py b/stgit/lib/git.py
index 35b9bbf..c5b048f 100644
--- a/stgit/lib/git.py
+++ b/stgit/lib/git.py
@@ -298,6 +298,10 @@ class RunWithEnv(object):
     def run(self, args, env = {}):
         return run.Run(*args).env(utils.add_dict(self.env, env))
 
+class RunWithEnvCwd(RunWithEnv):
+    def run(self, args, env = {}):
+        return RunWithEnv.run(self, args, env).cwd(self.cwd)
+
 class Repository(RunWithEnv):
     def __init__(self, directory):
         self.__git_dir = directory
@@ -490,19 +494,20 @@ class Index(RunWithEnv):
 class Worktree(object):
     def __init__(self, directory):
         self.__directory = directory
-    env = property(lambda self: { 'GIT_WORK_TREE': self.__directory })
+    env = property(lambda self: { 'GIT_WORK_TREE': '.' })
     directory = property(lambda self: self.__directory)
 
 class CheckoutException(exception.StgException):
     pass
 
-class IndexAndWorktree(RunWithEnv):
+class IndexAndWorktree(RunWithEnvCwd):
     def __init__(self, index, worktree):
         self.__index = index
         self.__worktree = worktree
     index = property(lambda self: self.__index)
     env = property(lambda self: utils.add_dict(self.__index.env,
                                                self.__worktree.env))
+    cwd = property(lambda self: self.__worktree.directory)
     def checkout(self, old_tree, new_tree):
         # TODO: Optionally do a 3-way instead of doing nothing when we
         # have a problem. Or maybe we should stash changes in a patch?
@@ -512,7 +517,7 @@ class IndexAndWorktree(RunWithEnv):
             self.run(['git', 'read-tree', '-u', '-m',
                       '--exclude-per-directory=.gitignore',
                       old_tree.sha1, new_tree.sha1]
-                     ).cwd(self.__worktree.directory).discard_output()
+                     ).discard_output()
         except run.RunException:
             raise CheckoutException('Index/workdir dirty')
     def merge(self, base, ours, theirs):
@@ -524,8 +529,7 @@ class IndexAndWorktree(RunWithEnv):
                           theirs.sha1],
                          env = { 'GITHEAD_%s' % base.sha1: 'ancestor',
                                  'GITHEAD_%s' % ours.sha1: 'current',
-                                 'GITHEAD_%s' % theirs.sha1: 'patched'}
-                         ).cwd(self.__worktree.directory)
+                                 'GITHEAD_%s' % theirs.sha1: 'patched'})
             r.discard_output()
         except run.RunException, e:
             if r.exitcode == 1:

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [StGit PATCH 2/2] Log environment and cwd as well as the actual command
  2008-04-12 15:47 [StGit PATCH 0/2] Fix stg breakage with nweer gits Karl Hasselström
  2008-04-12 15:47 ` [StGit PATCH 1/2] Don't both change directory and set GIT_WORK_TREE Karl Hasselström
@ 2008-04-12 15:47 ` Karl Hasselström
  1 sibling, 0 replies; 3+ messages in thread
From: Karl Hasselström @ 2008-04-12 15:47 UTC (permalink / raw)
  To: Catalin Marinas; +Cc: git, Erik Sandberg

When debugging subprocess calls (with STGIT_SUBPROCESS_LOG=debug),
it's important to know the environment and working directory we pass
to the subprocess, not just the command-line parameters.

Signed-off-by: Karl Hasselström <kha@treskal.com>

---

 stgit/run.py |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)


diff --git a/stgit/run.py b/stgit/run.py
index 77f2e65..0b79729 100644
--- a/stgit/run.py
+++ b/stgit/run.py
@@ -48,6 +48,12 @@ class Run:
     def __log_start(self):
         if _log_mode == 'debug':
             out.start('Running subprocess %s' % self.__cmd)
+            if self.__cwd != None:
+                out.info('cwd: %s' % self.__cwd)
+            if self.__env != None:
+                for k in sorted(self.__env.iterkeys()):
+                    if k not in os.environ or os.environ[k] != self.__env[k]:
+                        out.info('%s: %s' % (k, self.__env[k]))
         elif _log_mode == 'profile':
             out.start('Running subprocess %s' % self.__cmd[0])
             self.__starttime = datetime.datetime.now()

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2008-04-12 15:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-12 15:47 [StGit PATCH 0/2] Fix stg breakage with nweer gits Karl Hasselström
2008-04-12 15:47 ` [StGit PATCH 1/2] Don't both change directory and set GIT_WORK_TREE Karl Hasselström
2008-04-12 15:47 ` [StGit PATCH 2/2] Log environment and cwd as well as the actual command Karl Hasselström

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).