Patchwork [05,of,10,shelve-ext] shelve: add a function to check whether obs-based shelve is enabled

login
register
mail settings
Submitter Kostia Balytskyi
Date Nov. 29, 2016, 3:22 p.m.
Message ID <7f225df4c58b4f62a788.1480432979@dev1902.lla1.facebook.com>
Download mbox | patch
Permalink /patch/17789/
State Accepted
Headers show

Comments

Kostia Balytskyi - Nov. 29, 2016, 3:22 p.m.
# HG changeset patch
# User Kostia Balytskyi <ikostia@fb.com>
# Date 1480426659 28800
#      Tue Nov 29 05:37:39 2016 -0800
# Node ID 7f225df4c58b4f62a7883f95349cdb9e9c86e15e
# Parent  4166a4cfdc14629e169f12e83607b065887594b7
shelve: add a function to check whether obs-based shelve is enabled

A central place to check whether code should use traditional or
obsolescense-based shelve behavior.

Patch

diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -41,6 +41,7 @@  from mercurial import (
     mdiff,
     merge,
     node as nodemod,
+    obsolete,
     patch,
     phases,
     repair,
@@ -71,6 +72,18 @@  patchextension = 'patch'
 # generic user for all shelve operations
 shelveuser = 'shelve@localhost'
 
+def isobsshelve(repo, ui):
+    """Check whether obsolescense-based shelve is enabled"""
+    obsshelve = ui.configbool('experimental', 'obsshelve')
+    if not obsshelve:
+        return False
+    if not obsolete.isenabled(repo, obsolete.createmarkersopt):
+        w = _('ignoring experimental.obsshelve because createmarkers option '
+              'is disabled')
+        ui.warn(w)
+        return False
+    return True
+
 class shelvedfile(object):
     """Helper for the file storing a single shelve