obsnote: warn if user try to store a note in obsmarker on an older hg
authorPulkit Goyal <7895pulkit@gmail.com>
Tue, 12 Dec 2017 00:27:08 +0530
changeset 3283 039c4b8dc3ed
parent 3282 3675fe74521d
child 3284 ee71cc4eff21
obsnote: warn if user try to store a note in obsmarker on an older hg Support to store a note in obsmarker is from hg>=4.4. We have added notes support to all the evolve commands but we do support versions which don't support storing note in obsmarker. Warn if user tries to store a note in older hg.
hgext3rd/evolve/cmdrewrite.py
hgext3rd/evolve/compat.py
--- a/hgext3rd/evolve/cmdrewrite.py	Tue Dec 12 02:16:58 2017 +0100
+++ b/hgext3rd/evolve/cmdrewrite.py	Tue Dec 12 00:27:08 2017 +0530
@@ -49,13 +49,16 @@
 
 # option added by evolve
 
-def _checknotesize(opts):
+def _checknotesize(ui, opts):
     """ make sure note is of valid format """
 
     note = opts.get('note')
     if not note:
         return
 
+    if not compat.isobsnotesupported():
+        ui.warn(_("current hg version does not support storing"
+                  " note in obsmarker\n"))
     if len(note) > 255:
         raise error.Abort(_("cannot store a note of more than 255 bytes"))
     if '\n' in note:
@@ -111,7 +114,7 @@
 
     Returns 0 on success, 1 if nothing changed.
     """
-    _checknotesize(opts)
+    _checknotesize(ui, opts)
     opts = opts.copy()
     if opts.get('extract'):
         return uncommit(ui, repo, *pats, **opts)
@@ -328,7 +331,7 @@
     Return 0 if changed files are uncommitted.
     """
 
-    _checknotesize(opts)
+    _checknotesize(ui, opts)
     _resolveoptions(ui, opts) # process commitopts3
     interactive = opts.get('interactive')
     wlock = lock = tr = None
@@ -539,7 +542,7 @@
 
          hg fold foo::@ --exact
     """
-    _checknotesize(opts)
+    _checknotesize(ui, opts)
     _resolveoptions(ui, opts)
     revs = list(revs)
     revs.extend(opts['rev'])
@@ -652,7 +655,7 @@
        See :hg:`help phases` for more about draft revisions, and
        :hg:`help revsets` for more about the `draft()` and `only()` keywords.
     """
-    _checknotesize(opts)
+    _checknotesize(ui, opts)
     _resolveoptions(ui, opts)
     revs = list(revs)
     revs.extend(opts['rev'])
@@ -805,7 +808,7 @@
     must acknowledge it by passing ``--split``. Similarly, when you prune multiple
     changesets with a single successor, you must pass the ``--fold`` option.
     """
-    _checknotesize(opts)
+    _checknotesize(ui, opts)
     revs = scmutil.revrange(repo, list(revs) + opts.get('rev'))
     succs = opts['new'] + opts['succ']
     bookmarks = set(opts.get('bookmark'))
@@ -965,7 +968,7 @@
 
     Use --rev to split a given changeset instead.
     """
-    _checknotesize(opts)
+    _checknotesize(ui, opts)
     _resolveoptions(ui, opts)
     tr = wlock = lock = None
     newcommits = []
@@ -1063,7 +1066,7 @@
 
     This is used to "resurrect" changesets
     """
-    _checknotesize(opts)
+    _checknotesize(ui, opts)
     duplicate = opts['duplicate']
     allowdivergence = opts['allowdivergence']
     revs = list(revs)
--- a/hgext3rd/evolve/compat.py	Tue Dec 12 02:16:58 2017 +0100
+++ b/hgext3rd/evolve/compat.py	Tue Dec 12 00:27:08 2017 +0530
@@ -97,6 +97,14 @@
             bookmarks[name] = node
     bookmarks.recordchange(tr)
 
+def isobsnotesupported():
+    # hack to know obsnote is supported. The patches for obsnote support was
+    # pushed before the obsfateprinter patches, so this will serve as a good
+    # check
+    if not obsutil:
+        return False
+    return util.safehasattr(obsutil, 'obsfateprinter')
+
 # Evolution renaming compat
 
 TROUBLES = {}