diff hgext/censor.py @ 25806:5e18f6e39006

censor: make various path forms available like other Mercurial commands Before this patch, censored file should be exactly "a path relative to repository root" regardless of current working directory, because "hg censor" passes "path" to "repo.file()" directly without any preparations. To make various path forms available like other Mercurial commands, this patch gets a target file path in the way of "hg parents FILE". Getting "wctx" is relocated to reuse "wctx" for efficiency.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Fri, 17 Jul 2015 00:22:16 +0900
parents 328739ea70c3
children 56b2bcea2529
line wrap: on
line diff
--- a/hgext/censor.py	Tue Jul 14 14:40:56 2015 +0100
+++ b/hgext/censor.py	Fri Jul 17 00:22:16 2015 +0900
@@ -47,6 +47,12 @@
     if not rev:
         raise util.Abort(_('must specify revision to censor'))
 
+    wctx = repo[None]
+
+    m = scmutil.match(wctx, (path,))
+    if m.anypats() or len(m.files()) != 1:
+        raise util.Abort(_('can only specify an explicit filename'))
+    path = m.files()[0]
     flog = repo.file(path)
     if not len(flog):
         raise util.Abort(_('cannot censor file with no history'))
@@ -70,7 +76,6 @@
         raise util.Abort(_('cannot censor file in heads (%s)') % headlist,
             hint=_('clean/delete and commit first'))
 
-    wctx = repo[None]
     wp = wctx.parents()
     if ctx.node() in [p.node() for p in wp]:
         raise util.Abort(_('cannot censor working directory'),