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

login
register
mail settings
Submitter Yuya Nishihara
Date April 2, 2015, 1:35 p.m.
Message ID <ab6b3165b3f0afc27431.1427981756@mimosa>
Download mbox | patch
Permalink /patch/8452/
State Accepted
Headers show

Comments

Yuya Nishihara - April 2, 2015, 1:35 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@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.

Patch

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]