changeset 34889:554885e10868

amend: error out if the note is greater than 255bytes In obsmarker we can't store keys and values of more than 255 bytes in metadata. If we try to do so, ProgrammingError is raised. The note flag to amend stores the note in obsmetadata. If a user will try to store a larger note, he will encounter ProgrammingError which is wrong. We must error out early. Thanks to Yuya for warning about this. Differential Revision: https://phab.mercurial-scm.org/D1179
author Pulkit Goyal <7895pulkit@gmail.com>
date Thu, 19 Oct 2017 03:20:47 +0530
parents 317566f0c2e6
children effae88bccdb
files hgext/amend.py tests/test-amend.t
diffstat 2 files changed, 6 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/amend.py	Wed Oct 18 15:05:03 2017 -0700
+++ b/hgext/amend.py	Thu Oct 19 03:20:47 2017 +0530
@@ -16,6 +16,7 @@
 from mercurial import (
     cmdutil,
     commands,
+    error,
     registrar,
 )
 
@@ -45,6 +46,8 @@
 
     See :hg:`help commit` for more details.
     """
+    if len(opts['note']) > 255:
+        raise error.Abort(_("cannot store a note of more than 255 bytes"))
     with repo.wlock(), repo.lock():
         if not opts.get('logfile'):
             opts['message'] = opts.get('message') or repo['.'].description()
--- a/tests/test-amend.t	Wed Oct 18 15:05:03 2017 -0700
+++ b/tests/test-amend.t	Thu Oct 19 03:20:47 2017 +0530
@@ -198,6 +198,9 @@
 
   $ echo foo > bar
   $ hg add bar
+  $ hg amend --note 'yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy'
+  abort: cannot store a note of more than 255 bytes
+  [255]
   $ hg amend --note "adding bar"
   $ hg debugobsolete -r .
   112478962961147124edd43549aedd1a335e44bf be169c7e8dbe21cd10b3d79691cbe7f241e3c21c 0 (Thu Jan 01 00:00:00 1970 +0000) {'operation': 'amend', 'user': 'test'}