Merge branch 'ab/plug-leak-in-revisions'

Plug the memory leaks from the trickiest API of all, the revision
walker.

* ab/plug-leak-in-revisions: (27 commits)
  revisions API: add a TODO for diff_free(&revs->diffopt)
  revisions API: have release_revisions() release "topo_walk_info"
  revisions API: have release_revisions() release "date_mode"
  revisions API: call diff_free(&revs->pruning) in revisions_release()
  revisions API: release "reflog_info" in release revisions()
  revisions API: clear "boundary_commits" in release_revisions()
  revisions API: have release_revisions() release "prune_data"
  revisions API: have release_revisions() release "grep_filter"
  revisions API: have release_revisions() release "filter"
  revisions API: have release_revisions() release "cmdline"
  revisions API: have release_revisions() release "mailmap"
  revisions API: have release_revisions() release "commits"
  revisions API users: use release_revisions() for "prune_data" users
  revisions API users: use release_revisions() with UNLEAK()
  revisions API users: use release_revisions() in builtin/log.c
  revisions API users: use release_revisions() in http-push.c
  revisions API users: add "goto cleanup" for release_revisions()
  stash: always have the owner of "stash_info" free it
  revisions API users: use release_revisions() needing REV_INFO_INIT
  revision.[ch]: document and move code declared around "init"
  ...
This commit is contained in:
Junio C Hamano
2022-06-07 14:10:56 -07:00
117 changed files with 500 additions and 190 deletions

View File

@ -330,31 +330,24 @@ struct rev_info {
struct tmp_objdir *remerge_objdir;
};
int ref_excluded(struct string_list *, const char *path);
void clear_ref_exclusion(struct string_list **);
void add_ref_exclusion(struct string_list **, const char *exclude);
#define REV_TREE_SAME 0
#define REV_TREE_NEW 1 /* Only new files */
#define REV_TREE_OLD 2 /* Only files removed */
#define REV_TREE_DIFFERENT 3 /* Mixed changes */
/* revision.c */
typedef void (*show_early_output_fn_t)(struct rev_info *, struct commit_list *);
extern volatile show_early_output_fn_t show_early_output;
struct setup_revision_opt {
const char *def;
void (*tweak)(struct rev_info *, struct setup_revision_opt *);
unsigned int assume_dashdash:1,
allow_exclude_promisor_objects:1;
unsigned revarg_opt;
};
#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
#define init_revisions(revs, prefix) repo_init_revisions(the_repository, revs, prefix)
#endif
/**
* Initialize the "struct rev_info" structure with a macro.
*
* This will not fully initialize a "struct rev_info", the
* repo_init_revisions() function needs to be called before
* setup_revisions() and any revision walking takes place.
*
* Use REV_INFO_INIT to make the "struct rev_info" safe for passing to
* release_revisions() when it's inconvenient (e.g. due to a "goto
* cleanup" pattern) to arrange for repo_init_revisions() to be called
* before release_revisions() is called.
*
* Initializing with this REV_INFO_INIT is redundant to invoking
* repo_init_revisions(). If repo_init_revisions() is guaranteed to be
* called before release_revisions() the "struct rev_info" can be left
* uninitialized.
*/
#define REV_INFO_INIT { 0 }
/**
* Initialize a rev_info structure with default values. The third parameter may
@ -367,6 +360,9 @@ struct setup_revision_opt {
void repo_init_revisions(struct repository *r,
struct rev_info *revs,
const char *prefix);
#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
#define init_revisions(revs, prefix) repo_init_revisions(the_repository, revs, prefix)
#endif
/**
* Parse revision information, filling in the `rev_info` structure, and
@ -375,9 +371,22 @@ void repo_init_revisions(struct repository *r,
* head of the argument list. The last parameter is used in case no
* parameter given by the first two arguments.
*/
struct setup_revision_opt {
const char *def;
void (*tweak)(struct rev_info *, struct setup_revision_opt *);
unsigned int assume_dashdash:1,
allow_exclude_promisor_objects:1;
unsigned revarg_opt;
};
int setup_revisions(int argc, const char **argv, struct rev_info *revs,
struct setup_revision_opt *);
/**
* Free data allocated in a "struct rev_info" after it's been
* initialized with repo_init_revisions() or REV_INFO_INIT.
*/
void release_revisions(struct rev_info *revs);
void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,
const struct option *options,
const char * const usagestr[]);
@ -418,6 +427,14 @@ void mark_trees_uninteresting_sparse(struct repository *r, struct oidset *trees)
void show_object_with_name(FILE *, struct object *, const char *);
/**
* Helpers to check if a "struct string_list" item matches with
* wildmatch().
*/
int ref_excluded(struct string_list *, const char *path);
void clear_ref_exclusion(struct string_list **);
void add_ref_exclusion(struct string_list **, const char *exclude);
/**
* This function can be used if you want to add commit objects as revision
* information. You can use the `UNINTERESTING` object flag to indicate if
@ -473,4 +490,10 @@ int rewrite_parents(struct rev_info *revs,
*/
struct commit_list *get_saved_parents(struct rev_info *revs, const struct commit *commit);
/**
* Global for the (undocumented) "--early-output" flag for "git log".
*/
typedef void (*show_early_output_fn_t)(struct rev_info *, struct commit_list *);
extern volatile show_early_output_fn_t show_early_output;
#endif