D5745: status: extract helper for producing relative or absolute path for UI

martinvonz (Martin von Zweigbergk) phabricator at mercurial-scm.org
Thu Jan 31 16:27:32 EST 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG1d6eae696cf1: status: extract helper for producing relative or absolute path for UI (authored by martinvonz, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5745?vs=13574&id=13649

REVISION DETAIL
  https://phab.mercurial-scm.org/D5745

AFFECTED FILES
  mercurial/commands.py
  mercurial/scmutil.py

CHANGE DETAILS

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -725,6 +725,14 @@
         return []
     return parents
 
+def getuipathfn(repo, relative):
+    if relative:
+        cwd = repo.getcwd()
+        pathto = repo.pathto
+        return lambda f: pathto(f, cwd)
+    else:
+        return lambda f: f
+
 def expandpats(pats):
     '''Expand bare globs when running on windows.
     On posix we assume it already has already been done by sh.'''
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5414,10 +5414,8 @@
         repo = scmutil.unhidehashlikerevs(repo, revs, 'nowarn')
         ctx1, ctx2 = scmutil.revpair(repo, revs)
 
-    if pats or ui.configbool('commands', 'status.relative'):
-        cwd = repo.getcwd()
-    else:
-        cwd = ''
+    relative = pats or ui.configbool('commands', 'status.relative'):
+    uipathfn = scmutil.getuipathfn(repo, relative)
 
     if opts.get('print0'):
         end = '\0'
@@ -5468,10 +5466,10 @@
                 fm.context(ctx=ctx2)
                 fm.data(path=f)
                 fm.condwrite(showchar, 'status', '%s ', char, label=label)
-                fm.plain(fmt % repo.pathto(f, cwd), label=label)
+                fm.plain(fmt % uipathfn(f), label=label)
                 if f in copy:
                     fm.data(source=copy[f])
-                    fm.plain(('  %s' + end) % repo.pathto(copy[f], cwd),
+                    fm.plain(('  %s' + end) % uipathfn(copy[f]),
                              label='status.copied')
 
     if ((ui.verbose or ui.configbool('commands', 'status.verbose'))



To: martinvonz, #hg-reviewers, pulkit
Cc: mercurial-devel


More information about the Mercurial-devel mailing list