Skip to content

Commit

Permalink
localrepo: add configurable limits for files count in a commit
Browse files Browse the repository at this point in the history
Summary: Currently, commit can have unbounded number of files. This can cause problems if users (including bot) create commits with exceptionally large number of files.

Reviewed By: muirdm

Differential Revision: D51647160

fbshipit-source-id: 3fc91a7f09c9588be404a650f1424993b99dd30d
  • Loading branch information
zzl0 authored and facebook-github-bot committed Nov 29, 2023
1 parent 56ec1cd commit 454b41b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions eden/scm/sapling/localrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2782,6 +2782,13 @@ def commitctx(self, ctx, error=False):
% (extraslen, extraslimit)
)

file_count_limit = self.ui.configint("commit", "file-count-limit")
if file_count_limit and file_count_limit < len(ctx.files()):
raise errormod.Abort(
_("commit file count (%d) exceeds configured limit (%d)")
% (len(ctx.files()), file_count_limit)
)

isgit = git.isgitformat(self)
lock = self.lock()
try:
Expand Down
17 changes: 17 additions & 0 deletions eden/scm/tests/test-commit-files-count-limits.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#debugruntest-compatible
$ eagerepo
$ newrepo

$ echo 1 > foo
$ echo 2 > bar
$ hg add . -q

Commit should fail if the number of changed files exceeds the limit
$ hg commit -m init --config commit.file-count-limit=1
abort: commit file count (2) exceeds configured limit (1)
[255]

Commit should succeed if the number of changed files <= the limit
$ hg commit -m init --config commit.file-count-limit=2
$ hg log -G -T '{desc}'
@ init

0 comments on commit 454b41b

Please sign in to comment.