cmdrewrite: add a utility function to make sure note is of valid format
authorPulkit Goyal <7895pulkit@gmail.com>
Sun, 12 Nov 2017 01:26:30 +0530
changeset 3213 7bc587557e4f
parent 3212 6ffd0c36ccc1
child 3214 9fe2b3fd7fc7
cmdrewrite: add a utility function to make sure note is of valid format Upcoming patches will add support to store a note on various evolution related commands by storing that in obsmarker. Since the obsmarker metadata field can't store things above 255 bytes, this patch introduces a function which will be used to make sure note is under 255 bytes and does not contain newlines. We don't want notes to be multilines.
hgext3rd/evolve/cmdrewrite.py
--- a/hgext3rd/evolve/cmdrewrite.py	Thu Nov 30 12:14:36 2017 -0500
+++ b/hgext3rd/evolve/cmdrewrite.py	Sun Nov 12 01:26:30 2017 +0530
@@ -49,6 +49,18 @@
 
 # option added by evolve
 
+def _checknotesize(opts):
+    """ make sure note is of valid format """
+
+    note = opts.get('note')
+    if not note:
+        return
+
+    if len(note) > 255:
+        raise error.Abort(_("cannot store a note of more than 255 bytes"))
+    if '\n' in note:
+        raise error.Abort(_("note cannot contain a newline"))
+
 def _resolveoptions(ui, opts):
     """modify commit options dict to handle related options