diff options
author | zeripath <art27@cantab.net> | 2023-01-28 15:54:40 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-28 15:54:40 +0000 |
commit | 78e6b21c1a4c9867dd3054d6c167cc80407b020d (patch) | |
tree | c4c3d0bd55d7269ed0f625cb992d0fafbe43beda /modules/util | |
parent | e9cd18b5578cdf84264f3d69a5f166a33d74b4e3 (diff) | |
download | gitea-78e6b21c1a4c9867dd3054d6c167cc80407b020d.tar.gz gitea-78e6b21c1a4c9867dd3054d6c167cc80407b020d.zip |
Improve checkIfPRContentChanged (#22611)
The code for checking if a commit has caused a change in a PR is
extremely inefficient and affects the head repository instead of using a
temporary repository.
This PR therefore makes several significant improvements:
* A temporary repo like that used in merging.
* The diff code is then significant improved to use a three-way diff
instead of comparing diffs (possibly binary) line-by-line - in memory...
Ref #22578
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules/util')
-rw-r--r-- | modules/util/io.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/modules/util/io.go b/modules/util/io.go index e5d7561bef..69b1d63145 100644 --- a/modules/util/io.go +++ b/modules/util/io.go @@ -4,6 +4,7 @@ package util import ( + "errors" "io" ) @@ -17,3 +18,24 @@ func ReadAtMost(r io.Reader, buf []byte) (n int, err error) { } return n, err } + +// ErrNotEmpty is an error reported when there is a non-empty reader +var ErrNotEmpty = errors.New("not-empty") + +// IsEmptyReader reads a reader and ensures it is empty +func IsEmptyReader(r io.Reader) (err error) { + var buf [1]byte + + for { + n, err := r.Read(buf[:]) + if err != nil { + if err == io.EOF { + return nil + } + return err + } + if n > 0 { + return ErrNotEmpty + } + } +} |