git/revision.h

#ifndef REVISION_H
#define REVISION_H

#include "commit.h"
#include "grep.h"
#include "notes.h"
#include "oidset.h"
#include "pretty.h"
#include "diff.h"
#include "commit-slab-decl.h"
#include "decorate.h"
#include "ident.h"
#include "list-objects-filter-options.h"
#include "strvec.h"

/**
 * The revision walking API offers functions to build a list of revisions
 * and then iterate over that list.
 *
 * Calling sequence
 * ----------------
 *
 * The walking API has a given calling sequence: first you need to initialize
 * a rev_info structure, then add revisions to control what kind of revision
 * list do you want to get, finally you can iterate over the revision list.
 *
 */

/* Remember to update object flag allocation in object.h */
#define SEEN
#define UNINTERESTING
#define TREESAME
#define SHOWN
#define TMP_MARK
#define BOUNDARY
#define CHILD_SHOWN
#define ADDED
#define SYMMETRIC_LEFT
#define PATCHSAME
#define BOTTOM

/* WARNING: This is also used as REACHABLE in commit-graph.c. */
#define PULL_MERGE

#define TOPO_WALK_EXPLORED
#define TOPO_WALK_INDEGREE

/*
 * Indicates object was reached by traversal. i.e. not given by user on
 * command-line or stdin.
 */
#define NOT_USER_GIVEN
#define TRACK_LINEAR
#define ANCESTRY_PATH
#define ALL_REV_FLAGS

#define DECORATE_SHORT_REFS
#define DECORATE_FULL_REFS

struct log_info;
struct repository;
struct rev_info;
struct string_list;
struct saved_parents;
struct bloom_key;
struct bloom_filter_settings;
struct option;
struct parse_opt_ctx_t;
define_shared_commit_slab();

struct rev_cmdline_info {};

struct ref_exclusions {};

/**
 * Initialize a `struct ref_exclusions` with a macro.
 */
#define REF_EXCLUSIONS_INIT

struct oidset;
struct topo_walk_info;

struct rev_info {};

/**
 * 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

/**
 * Initialize a rev_info structure with default values. The third parameter may
 * be NULL or can be prefix path, and then the `.prefix` variable will be set
 * to it. This is typically the first function you want to call when you want
 * to deal with a revision list. After calling this function, you are free to
 * customize options, like set `.ignore_merges` to 0 if you don't want to
 * ignore merges, and so on.
 */
void repo_init_revisions(struct repository *r,
			 struct rev_info *revs,
			 const char *prefix);

/**
 * Parse revision information, filling in the `rev_info` structure, and
 * removing the used arguments from the argument list. Returns the number
 * of arguments left that weren't recognized, which are also moved to the
 * head of the argument list. The last parameter is used in case no
 * parameter given by the first two arguments.
 */
struct setup_revision_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[]);
#define REVARG_CANNOT_BE_FILENAME
#define REVARG_COMMITTISH
int handle_revision_arg(const char *arg, struct rev_info *revs,
			int flags, unsigned revarg_opt);
void revision_opts_finish(struct rev_info *revs);

/**
 * Reset the flags used by the revision walking api. You can use this to do
 * multiple sequential revision walks.
 */
void reset_revision_walk(void);

/**
 * Prepares the rev_info structure for a walk. You should check if it returns
 * any error (non-zero return code) and if it does not, you can start using
 * get_revision() to do the iteration.
 */
int prepare_revision_walk(struct rev_info *revs);

/**
 * Takes a pointer to a `rev_info` structure and iterates over it, returning a
 * `struct commit *` each time you call it. The end of the revision list is
 * indicated by returning a NULL pointer.
 */
struct commit *get_revision(struct rev_info *revs);

const char *get_revision_mark(const struct rev_info *revs,
			      const struct commit *commit);
void put_revision_mark(const struct rev_info *revs,
		       const struct commit *commit);

void mark_parents_uninteresting(struct rev_info *revs, struct commit *commit);
void mark_tree_uninteresting(struct repository *r, struct tree *tree);
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 reference should be excluded.
 */

int ref_excluded(const struct ref_exclusions *exclusions, const char *path);
void init_ref_exclusions(struct ref_exclusions *);
void clear_ref_exclusions(struct ref_exclusions *);
void add_ref_exclusion(struct ref_exclusions *, const char *exclude);
void exclude_hidden_refs(struct ref_exclusions *, const char *section);

/**
 * 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
 * you want to include or exclude the given commit (and commits reachable
 * from the given commit) from the revision list.
 *
 * NOTE: If you have the commits as a string list then you probably want to
 * use setup_revisions(), instead of parsing each string and using this
 * function.
 */
void add_pending_object(struct rev_info *revs,
			struct object *obj, const char *name);

void add_pending_oid(struct rev_info *revs,
		     const char *name, const struct object_id *oid,
		     unsigned int flags);

void add_head_to_pending(struct rev_info *);
void add_reflogs_to_pending(struct rev_info *, unsigned int flags);
void add_index_objects_to_pending(struct rev_info *, unsigned int flags);

enum commit_action {};

enum commit_action get_commit_action(struct rev_info *revs,
				     struct commit *commit);
enum commit_action simplify_commit(struct rev_info *revs,
				   struct commit *commit);

enum rewrite_result {};

rewrite_parent_fn_t;

int rewrite_parents(struct rev_info *revs,
		    struct commit *commit,
		    rewrite_parent_fn_t rewrite_parent);

/*
 * The log machinery saves the original parent list so that
 * get_saved_parents() can later tell what the real parents of the
 * commits are, when commit->parents has been modified by history
 * simplification.
 *
 * get_saved_parents() will transparently return commit->parents if
 * history simplification is off.
 */
struct commit_list *get_saved_parents(struct rev_info *revs, const struct commit *commit);

/**
 * Global for the (undocumented) "--early-output" flag for "git log".
 */
show_early_output_fn_t;
extern volatile show_early_output_fn_t show_early_output;

#endif