Patchwork [1,of,4,V2] filelog: switch 'not len(filerevlog)' to 'not filerevlog'

login
register
mail settings
Submitter Durham Goode
Date June 4, 2013, 7:59 p.m.
Message ID <c74c942b6f1a8cfb4a47.1370375967@dev350.prn1.facebook.com>
Download mbox | patch
Permalink /patch/1697/
State Accepted
Commit 446ab88d3f1c55f7c33e965a2cd598787d2476a4
Headers show

Comments

Durham Goode - June 4, 2013, 7:59 p.m.
# HG changeset patch
# User Durham Goode <durham@fb.com>
# Date 1369964836 25200
#      Thu May 30 18:47:16 2013 -0700
# Node ID c74c942b6f1a8cfb4a47a9767e0ea41b93a0656d
# Parent  843cf14e70bfde062911b9b5f91117a598690805
filelog: switch 'not len(filerevlog)' to 'not filerevlog'

A few places in the code use 'if not len(revlog)' to check if the revlog
exists. Replacing this with 'not filerevlog' allows alternative revlog
implementations to override __nonzero__ to handle this case without
implementing __len__.

Patch

diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -359,7 +359,7 @@ 
         msgfiles = _('files')
         for i, fname in enumerate(sorted(changedfiles)):
             filerevlog = repo.file(fname)
-            if not len(filerevlog):
+            if not filerevlog:
                 raise util.Abort(_("empty or missing revlog for %s") % fname)
 
             if fastpathlinkrev:
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1320,7 +1320,7 @@ 
                 raise util.Abort(_('cannot follow file not in parent '
                                    'revision: "%s"') % f)
             filelog = repo.file(f)
-            if not len(filelog):
+            if not filelog:
                 # A zero count may be a directory or deleted file, so
                 # try to find matching entries on the slow path.
                 if follow: