Skip to content

Commit 13c4d7e

Browse files
HebaWalygitster
authored andcommitted
diff: move doc to diff.h and diffcore.h
Move the documentation from Documentation/technical/api-diff.txt to both diff.h and diffcore.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-diff.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 files. There are three members documented in the doc file that weren't found in the header files, assuming the doc wasn't up to date and the members no longer exist: touched_flags, COLOR_DIFF_WORDS and QUIET. Signed-off-by: Heba Waly <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d9f6f3b commit 13c4d7e

File tree

3 files changed

+158
-174
lines changed

3 files changed

+158
-174
lines changed

Documentation/technical/api-diff.txt

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

diff.h

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,49 @@
99
#include "object.h"
1010
#include "oidset.h"
1111

12+
/**
13+
* The diff API is for programs that compare two sets of files (e.g. two trees,
14+
* one tree and the index) and present the found difference in various ways.
15+
* The calling program is responsible for feeding the API pairs of files, one
16+
* from the "old" set and the corresponding one from "new" set, that are
17+
* different.
18+
* The library called through this API is called diffcore, and is responsible
19+
* for two things.
20+
*
21+
* - finding total rewrites (`-B`), renames (`-M`) and copies (`-C`), and
22+
* changes that touch a string (`-S`), as specified by the caller.
23+
*
24+
* - outputting the differences in various formats, as specified by the caller.
25+
*
26+
* Calling sequence
27+
* ----------------
28+
*
29+
* - Prepare `struct diff_options` to record the set of diff options, and then
30+
* call `repo_diff_setup()` to initialize this structure. This sets up the
31+
* vanilla default.
32+
*
33+
* - Fill in the options structure to specify desired output format, rename
34+
* detection, etc. `diff_opt_parse()` can be used to parse options given
35+
* from the command line in a way consistent with existing git-diff family
36+
* of programs.
37+
*
38+
* - Call `diff_setup_done()`; this inspects the options set up so far for
39+
* internal consistency and make necessary tweaking to it (e.g. if textual
40+
* patch output was asked, recursive behaviour is turned on); the callback
41+
* set_default in diff_options can be used to tweak this more.
42+
*
43+
* - As you find different pairs of files, call `diff_change()` to feed
44+
* modified files, `diff_addremove()` to feed created or deleted files, or
45+
* `diff_unmerge()` to feed a file whose state is 'unmerged' to the API.
46+
* These are thin wrappers to a lower-level `diff_queue()` function that is
47+
* flexible enough to record any of these kinds of changes.
48+
*
49+
* - Once you finish feeding the pairs of files, call `diffcore_std()`.
50+
* This will tell the diffcore library to go ahead and do its work.
51+
*
52+
* - Calling `diff_flush()` will produce the output.
53+
*/
54+
1255
struct combine_diff_path;
1356
struct commit;
1457
struct diff_filespec;
@@ -65,21 +108,66 @@ typedef struct strbuf *(*diff_prefix_fn_t)(struct diff_options *opt, void *data)
65108

66109
#define DIFF_FLAGS_INIT { 0 }
67110
struct diff_flags {
111+
112+
/**
113+
* Tells if tree traversal done by tree-diff should recursively descend
114+
* into a tree object pair that are different in preimage and postimage set.
115+
*/
68116
unsigned recursive;
69117
unsigned tree_in_recursive;
118+
119+
/* Affects the way how a file that is seemingly binary is treated. */
70120
unsigned binary;
71121
unsigned text;
122+
123+
/**
124+
* Tells the patch output format not to use abbreviated object names on the
125+
* "index" lines.
126+
*/
72127
unsigned full_index;
128+
129+
/* Affects if diff-files shows removed files. */
73130
unsigned silent_on_remove;
131+
132+
/**
133+
* Tells the diffcore library that the caller is feeding unchanged
134+
* filepairs to allow copies from unmodified files be detected.
135+
*/
74136
unsigned find_copies_harder;
137+
75138
unsigned follow_renames;
76139
unsigned rename_empty;
140+
141+
/* Internal; used for optimization to see if there is any change. */
77142
unsigned has_changes;
143+
78144
unsigned quick;
145+
146+
/**
147+
* Tells diff-files that the input is not tracked files but files in random
148+
* locations on the filesystem.
149+
*/
79150
unsigned no_index;
151+
152+
/**
153+
* Tells output routine that it is Ok to call user specified patch output
154+
* routine. Plumbing disables this to ensure stable output.
155+
*/
80156
unsigned allow_external;
157+
158+
/**
159+
* For communication between the calling program and the options parser;
160+
* tell the calling program to signal the presence of difference using
161+
* program exit code.
162+
*/
81163
unsigned exit_with_status;
164+
165+
/**
166+
* Tells the library that the calling program is feeding the filepairs
167+
* reversed; `one` is two, and `two` is one.
168+
*/
82169
unsigned reverse_diff;
170+
83171
unsigned check_failed;
84172
unsigned relative_name;
85173
unsigned ignore_submodules;
@@ -131,36 +219,72 @@ enum diff_submodule_format {
131219
DIFF_SUBMODULE_INLINE_DIFF
132220
};
133221

222+
/**
223+
* the set of options the calling program wants to affect the operation of
224+
* diffcore library with.
225+
*/
134226
struct diff_options {
135227
const char *orderfile;
228+
229+
/**
230+
* A constant string (can and typically does contain newlines to look for
231+
* a block of text, not just a single line) to filter out the filepairs
232+
* that do not change the number of strings contained in its preimage and
233+
* postimage of the diff_queue.
234+
*/
136235
const char *pickaxe;
236+
137237
const char *single_follow;
138238
const char *a_prefix, *b_prefix;
139239
const char *line_prefix;
140240
size_t line_prefix_length;
241+
242+
/**
243+
* collection of boolean options that affects the operation, but some do
244+
* not have anything to do with the diffcore library.
245+
*/
141246
struct diff_flags flags;
142247

143248
/* diff-filter bits */
144249
unsigned int filter;
145250

146251
int use_color;
252+
253+
/* Number of context lines to generate in patch output. */
147254
int context;
255+
148256
int interhunkcontext;
257+
258+
/* Affects the way detection logic for complete rewrites, renames and
259+
* copies.
260+
*/
149261
int break_opt;
150262
int detect_rename;
263+
151264
int irreversible_delete;
152265
int skip_stat_unmatch;
153266
int line_termination;
267+
268+
/* The output format used when `diff_flush()` is run. */
154269
int output_format;
270+
155271
unsigned pickaxe_opts;
272+
273+
/* Affects the way detection logic for complete rewrites, renames and
274+
* copies.
275+
*/
156276
int rename_score;
157277
int rename_limit;
278+
158279
int needed_rename_limit;
159280
int degraded_cc_to_c;
160281
int show_rename_progress;
161282
int dirstat_permille;
162283
int setup;
284+
285+
/* Number of hexdigits to abbreviate raw format output to. */
163286
int abbrev;
287+
164288
int ita_invisible_in_index;
165289
/* white-space error highlighting */
166290
#define WSEH_NEW (1<<12)
@@ -192,6 +316,7 @@ struct diff_options {
192316
/* to support internal diff recursion by --follow hack*/
193317
int found_follow;
194318

319+
/* Callback which allows tweaking the options in diff_setup_done(). */
195320
void (*set_default)(struct diff_options *);
196321

197322
FILE *file;
@@ -270,6 +395,7 @@ enum color_diff {
270395
DIFF_FILE_OLD_BOLD = 21,
271396
DIFF_FILE_NEW_BOLD = 22,
272397
};
398+
273399
const char *diff_get_color(int diff_use_color, enum color_diff ix);
274400
#define diff_get_color_opt(o, ix) \
275401
diff_get_color((o)->use_color, ix)

0 commit comments

Comments
 (0)