changeset 27651:07fc2f2134ba

origpath: move from cmdutil to scmutil This is a lower-level function so it doesn't need to be in cmdutil, and putting it here avoids a bunch of potential import cycle issues.
author Siddharth Agarwal <sid0@fb.com>
date Sat, 02 Jan 2016 03:02:57 -0800
parents e7222d326ea2
children cc91f3bc5461
files hgext/largefiles/lfcommands.py hgext/mq.py hgext/shelve.py mercurial/cmdutil.py mercurial/commands.py mercurial/filemerge.py mercurial/scmutil.py mercurial/subrepo.py
diffstat 8 files changed, 32 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/largefiles/lfcommands.py	Sun Nov 22 17:57:35 2015 -0800
+++ b/hgext/largefiles/lfcommands.py	Sat Jan 02 03:02:57 2016 -0800
@@ -444,9 +444,9 @@
         updated, removed = 0, 0
         for lfile in lfiles:
             abslfile = repo.wjoin(lfile)
-            abslfileorig = cmdutil.origpath(ui, repo, abslfile)
+            abslfileorig = scmutil.origpath(ui, repo, abslfile)
             absstandin = repo.wjoin(lfutil.standin(lfile))
-            absstandinorig = cmdutil.origpath(ui, repo, absstandin)
+            absstandinorig = scmutil.origpath(ui, repo, absstandin)
             if os.path.exists(absstandin):
                 if (os.path.exists(absstandinorig) and
                     os.path.exists(abslfile)):
--- a/hgext/mq.py	Sun Nov 22 17:57:35 2015 -0800
+++ b/hgext/mq.py	Sat Jan 02 03:02:57 2016 -0800
@@ -700,9 +700,9 @@
             absf = repo.wjoin(f)
             if os.path.lexists(absf):
                 self.ui.note(_('saving current version of %s as %s\n') %
-                             (f, cmdutil.origpath(self.ui, repo, f)))
-
-                absorig = cmdutil.origpath(self.ui, repo, absf)
+                             (f, scmutil.origpath(self.ui, repo, f)))
+
+                absorig = scmutil.origpath(self.ui, repo, absf)
                 if copy:
                     util.copyfile(absf, absorig)
                 else:
--- a/hgext/shelve.py	Sun Nov 22 17:57:35 2015 -0800
+++ b/hgext/shelve.py	Sat Jan 02 03:02:57 2016 -0800
@@ -512,7 +512,7 @@
         # revert will overwrite unknown files, so move them out of the way
         for file in repo.status(unknown=True).unknown:
             if file in files:
-                util.rename(file, cmdutil.origpath(ui, repo, file))
+                util.rename(file, scmutil.origpath(ui, repo, file))
         ui.pushbuffer(True)
         cmdutil.revert(ui, repo, shelvectx, repo.dirstate.parents(),
                        *pathtofiles(repo, files),
--- a/mercurial/cmdutil.py	Sun Nov 22 17:57:35 2015 -0800
+++ b/mercurial/cmdutil.py	Sat Jan 02 03:02:57 2016 -0800
@@ -3098,7 +3098,7 @@
                     xlist.append(abs)
                     if dobackup and (backup <= dobackup
                                      or wctx[abs].cmp(ctx[abs])):
-                            bakname = origpath(ui, repo, rel)
+                            bakname = scmutil.origpath(ui, repo, rel)
                             ui.note(_('saving current version of %s as %s\n') %
                                     (rel, bakname))
                             if not opts.get('dry_run'):
@@ -3130,26 +3130,6 @@
     finally:
         wlock.release()
 
-def origpath(ui, repo, filepath):
-    '''customize where .orig files are created
-
-    Fetch user defined path from config file: [ui] origbackuppath = <path>
-    Fall back to default (filepath) if not specified
-    '''
-    origbackuppath = ui.config('ui', 'origbackuppath', None)
-    if origbackuppath is None:
-        return filepath + ".orig"
-
-    filepathfromroot = os.path.relpath(filepath, start=repo.root)
-    fullorigpath = repo.wjoin(origbackuppath, filepathfromroot)
-
-    origbackupdir = repo.vfs.dirname(fullorigpath)
-    if not repo.vfs.exists(origbackupdir):
-        ui.note(_('creating directory: %s\n') % origbackupdir)
-        util.makedirs(origbackupdir)
-
-    return fullorigpath + ".orig"
-
 def _revertprefetch(repo, ctx, *files):
     """Let extension changing the storage layer prefetch content"""
     pass
--- a/mercurial/commands.py	Sun Nov 22 17:57:35 2015 -0800
+++ b/mercurial/commands.py	Sat Jan 02 03:02:57 2016 -0800
@@ -5953,7 +5953,7 @@
                 if complete:
                     try:
                         util.rename(a + ".resolve",
-                                    cmdutil.origpath(ui, repo, a))
+                                    scmutil.origpath(ui, repo, a))
                     except OSError as inst:
                         if inst.errno != errno.ENOENT:
                             raise
@@ -5973,7 +5973,7 @@
             # replace filemerge's .orig file with our resolve file
             a = repo.wjoin(f)
             try:
-                util.rename(a + ".resolve", cmdutil.origpath(ui, repo, a))
+                util.rename(a + ".resolve", scmutil.origpath(ui, repo, a))
             except OSError as inst:
                 if inst.errno != errno.ENOENT:
                     raise
--- a/mercurial/filemerge.py	Sun Nov 22 17:57:35 2015 -0800
+++ b/mercurial/filemerge.py	Sat Jan 02 03:02:57 2016 -0800
@@ -16,9 +16,9 @@
 from .node import nullid, short
 
 from . import (
-    cmdutil,
     error,
     match,
+    scmutil,
     simplemerge,
     tagmerge,
     templatekw,
@@ -608,7 +608,7 @@
     b = temp("base", fca)
     c = temp("other", fco)
     if not fcd.isabsent():
-        back = cmdutil.origpath(ui, repo, a)
+        back = scmutil.origpath(ui, repo, a)
         if premerge:
             util.copyfile(a, back)
     else:
--- a/mercurial/scmutil.py	Sun Nov 22 17:57:35 2015 -0800
+++ b/mercurial/scmutil.py	Sat Jan 02 03:02:57 2016 -0800
@@ -838,6 +838,26 @@
     '''Return a matcher that will efficiently match exactly these files.'''
     return matchmod.exact(repo.root, repo.getcwd(), files, badfn=badfn)
 
+def origpath(ui, repo, filepath):
+    '''customize where .orig files are created
+
+    Fetch user defined path from config file: [ui] origbackuppath = <path>
+    Fall back to default (filepath) if not specified
+    '''
+    origbackuppath = ui.config('ui', 'origbackuppath', None)
+    if origbackuppath is None:
+        return filepath + ".orig"
+
+    filepathfromroot = os.path.relpath(filepath, start=repo.root)
+    fullorigpath = repo.wjoin(origbackuppath, filepathfromroot)
+
+    origbackupdir = repo.vfs.dirname(fullorigpath)
+    if not repo.vfs.exists(origbackupdir):
+        ui.note(_('creating directory: %s\n') % origbackupdir)
+        util.makedirs(origbackupdir)
+
+    return fullorigpath + ".orig"
+
 def addremove(repo, matcher, prefix, opts=None, dry_run=None, similarity=None):
     if opts is None:
         opts = {}
--- a/mercurial/subrepo.py	Sun Nov 22 17:57:35 2015 -0800
+++ b/mercurial/subrepo.py	Sat Jan 02 03:02:57 2016 -0800
@@ -1910,7 +1910,7 @@
             status = self.status(None)
             names = status.modified
             for name in names:
-                bakname = cmdutil.origpath(self.ui, self._subparent, name)
+                bakname = scmutil.origpath(self.ui, self._subparent, name)
                 self.ui.note(_('saving current version of %s as %s\n') %
                         (name, bakname))
                 self.wvfs.rename(name, bakname)