Patchwork D8033: copy: move argument validation a little earlier

login
register
mail settings
Submitter phabricator
Date Jan. 28, 2020, 11:53 p.m.
Message ID <differential-rev-PHID-DREV-swkvxyjm2ublcrfi5oqq-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/44719/
State Superseded
Headers show

Comments

phabricator - Jan. 28, 2020, 11:53 p.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Argument validation is usually done early and I will want it done
  before some code that I'm about to add.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/cmdutil.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel
phabricator - Feb. 7, 2020, 8:49 p.m.
marmoute added a comment.
marmoute accepted this revision.


  This looks like a cleanup we can take anyway.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8033/new/

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

To: martinvonz, #hg-reviewers, marmoute
Cc: marmoute, mercurial-devel
phabricator - Feb. 12, 2020, 7:44 p.m.
This revision is now accepted and ready to land.
durin42 added a comment.
durin42 accepted this revision.


  Oddly, this had some rejects (I didn't look why) but i"d be happy to see this earlier in the series.

REPOSITORY
  rHG Mercurial

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8033/new/

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

To: martinvonz, #hg-reviewers, marmoute, durin42
Cc: durin42, marmoute, mercurial-devel
phabricator - Feb. 12, 2020, 10:27 p.m.
martinvonz added a comment.


  In D8033#120581 <https://phab.mercurial-scm.org/D8033#120581>, @durin42 wrote:
  
  > Oddly, this had some rejects (I didn't look why) but i"d be happy to see this earlier in the series.
  
  I moved some revisions around, but it wasn't trivial to move this one. I don't mind waiting until the parents are accepted anyway.

REPOSITORY
  rHG Mercurial

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8033/new/

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

To: martinvonz, #hg-reviewers, marmoute, durin42
Cc: durin42, marmoute, mercurial-devel

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1421,6 +1421,13 @@ 
     ctx = repo[None]
     pctx = ctx.p1()
 
+    pats = scmutil.expandpats(pats)
+    if not pats:
+        raise error.Abort(_(b'no source or destination specified'))
+    if len(pats) == 1:
+        raise error.Abort(_(b'no destination specified'))
+    dest = pats.pop()
+
     uipathfn = scmutil.getuipathfn(repo, legacyrelativevalue=True)
 
     def walkpat(pat):
@@ -1658,12 +1665,6 @@ 
                     res = lambda p: dest
         return res
 
-    pats = scmutil.expandpats(pats)
-    if not pats:
-        raise error.Abort(_(b'no source or destination specified'))
-    if len(pats) == 1:
-        raise error.Abort(_(b'no destination specified'))
-    dest = pats.pop()
     destdirexists = os.path.isdir(dest) and not os.path.islink(dest)
     if not destdirexists:
         if len(pats) > 1 or matchmod.patkind(pats[0]):