1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-06-03 18:06:10 +02:00
git/builtin
Ævar Arnfjörð Bjarmason e900d494dc diff: add an API for deferred freeing
Add a diff_free() function to free anything we may have allocated in
the "diff_options" struct, and the ability to make calling it a noop
by setting "no_free" in "diff_options".

This is required because when e.g. "git diff" is run we'll allocate
things in that struct, use the diff machinery once, and then exit.

But if we run e.g. "git log -p" we're going to re-use what we
allocated across multiple diff_flush() calls, and only want to free
things at the end.

We've thus ended up with features like the recently added "diff -I"[1]
where we'll leak memory. As it turns out it could have simply used the
pattern established in 6ea57703f6 (log: prepare log/log-tree to reuse
the diffopt.close_file attribute, 2016-06-22).

Manually adding more such flags to things log_tree_commit() every time
we need to allocate something would be tedious. Let's instead move
that fclose() code it to a new diff_free(), in anticipation of freeing
more things in that function in follow-up commits.

Some functions such as log_tree_commit() need an idiom of optionally
retaining a previous "no_free", as they may either free the memory
themselves, or their caller may do so. I'm keeping that idiom in
log_show_early() for good measure, even though I don't think it's
currently called in this manner. It also gets passed an existing
"struct rev_info", so future callers may want to set the "no_free"
flag.

This change is a bit hard to read because while the freeing pattern
we're introducing isn't unusual, the "file" member is a special
snowflake. We usually don't want to fclose() it. This is because
"file" is usually stdout, in which case we don't want to fclose()
it. We only want to opt-in to closing it when we e.g. open a file on
the filesystem. Thus the opt-in "close_file" flag.

So the API in general just needs a "no_free" flag to defer freeing,
but the "file" member still needs its "close_file" flag. This is made
more confusing because while refactoring this code we could replace
some "close_file=0" with "no_free=1", whereas others need to set both
flags.

This is because there were some cases where an existing "close_file=0"
meant "let's defer deallocation", and others where it meant "we don't
want to close this file handle at all".

1. 296d4a94e7 (diff: add -I<regex> that ignores matching changes,
   2020-10-20)

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-02-11 09:21:05 -08:00
..
add.c drop unused argc parameters 2020-09-30 12:53:47 -07:00
am.c builtin/*: update usage format 2021-01-06 15:10:49 -08:00
annotate.c strvec: rename struct fields 2020-07-30 19:18:06 -07:00
apply.c
archive.c
bisect--helper.c Merge branch 'mr/bisect-in-c-3' 2020-11-09 14:06:25 -08:00
blame.c Merge branch 'ab/mailmap' 2021-01-25 14:19:19 -08:00
branch.c Merge branch 'ph/use-delete-refs' 2021-02-05 16:40:45 -08:00
bugreport.c builtin/bugreport.c: use thread-safe localtime_r() 2020-12-01 13:05:37 -08:00
bundle.c Merge branch 'bc/sha-256-part-3' 2020-08-11 18:04:11 -07:00
cat-file.c Merge branch 'cc/cat-file-usage-update' into master 2020-07-09 14:00:41 -07:00
check-attr.c
check-ignore.c dir: fix problematic API to avoid memory leaks 2020-08-18 17:17:31 -07:00
check-mailmap.c shortlog: remove unused(?) "repo-abbrev" feature 2021-01-12 14:04:42 -08:00
check-ref-format.c
checkout-index.c checkout-index: propagate errors to exit code 2020-10-27 12:41:56 -07:00
checkout.c cache-tree: clean up cache_tree_update() 2021-01-23 17:14:07 -08:00
clean.c quote_path: give flags parameter to quote_path() 2020-09-10 10:49:19 -07:00
clone.c Merge branch 'js/init-defaultbranch-advice' 2020-12-18 15:15:17 -08:00
column.c
commit-graph.c builtin/*: update usage format 2021-01-06 15:10:49 -08:00
commit-tree.c Use OPT_CALLBACK and OPT_CALLBACK_F 2020-04-28 10:47:10 -07:00
commit.c shortlog: remove unused(?) "repo-abbrev" feature 2021-01-12 14:04:42 -08:00
config.c config: implement --fixed-value with --get* 2020-11-25 14:43:48 -08:00
count-objects.c
credential-cache--daemon.c make credential helpers builtins 2020-08-13 11:02:08 -07:00
credential-cache.c Merge branch 'jc/undash-in-tree-git-callers' 2020-09-03 12:37:03 -07:00
credential-store.c crendential-store: use timeout when locking file 2020-11-25 12:30:18 -08:00
credential.c credential: load default config 2020-10-16 12:30:45 -07:00
describe.c refs: switch peel_ref() to peel_iterated_oid() 2021-01-21 15:51:31 -08:00
diff-files.c diff-merges: new function diff_merges_set_dense_combined_if_unset() 2020-12-21 13:47:31 -08:00
diff-index.c builtin/diff-index: learn --merge-base 2020-09-20 21:30:26 -07:00
diff-tree.c builtin/diff-tree: learn --merge-base 2020-09-21 13:37:03 -07:00
diff.c Merge branch 'so/log-diff-merge' 2021-02-05 16:40:44 -08:00
difftool.c Use new HASHMAP_INIT macro to simplify hashmap initialization 2020-11-11 12:55:27 -08:00
env--helper.c assert PARSE_OPT_NONEG in parse-options callbacks 2020-09-30 12:53:47 -07:00
fast-export.c builtin/*: update usage format 2021-01-06 15:10:49 -08:00
fast-import.c Merge branch 'jk/fast-import-marks-cleanup' 2020-11-02 13:17:40 -08:00
fetch-pack.c fetch-pack: remove no_dependents code 2020-08-18 16:46:53 -07:00
fetch.c fetch: implement support for atomic reference updates 2021-01-12 12:06:15 -08:00
fmt-merge-msg.c Lib-ify fmt-merge-msg 2020-03-24 15:04:43 -07:00
for-each-ref.c ref-filter: move ref_sorting flags to a bitfield 2021-01-07 15:13:21 -08:00
for-each-repo.c for-each-repo: do nothing on empty config 2021-01-07 19:12:02 -08:00
fsck.c fsck: make fsck_config() re-usable 2021-01-05 14:58:29 -08:00
gc.c Merge branch 'jk/peel-iterated-oid' 2021-02-03 15:04:49 -08:00
get-tar-commit-id.c
grep.c grep/log: remove hidden --debug and --grep-debug options 2021-01-26 11:36:20 -08:00
hash-object.c
help.c help: drop usage of 'common' and 'useful' for guides 2020-08-04 18:34:01 -07:00
index-pack.c object-file.c: rename from sha1-file.c 2021-01-04 13:01:55 -08:00
init-db.c get_default_branch_name(): prepare for showing some advice 2020-12-13 15:53:50 -08:00
interpret-trailers.c Use OPT_CALLBACK and OPT_CALLBACK_F 2020-04-28 10:47:10 -07:00
log.c diff: add an API for deferred freeing 2021-02-11 09:21:05 -08:00
ls-files.c ls-files.c: add --deduplicate option 2021-01-23 11:48:20 -08:00
ls-remote.c Merge branch 'jk/unleak-fixes' 2020-08-24 14:54:30 -07:00
ls-tree.c
mailinfo.c
mailsplit.c
merge-base.c rebase: --fork-point regression fix 2020-02-11 09:59:39 -08:00
merge-file.c
merge-index.c
merge-ours.c
merge-recursive.c
merge-tree.c merge-base, xdiff: zero out xpparam_t structures 2020-10-20 12:53:26 -07:00
merge.c Merge branch 'so/log-diff-merge' 2021-02-05 16:40:44 -08:00
mktag.c mktag: add a --[no-]strict option 2021-01-06 14:22:24 -08:00
mktree.c
multi-pack-index.c
mv.c git-mv: improve error message for conflicted file 2020-07-20 14:35:43 -07:00
name-rev.c oid_pos(): access table through const pointers 2021-01-28 12:03:26 -08:00
notes.c Use OPT_CALLBACK and OPT_CALLBACK_F 2020-04-28 10:47:10 -07:00
pack-objects.c Merge branch 'jv/pack-objects-narrower-ref-iteration' 2021-02-05 16:40:45 -08:00
pack-redundant.c Merge branch 'jc/deprecate-pack-redundant' 2021-01-25 14:19:18 -08:00
pack-refs.c
patch-id.c patch-id: use oid_to_hex() to print multiple object IDs 2019-12-09 12:26:40 -08:00
prune-packed.c Lib-ify prune-packed 2020-03-24 15:04:44 -07:00
prune.c Merge branch 'tb/shallow-cleanup' 2020-05-13 12:19:18 -07:00
pull.c pull: display default warning only when non-ff 2020-12-15 17:39:42 -08:00
push.c Merge branch 'sk/force-if-includes' 2020-10-27 15:09:49 -07:00
range-diff.c strvec: convert builtin/ callers away from argv_array name 2020-07-28 15:02:18 -07:00
read-tree.c Use OPT_CALLBACK and OPT_CALLBACK_F 2020-04-28 10:47:10 -07:00
rebase.c Merge branch 'rs/rebase-commit-validation' 2021-01-15 15:20:29 -08:00
receive-pack.c Merge branch 'js/trace2-session-id' 2020-12-08 15:11:20 -08:00
reflog.c Merge branch 'es/get-worktrees-unsort' 2020-07-06 22:09:15 -07:00
remote-ext.c strvec: convert builtin/ callers away from argv_array name 2020-07-28 15:02:18 -07:00
remote-fd.c
remote.c config: convert multi_replace to flags 2020-11-25 14:43:47 -08:00
repack.c fetch-pack: refactor writing promisor file 2021-01-12 16:01:07 -08:00
replace.c strvec: rename struct fields 2020-07-30 19:18:06 -07:00
rerere.c
reset.c wt-status: tolerate dangling marks 2020-09-02 14:39:25 -07:00
rev-list.c bisect: combine args passed to find_bisection() 2020-08-07 15:13:03 -07:00
rev-parse.c rev-parse: add option for absolute or relative path formatting 2020-12-12 23:35:51 -08:00
revert.c Merge branch 'en/merge-ort-api-null-impl' 2020-11-18 13:32:53 -08:00
rm.c rm: support the --pathspec-from-file option 2020-02-19 10:56:49 -08:00
send-pack.c push: parse and set flag for "--force-if-includes" 2020-10-03 09:59:19 -07:00
shortlog.c Merge branch 'ab/mailmap' 2021-01-25 14:19:19 -08:00
show-branch.c Merge branch 'jt/interpret-branch-name-fallback' 2020-09-09 13:53:09 -07:00
show-index.c builtin/show-index: provide options to determine hash algo 2020-05-27 10:07:07 -07:00
show-ref.c refs: switch peel_ref() to peel_iterated_oid() 2021-01-21 15:51:31 -08:00
sparse-checkout.c sparse-checkout: load sparse-checkout patterns 2021-01-23 17:14:07 -08:00
stash.c Merge branch 'en/stash-apply-sparse-checkout' 2021-01-15 15:20:29 -08:00
stripspace.c
submodule--helper.c builtin/*: update usage format 2021-01-06 15:10:49 -08:00
symbolic-ref.c
tag.c Merge branch 'ph/use-delete-refs' 2021-02-05 16:40:45 -08:00
unpack-file.c
unpack-objects.c sha1-file: pass git_hash_algo to hash_object_file() 2020-01-31 10:45:39 -08:00
update-index.c Use OPT_CALLBACK and OPT_CALLBACK_F 2020-04-28 10:47:10 -07:00
update-ref.c update-ref: disallow "start" for ongoing transactions 2020-11-16 13:44:01 -08:00
update-server-info.c
upload-archive.c strvec: rename struct fields 2020-07-30 19:18:06 -07:00
upload-pack.c
var.c
verify-commit.c
verify-pack.c Merge branch 'bc/sha-256-part-3' 2020-08-11 18:04:11 -07:00
verify-tag.c
worktree.c worktree: teach `list` verbose mode 2021-01-30 09:57:40 -08:00
write-tree.c