From patchwork Fri May 31 17:19:47 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [5,of,8] revlog: add revlog.empty() From: Durham Goode X-Patchwork-Id: 1688 Message-Id: <37611b85f4af013a0e66.1370020787@dev350.prn1.facebook.com> To: mercurial-devel@selenic.com Date: Fri, 31 May 2013 10:19:47 -0700 # HG changeset patch # User Durham Goode # Date 1369964836 25200 # Thu May 30 18:47:16 2013 -0700 # Node ID 37611b85f4af013a0e66aad75e8578cdf3247c79 # Parent 036972b09c16295c000847ba359193858e7b3a4d revlog: add revlog.empty() A few places in the code use 'if not len(revlog)' to check if the revlog exists. This adds an explicit method for that so alternative revlog implementations can answer that question without having to implement __len__. Updates two locations to use the new function. 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 filerevlog.empty(): 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 filelog.empty(): # A zero count may be a directory or deleted file, so # try to find matching entries on the slow path. if follow: diff --git a/mercurial/revlog.py b/mercurial/revlog.py --- a/mercurial/revlog.py +++ b/mercurial/revlog.py @@ -261,6 +261,8 @@ return self.node(len(self.index) - 2) def __len__(self): return len(self.index) - 1 + def empty(self): + return len(self) == 0 def __iter__(self): return iter(xrange(len(self))) def revs(self, start=0, stop=None):