Skip to content

Commit 301d595

Browse files
HebaWalygitster
authored andcommitted
revision: move doc to revision.h
Move the documentation from Documentation/technical/api-revision-walking.txt to revision.h as it's easier for the developers to find the usage information beside the code instead of looking for it in another doc file. Also documentation/technical/api-revision-walking.txt is removed because the information it has is now redundant and it'll be hard to keep it up to date and synchronized with the documentation in the header file. Signed-off-by: Heba Waly <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3a1b341 commit 301d595

File tree

3 files changed

+60
-73
lines changed

3 files changed

+60
-73
lines changed

Documentation/MyFirstObjectWalk.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ revision walk is used for operations like `git log`.
1717

1818
- `Documentation/user-manual.txt` under "Hacking Git" contains some coverage of
1919
the revision walker in its various incarnations.
20-
- `Documentation/technical/api-revision-walking.txt`
20+
- `revision.h`
2121
- https://eagain.net/articles/git-for-computer-scientists/[Git for Computer Scientists]
2222
gives a good overview of the types of objects in Git and what your object
2323
walk is really describing.

Documentation/technical/api-revision-walking.txt

Lines changed: 0 additions & 72 deletions
This file was deleted.

revision.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@
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+
*/
309331
void 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+
*/
312342
int setup_revisions(int argc, const char **argv, struct rev_info *revs,
313343
struct setup_revision_opt *);
344+
314345
void 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,
319350
int 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+
*/
322357
void 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+
*/
323364
int 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+
*/
324371
struct commit *get_revision(struct rev_info *revs);
372+
325373
char *get_revision_mark(const struct rev_info *revs,
326374
const struct commit *commit);
327375
void put_revision_mark(const struct rev_info *revs,
@@ -333,8 +381,19 @@ void mark_trees_uninteresting_sparse(struct repository *r, struct oidset *trees)
333381

334382
void 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+
*/
336394
void add_pending_object(struct rev_info *revs,
337395
struct object *obj, const char *name);
396+
338397
void add_pending_oid(struct rev_info *revs,
339398
const char *name, const struct object_id *oid,
340399
unsigned int flags);

0 commit comments

Comments
 (0)