forked from git/git
-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
This fixes a minor memory leak (detected by LeakSanitizer) in git merge #1577
Open
kevinbackhouse
wants to merge
2
commits into
gitgitgadget:master
Choose a base branch
from
kevinbackhouse:free-merge-bases
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/sh | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On the Git mailing list, Junio C Hamano wrote (reply to this): "Kevin Backhouse via GitGitGadget" <gitgitgadget@gmail.com> writes:
> Subject: Re: [PATCH v2 1/2] Regression test for https://github.com/gitgitgadget/git/pull/1577
We try to come up with titles that are helpful to readers when seen
in "git shortlog --since=6.months --no-merges", and the above does
not exactly it.
> From: Kevin Backhouse <kevinbackhouse@github.com>
>
> Signed-off-by: Kevin Backhouse <kevinbackhouse@github.com>
> ---
> t/t9904-merge-leak.sh | 40 ++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 40 insertions(+)
> create mode 100755 t/t9904-merge-leak.sh
>
> diff --git a/t/t9904-merge-leak.sh b/t/t9904-merge-leak.sh
> new file mode 100755
> index 00000000000..09a4474fd73
> --- /dev/null
> +++ b/t/t9904-merge-leak.sh
> @@ -0,0 +1,40 @@
> +#!/bin/sh
> +#
> +
> +test_description='regression test for memory leak in git merge'
> +
> +GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
> +export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
> +
> +. ./lib-bash.sh
> +
> +# test-lib.sh disables LeakSanitizer by default, but we want it enabled
> +# for this test
> +ASAN_OPTIONS=
> +export ASAN_OPTIONS
You do not want to do this.
We have CI jobs that run everybody under asan, ubsan etc., so it is
sufficient and much more preferrable to just add a reproduction
recipe to an _existing_ test that is about "git merge" (or if we
have "ort" specific one, "git merge -s ort"). Of course they would
not fail in jobs that do not enable asan, and that is expected and
perfectly OK.
Also, please check Documentation/CodingGuidelines for shell style
issues.
> +. "$GIT_BUILD_DIR/contrib/completion/git-prompt.sh"
Is this about testing prompts, or does the bug/leak appear only when
the prompt support is in use? Could you explain why this is needed?
> +test_expect_success 'Merge fails due to local changes' '
> + git init &&
> + echo x > x.txt &&
> + git add . &&
> + git commit -m "WIP" &&
> + git checkout -b dev &&
> + echo y > x.txt &&
> + git add . &&
> + git commit -m "WIP" &&
> + git checkout main &&
> + echo z > x.txt &&
> + git add . &&
> + git commit -m "WIP" &&
> + echo a > x.txt &&
> + git add . &&
> + echo "error: ''Your local changes to the following files would be overwritten by merge:''" >expected &&
> + echo " x.txt" >>expected &&
> + echo "Merge with strategy ort failed." >>expected &&
> + test_must_fail git merge -s ort dev 2>actual &&
> + test_cmp expected actual
> +'
If this 1/2 adds a new test that is expected to fail without leak
fix, which has to wait until 2/2, it breaks the bisection. In this
case, since it will be a simple addition to an existing test script,
having both tests and code changes in a single patch is the most
appropriate.
Thank you for working on this.
> +
> +test_done |
||
# | ||
|
||
test_description='regression test for memory leak in git merge' | ||
|
||
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main | ||
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME | ||
|
||
. ./lib-bash.sh | ||
|
||
# test-lib.sh disables LeakSanitizer by default, but we want it enabled | ||
# for this test | ||
ASAN_OPTIONS= | ||
export ASAN_OPTIONS | ||
|
||
. "$GIT_BUILD_DIR/contrib/completion/git-prompt.sh" | ||
|
||
test_expect_success 'Merge fails due to local changes' ' | ||
git init && | ||
echo x > x.txt && | ||
git add . && | ||
git commit -m "WIP" && | ||
git checkout -b dev && | ||
echo y > x.txt && | ||
git add . && | ||
git commit -m "WIP" && | ||
git checkout main && | ||
echo z > x.txt && | ||
git add . && | ||
git commit -m "WIP" && | ||
echo a > x.txt && | ||
git add . && | ||
echo "error: ''Your local changes to the following files would be overwritten by merge:''" >expected && | ||
echo " x.txt" >>expected && | ||
echo "Merge with strategy ort failed." >>expected && | ||
test_must_fail git merge -s ort dev 2>actual && | ||
test_cmp expected actual | ||
' | ||
|
||
test_done |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On the Git mailing list, Junio C Hamano wrote (reply to this):