[PATCH 4 of 4] subrepo: use low-level git-diff-index for dirty()

Eric Eisner ede at MIT.EDU
Tue Dec 14 21:07:27 CST 2010


# HG changeset patch
# User Eric Eisner <ede at mit.edu>
# Date 1292381893 18000
# Node ID d7097778f8f05ade484158220fb0233bea4ca2e2
# Parent  2fe9343bf03801cdb3c3f272f133263f7f23da00
subrepo: use low-level git-diff-index for dirty()

Despite its name, git-diff-index compares a revision to the files in the
working directory. This seems way less sketchy and more future proof than
parsing human-readable git-status.

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -710,9 +710,8 @@ class gitsubrepo(abstractsubrepo):
         if self._state[1] != self._gitstate(): # version checked out changed?
             return True
         # check for staged changes or modified files; ignore untracked files
-        status = self._gitcommand(['status'])
-        return ('\n# Changed but not updated:' in status or
-                '\n# Changes to be committed:' in status)
+        out, code = self._gitdir(['diff-index', '--quiet', 'HEAD'])
+        return code == 1
 
     def get(self, state):
         source, revision, kind = state


More information about the Mercurial-devel mailing list