Patchwork [5,of,6,V2] subrepo: do not push mercurial subrepos whose store is clean

login
register
mail settings
Submitter Angel Ezquerra
Date March 9, 2013, 12:12 a.m.
Message ID <8ca082e2fe72e43786c3.1362787958@Angel-PC.localdomain>
Download mbox | patch
Permalink /patch/1091/
State Accepted
Commit 798bdb7f15171f0fb10675ccb56536382e58671c
Headers show

Comments

Angel Ezquerra - March 9, 2013, 12:12 a.m.
# HG changeset patch
# User Angel Ezquerra <angel.ezquerra@gmail.com>
# Date 1360974100 -3600
#      Sat Feb 16 01:21:40 2013 +0100
# Node ID 8ca082e2fe72e43786c329ab9a855310e81acc18
# Parent  c363610c5a98db8167102cde019fdca4966e7c02
subrepo: do not push mercurial subrepos whose store is clean

This patch stops mercurial from pushing unmodified subrepos. An unmodified
subrepo is one whose store is "clean" versus a given target subrepo.

Note that subrepos may have a clean store versus a target repo but not versus another. This patch handles this scenario by individually keeping track of the state of the store versus all push targets.

Tests will be added on the following revision.

Patch

diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -14,10 +14,19 @@ 
 
 nullstate = ('', '', 'empty')
 
+def _expandedabspath(path):
+    '''
+    get a path or url and if it is a path expand it and return an absolute path
+    '''
+    expandedpath = util.urllocalpath(util.expandpath(path))
+    u = util.url(expandedpath)
+    if not u.scheme:
+        path = util.normpath(os.path.abspath(u.path))
+    return path
 
 def _getstorehashcachename(remotepath):
     '''get a unique filename for the store hash cache of a remote repository'''
-    return util.sha1(remotepath).hexdigest()[0:12]
+    return util.sha1(_expandedabspath(remotepath)).hexdigest()[0:12]
 
 def _calcfilehash(filename):
     data = ''
@@ -475,10 +484,10 @@ 
         require a push to a given remote path.'''
         # sort the files that will be hashed in increasing (likely) file size
         filelist = ('bookmarks', 'store/phaseroots', 'store/00changelog.i')
-        yield '# %s\n' % remotepath
+        yield '# %s\n' % _expandedabspath(remotepath)
         for relname in filelist:
             absname = os.path.normpath(self._repo.join(relname))
-            yield '%s = %s\n' % (absname, _calcfilehash(absname))
+            yield '%s = %s\n' % (relname, _calcfilehash(absname))
 
     def _getstorehashcachepath(self, remotepath):
         '''get a unique path for the store hash cache'''
@@ -690,6 +699,12 @@ 
                 return False
 
         dsturl = _abssource(self._repo, True)
+        if not force:
+            if self.storeclean(dsturl):
+                self._repo.ui.status(
+                    _('no changes made to subrepo %s since last push to %s\n')
+                    % (subrelpath(self), dsturl))
+                return None
         self._repo.ui.status(_('pushing subrepo %s to %s\n') %
             (subrelpath(self), dsturl))
         other = hg.peer(self._repo, {'ssh': ssh}, dsturl)