99#include "diff.h"
1010#include "commit-slab-decl.h"
1111
12+ /**
13+ * The revision walking API offers functions to build a list of revisions
14+ * and then iterate over that list.
15+ *
16+ * Calling sequence
17+ * ----------------
18+ *
19+ * The walking API has a given calling sequence: first you need to initialize
20+ * a rev_info structure, then add revisions to control what kind of revision
21+ * list do you want to get, finally you can iterate over the revision list.
22+ *
23+ */
24+
1225/* Remember to update object flag allocation in object.h */
1326#define SEEN (1u<<0)
1427#define UNINTERESTING (1u<<1)
@@ -306,11 +319,29 @@ struct setup_revision_opt {
306319#ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS
307320#define init_revisions (revs , prefix ) repo_init_revisions(the_repository, revs, prefix)
308321#endif
322+
323+ /**
324+ * Initialize a rev_info structure with default values. The third parameter may
325+ * be NULL or can be prefix path, and then the `.prefix` variable will be set
326+ * to it. This is typically the first function you want to call when you want
327+ * to deal with a revision list. After calling this function, you are free to
328+ * customize options, like set `.ignore_merges` to 0 if you don't want to
329+ * ignore merges, and so on.
330+ */
309331void repo_init_revisions (struct repository * r ,
310332 struct rev_info * revs ,
311333 const char * prefix );
334+
335+ /**
336+ * Parse revision information, filling in the `rev_info` structure, and
337+ * removing the used arguments from the argument list. Returns the number
338+ * of arguments left that weren't recognized, which are also moved to the
339+ * head of the argument list. The last parameter is used in case no
340+ * parameter given by the first two arguments.
341+ */
312342int setup_revisions (int argc , const char * * argv , struct rev_info * revs ,
313343 struct setup_revision_opt * );
344+
314345void parse_revision_opt (struct rev_info * revs , struct parse_opt_ctx_t * ctx ,
315346 const struct option * options ,
316347 const char * const usagestr []);
@@ -319,9 +350,26 @@ void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,
319350int handle_revision_arg (const char * arg , struct rev_info * revs ,
320351 int flags , unsigned revarg_opt );
321352
353+ /**
354+ * Reset the flags used by the revision walking api. You can use this to do
355+ * multiple sequential revision walks.
356+ */
322357void reset_revision_walk (void );
358+
359+ /**
360+ * Prepares the rev_info structure for a walk. You should check if it returns
361+ * any error (non-zero return code) and if it does not, you can start using
362+ * get_revision() to do the iteration.
363+ */
323364int prepare_revision_walk (struct rev_info * revs );
365+
366+ /**
367+ * Takes a pointer to a `rev_info` structure and iterates over it, returning a
368+ * `struct commit *` each time you call it. The end of the revision list is
369+ * indicated by returning a NULL pointer.
370+ */
324371struct commit * get_revision (struct rev_info * revs );
372+
325373char * get_revision_mark (const struct rev_info * revs ,
326374 const struct commit * commit );
327375void put_revision_mark (const struct rev_info * revs ,
@@ -333,8 +381,19 @@ void mark_trees_uninteresting_sparse(struct repository *r, struct oidset *trees)
333381
334382void show_object_with_name (FILE * , struct object * , const char * );
335383
384+ /**
385+ * This function can be used if you want to add commit objects as revision
386+ * information. You can use the `UNINTERESTING` object flag to indicate if
387+ * you want to include or exclude the given commit (and commits reachable
388+ * from the given commit) from the revision list.
389+ *
390+ * NOTE: If you have the commits as a string list then you probably want to
391+ * use setup_revisions(), instead of parsing each string and using this
392+ * function.
393+ */
336394void add_pending_object (struct rev_info * revs ,
337395 struct object * obj , const char * name );
396+
338397void add_pending_oid (struct rev_info * revs ,
339398 const char * name , const struct object_id * oid ,
340399 unsigned int flags );
0 commit comments