[PATCH 1 of 4] scmutil: add function to help handling workingctx in arithmetic operation

Yuya Nishihara yuya at tcha.org
Thu Apr 2 13:35:56 UTC 2015


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1426329539 -32400
#      Sat Mar 14 19:38:59 2015 +0900
# Node ID ab6b3165b3f0afc274311ab8c6070a3c81ac35ec
# Parent  37a2b446985f2ef77b9690a0548c8630828b7412
scmutil: add function to help handling workingctx in arithmetic operation

It's unfortunate that workingctx revision is None, which doesn't work well in
arithmetic operation or comparison. This function is trivial but will be used
in several places.

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -582,6 +582,13 @@ def rcpath():
             _rcpath = osrcpath()
     return _rcpath
 
+def intrev(repo, rev):
+    """Return integer for a given revision that can be used in comparison or
+    arithmetic operation"""
+    if rev is None:
+        return len(repo)
+    return rev
+
 def revsingle(repo, revspec, default='.'):
     if not revspec and revspec != 0:
         return repo[default]


More information about the Mercurial-devel mailing list