Patchwork [6,of,8,RFC] annotate: abort early if no file is specified

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 19, 2014, 10:56 p.m.
Message ID <5b82336b237f8f45a01f.1408488980@mimosa>
Download mbox | patch
Permalink /patch/5529/
State Accepted
Commit 711de9dcb1d37f639ceb36ef4dd7d366df3da20a
Headers show

Comments

Yuya Nishihara - Aug. 19, 2014, 10:56 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1408179566 -32400
#      Sat Aug 16 17:59:26 2014 +0900
# Node ID 5b82336b237f8f45a01f31d4d0788464a1198843
# Parent  5358071e65be2fd330b45d5989198101ae6b01d6
annotate: abort early if no file is specified

This change is intended to move getdate function near opmap table.
Pierre-Yves David - Aug. 21, 2014, 4:37 p.m.
On 08/19/2014 03:56 PM, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1408179566 -32400
> #      Sat Aug 16 17:59:26 2014 +0900
> # Node ID 5b82336b237f8f45a01f31d4d0788464a1198843
> # Parent  5358071e65be2fd330b45d5989198101ae6b01d6
> annotate: abort early if no file is specified

I pushed this was as it seemed a bit unrelated. (and failing early seems 
a good idea in general)

(queued)

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -260,6 +260,9 @@  def annotate(ui, repo, *pats, **opts):
 
     Returns 0 on success.
     """
+    if not pats:
+        raise util.Abort(_('at least one filename or pattern is required'))
+
     if opts.get('follow'):
         # --follow is deprecated and now just an alias for -f/--file
         # to mimic the behavior of Mercurial before version 1.5
@@ -267,10 +270,6 @@  def annotate(ui, repo, *pats, **opts):
 
     datefunc = ui.quiet and util.shortdate or util.datestr
     getdate = util.cachefunc(lambda x: datefunc(x[0].date()))
-
-    if not pats:
-        raise util.Abort(_('at least one filename or pattern is required'))
-
     hexfn = ui.debugflag and hex or short
 
     opmap = [('user', ' ', lambda x: ui.shortuser(x[0].user())),