mirror of
https://github.com/facebook/sapling.git
synced 2024-12-26 14:34:34 +03:00
localrepo: add configurable limits for description and extras
Summary: Commit messages and extras can be unbounded in size. This can cause problems if users create commits with exceptionally large messages or extras. Mercurial will commit these to the changelog, increasing its size. On Mononoke, large commit messages may go over the cacheing threshold, resulting in poor performance for requests involving these commits as Mononoke will need to reload on every access. Commit messages should not usually be that large. Mostly likely it will happen by accident, e.g. through use of `hg commit -l some-large-file`. Prevent this from happening by accident by adding configuration for soft limits when creating commits. If a user really does need to create a commit with a very large message or extras, they can override using the config option. Reviewed By: xavierd Differential Revision: D19942522 fbshipit-source-id: 09b9fe1f470467237acc1b20286d2b1d2ab25613
This commit is contained in:
parent
fc1323019f
commit
0387f1c67e
@ -163,6 +163,8 @@ coreconfigitem(
|
||||
alias=[("experimental", "updatecheck")],
|
||||
)
|
||||
coreconfigitem("commands", "update.requiredest", default=False)
|
||||
coreconfigitem("commit", "description-size-limit", default=None)
|
||||
coreconfigitem("commit", "extras-size-limit", default=None)
|
||||
coreconfigitem("committemplate", ".*", default=None, generic=True)
|
||||
coreconfigitem("connectionpool", "lifetime", default=None)
|
||||
coreconfigitem("convert", "git.committeractions", default=lambda: ["messagedifferent"])
|
||||
|
@ -692,6 +692,19 @@ effect and style see :hg:`help color`.
|
||||
will be disallowed.
|
||||
(default: False)
|
||||
|
||||
``commit``
|
||||
----------
|
||||
|
||||
``description-size-limit``
|
||||
Maximum length (in bytes) of the description for new commits. Set this
|
||||
to a reasonable value to prevent accidentally creating commits with
|
||||
very large commit messages.
|
||||
|
||||
``extras-size-limit``
|
||||
Maximum total size (in bytes) of the commit extras for new commits.
|
||||
Set this to a reasonable value to prevent accidentally creating commits
|
||||
with very large metadata.
|
||||
|
||||
``committemplate``
|
||||
------------------
|
||||
|
||||
|
@ -2226,6 +2226,24 @@ class localrepository(object):
|
||||
p1, p2 = ctx.p1(), ctx.p2()
|
||||
user = ctx.user()
|
||||
|
||||
descriptionlimit = self.ui.configbytes("commit", "description-size-limit")
|
||||
if descriptionlimit:
|
||||
descriptionlen = len(ctx.description())
|
||||
if descriptionlen > descriptionlimit:
|
||||
raise errormod.Abort(
|
||||
_("commit message length (%s) exceeds configured limit (%s)")
|
||||
% (descriptionlen, descriptionlimit)
|
||||
)
|
||||
|
||||
extraslimit = self.ui.configbytes("commit", "extras-size-limit")
|
||||
if extraslimit:
|
||||
extraslen = sum(len(k) + len(v) for k, v in pycompat.iteritems(ctx.extra()))
|
||||
if extraslen > extraslimit:
|
||||
raise errormod.Abort(
|
||||
_("commit extras total size (%s) exceeds configured limit (%s)")
|
||||
% (extraslen, extraslimit)
|
||||
)
|
||||
|
||||
lock = self.lock()
|
||||
try:
|
||||
tr = self.transaction("commit")
|
||||
|
20
eden/scm/tests/test-commit-size-limits.t
Normal file
20
eden/scm/tests/test-commit-size-limits.t
Normal file
@ -0,0 +1,20 @@
|
||||
$ enable commitextras
|
||||
$ newrepo
|
||||
$ echo data > file
|
||||
$ hg add file
|
||||
|
||||
Test commit message limit
|
||||
$ hg commit -m "long message" --config commit.description-size-limit=11
|
||||
abort: commit message length (12) exceeds configured limit (11)
|
||||
[255]
|
||||
$ hg commit -m "long message" --config commit.description-size-limit=12
|
||||
|
||||
$ echo data >> file
|
||||
|
||||
Test extras limit (limit includes 13 bytes for "branch=default")
|
||||
$ hg commit -m "message" --extra "testextra=long value" \
|
||||
> --config commit.extras-size-limit=31
|
||||
abort: commit extras total size (32) exceeds configured limit (31)
|
||||
[255]
|
||||
$ hg commit -m "message" --extra "testextra=long value" \
|
||||
> --config commit.extras-size-limit=32
|
Loading…
Reference in New Issue
Block a user