Coverage Report

Created: 2026-12-01 06:58

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/git/diff.h
Line
Count
Source
1
/*
2
 * Copyright (C) 2005 Junio C Hamano
3
 */
4
#ifndef DIFF_H
5
#define DIFF_H
6
7
#include "hash.h"
8
#include "pathspec.h"
9
#include "strbuf.h"
10
#include "color.h"
11
12
struct oidset;
13
14
/**
15
 * The diff API is for programs that compare two sets of files (e.g. two trees,
16
 * one tree and the index) and present the found difference in various ways.
17
 * The calling program is responsible for feeding the API pairs of files, one
18
 * from the "old" set and the corresponding one from "new" set, that are
19
 * different.
20
 * The library called through this API is called diffcore, and is responsible
21
 * for two things.
22
 *
23
 * - finding total rewrites (`-B`), renames (`-M`) and copies (`-C`), and
24
 * changes that touch a string (`-S`), as specified by the caller.
25
 *
26
 * - outputting the differences in various formats, as specified by the caller.
27
 *
28
 * Calling sequence
29
 * ----------------
30
 *
31
 * - Prepare `struct diff_options` to record the set of diff options, and then
32
 * call `repo_diff_setup()` to initialize this structure.  This sets up the
33
 * vanilla default.
34
 *
35
 * - Fill in the options structure to specify desired output format, rename
36
 * detection, etc.  `diff_opt_parse()` can be used to parse options given
37
 * from the command line in a way consistent with existing git-diff family
38
 * of programs.
39
 *
40
 * - Call `diff_setup_done()`; this inspects the options set up so far for
41
 * internal consistency and make necessary tweaking to it (e.g. if textual
42
 * patch output was asked, recursive behaviour is turned on); the callback
43
 * set_default in diff_options can be used to tweak this more.
44
 *
45
 * - As you find different pairs of files, call `diff_change()` to feed
46
 * modified files, `diff_addremove()` to feed created or deleted files, or
47
 * `diff_unmerge()` to feed a file whose state is 'unmerged' to the API.
48
 * These are thin wrappers to a lower-level `diff_queue()` function that is
49
 * flexible enough to record any of these kinds of changes.
50
 *
51
 * - Once you finish feeding the pairs of files, call `diffcore_std()`.
52
 * This will tell the diffcore library to go ahead and do its work.
53
 *
54
 * - Calling `diff_flush()` will produce the output, it will call
55
 *   `diff_free()` to free any resources, e.g. those allocated in
56
 *   `diff_opt_parse()`.
57
 *
58
 * - Set `.no_free = 1` before calling `diff_flush()` to defer the
59
 *   freeing of allocated memory in diff_options. This is useful when
60
 *   `diff_flush()` is being called in a loop, rather than as a
61
 *   one-off. When setting `.no_free = 1` you must ensure that
62
 *   `diff_free()` is called at the end, either by flipping the flag
63
 *   before the last `diff_flush()` call, or by flipping it before
64
 *   calling `diff_free()` yourself.
65
 */
66
67
struct combine_diff_path;
68
struct commit;
69
struct diff_filespec;
70
struct diff_options;
71
struct diff_queue_struct;
72
struct oid_array;
73
struct option;
74
struct repository;
75
struct rev_info;
76
struct userdiff_driver;
77
78
typedef int (*pathchange_fn_t)(struct diff_options *options,
79
     struct combine_diff_path *path);
80
81
typedef void (*change_fn_t)(struct diff_options *options,
82
     unsigned old_mode, unsigned new_mode,
83
     const struct object_id *old_oid,
84
     const struct object_id *new_oid,
85
     int old_oid_valid, int new_oid_valid,
86
     const char *fullpath,
87
     unsigned old_dirty_submodule, unsigned new_dirty_submodule);
88
89
typedef void (*add_remove_fn_t)(struct diff_options *options,
90
        int addremove, unsigned mode,
91
        const struct object_id *oid,
92
        int oid_valid,
93
        const char *fullpath, unsigned dirty_submodule);
94
95
typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
96
    struct diff_options *options, void *data);
97
98
typedef const char *(*diff_prefix_fn_t)(struct diff_options *opt, void *data);
99
100
0
#define DIFF_FORMAT_RAW   0x0001
101
0
#define DIFF_FORMAT_DIFFSTAT  0x0002
102
0
#define DIFF_FORMAT_NUMSTAT 0x0004
103
0
#define DIFF_FORMAT_SUMMARY 0x0008
104
0
#define DIFF_FORMAT_PATCH 0x0010
105
0
#define DIFF_FORMAT_SHORTSTAT 0x0020
106
0
#define DIFF_FORMAT_DIRSTAT 0x0040
107
108
/* These override all above */
109
0
#define DIFF_FORMAT_NAME  0x0100
110
0
#define DIFF_FORMAT_NAME_STATUS 0x0200
111
0
#define DIFF_FORMAT_CHECKDIFF 0x0400
112
113
/* Same as output_format = 0 but we know that -s flag was given
114
 * and we should not give default value to output_format.
115
 */
116
0
#define DIFF_FORMAT_NO_OUTPUT 0x0800
117
118
0
#define DIFF_FORMAT_CALLBACK  0x1000
119
120
#define DIFF_FLAGS_INIT { 0 }
121
struct diff_flags {
122
123
  /**
124
   * Tells if tree traversal done by tree-diff should recursively descend
125
   * into a tree object pair that are different in preimage and postimage set.
126
   */
127
  unsigned recursive;
128
  unsigned tree_in_recursive;
129
130
  /*
131
   * Historically diff_tree_combined() overrides recursive to 1. To
132
   * suppress this behavior, set the flag below.
133
   * It has no effect if recursive is already set to 1.
134
   */
135
  unsigned no_recursive_diff_tree_combined;
136
137
  /* Affects the way how a file that is seemingly binary is treated. */
138
  unsigned binary;
139
  unsigned text;
140
141
  /**
142
   * Tells the patch output format not to use abbreviated object names on the
143
   * "index" lines.
144
   */
145
  unsigned full_index;
146
147
  /* Affects if diff-files shows removed files. */
148
  unsigned silent_on_remove;
149
150
  /**
151
   * Tells the diffcore library that the caller is feeding unchanged
152
   * filepairs to allow copies from unmodified files be detected.
153
   */
154
  unsigned find_copies_harder;
155
156
  unsigned follow_renames;
157
  unsigned follow_merges;
158
  unsigned rename_empty;
159
160
  /* Internal; used for optimization to see if there is any change. */
161
  unsigned has_changes;
162
163
  unsigned quick;
164
165
  /**
166
   * Tells diff-files that the input is not tracked files but files in random
167
   * locations on the filesystem.
168
   */
169
  unsigned no_index;
170
171
  /**
172
   * Tells output routine that it is Ok to call user specified patch output
173
   * routine.  Plumbing disables this to ensure stable output.
174
   */
175
  unsigned allow_external;
176
177
  /**
178
   * For communication between the calling program and the options parser;
179
   * tell the calling program to signal the presence of difference using
180
   * program exit code.
181
   */
182
  unsigned exit_with_status;
183
184
  /**
185
   * Tells the library that the calling program is feeding the filepairs
186
   * reversed; `one` is two, and `two` is one.
187
   */
188
  unsigned reverse_diff;
189
190
  unsigned check_failed;
191
  unsigned relative_name;
192
  unsigned ignore_submodules;
193
  unsigned dirstat_cumulative;
194
  unsigned dirstat_by_file;
195
  unsigned allow_textconv;
196
  unsigned textconv_set_via_cmdline;
197
  unsigned diff_from_contents;
198
  unsigned dirty_submodules;
199
  unsigned ignore_untracked_in_submodules;
200
  unsigned ignore_submodule_set;
201
  unsigned ignore_dirty_submodules;
202
  unsigned override_submodule_config;
203
  unsigned dirstat_by_line;
204
  unsigned funccontext;
205
  unsigned default_follow_renames;
206
  unsigned default_follow_merges;
207
  unsigned stat_with_summary;
208
  unsigned suppress_diff_headers;
209
  unsigned dual_color_diffed_diffs;
210
  unsigned suppress_hunk_header_line_count;
211
};
212
213
static inline void diff_flags_or(struct diff_flags *a,
214
         const struct diff_flags *b)
215
0
{
216
0
  char *tmp_a = (char *)a;
217
0
  const char *tmp_b = (const char *)b;
218
219
0
  for (size_t i = 0; i < sizeof(struct diff_flags); i++)
220
0
    tmp_a[i] |= tmp_b[i];
221
0
}
Unexecuted instantiation: remote.c:diff_flags_or
Unexecuted instantiation: revision.c:diff_flags_or
Unexecuted instantiation: shallow.c:diff_flags_or
Unexecuted instantiation: submodule.c:diff_flags_or
Unexecuted instantiation: tree-diff.c:diff_flags_or
Unexecuted instantiation: wt-status.c:diff_flags_or
Unexecuted instantiation: bisect.c:diff_flags_or
Unexecuted instantiation: bloom.c:diff_flags_or
Unexecuted instantiation: bundle.c:diff_flags_or
Unexecuted instantiation: combine-diff.c:diff_flags_or
Unexecuted instantiation: commit-reach.c:diff_flags_or
Unexecuted instantiation: commit.c:diff_flags_or
Unexecuted instantiation: diff-merges.c:diff_flags_or
Unexecuted instantiation: diff-lib.c:diff_flags_or
Unexecuted instantiation: diff.c:diff_flags_or
Unexecuted instantiation: diffcore-order.c:diff_flags_or
Unexecuted instantiation: diffcore-pickaxe.c:diff_flags_or
Unexecuted instantiation: diffcore-rename.c:diff_flags_or
Unexecuted instantiation: diffcore-rotate.c:diff_flags_or
Unexecuted instantiation: graph.c:diff_flags_or
Unexecuted instantiation: grep.c:diff_flags_or
Unexecuted instantiation: line-log.c:diff_flags_or
Unexecuted instantiation: list-objects.c:diff_flags_or
Unexecuted instantiation: log-tree.c:diff_flags_or
Unexecuted instantiation: merge-ort.c:diff_flags_or
Unexecuted instantiation: pack-bitmap.c:diff_flags_or
Unexecuted instantiation: patch-ids.c:diff_flags_or
Unexecuted instantiation: pretty.c:diff_flags_or
Unexecuted instantiation: range-diff.c:diff_flags_or
Unexecuted instantiation: read-cache.c:diff_flags_or
Unexecuted instantiation: reflog-walk.c:diff_flags_or
Unexecuted instantiation: files-backend.c:diff_flags_or
Unexecuted instantiation: sequencer.c:diff_flags_or
Unexecuted instantiation: apply.c:diff_flags_or
Unexecuted instantiation: attr.c:diff_flags_or
Unexecuted instantiation: list-objects-filter.c:diff_flags_or
Unexecuted instantiation: pack-bitmap-write.c:diff_flags_or
222
223
#define DIFF_XDL_TST(opts, flag)    ((opts)->xdl_opts & XDF_##flag)
224
0
#define DIFF_XDL_SET(opts, flag)    ((opts)->xdl_opts |= XDF_##flag)
225
#define DIFF_XDL_CLR(opts, flag)    ((opts)->xdl_opts &= ~XDF_##flag)
226
227
0
#define DIFF_WITH_ALG(opts, flag)   (((opts)->xdl_opts & ~XDF_DIFF_ALGORITHM_MASK) | XDF_##flag)
228
229
enum diff_words_type {
230
  DIFF_WORDS_NONE = 0,
231
  DIFF_WORDS_PORCELAIN,
232
  DIFF_WORDS_PLAIN,
233
  DIFF_WORDS_COLOR
234
};
235
236
enum diff_submodule_format {
237
  DIFF_SUBMODULE_SHORT = 0,
238
  DIFF_SUBMODULE_LOG,
239
  DIFF_SUBMODULE_INLINE_DIFF
240
};
241
242
/**
243
 * the set of options the calling program wants to affect the operation of
244
 * diffcore library with.
245
 */
246
struct diff_options {
247
  char *orderfile;
248
249
  /*
250
   * "--rotate-to=<file>" would start showing at <file> and when
251
   * the output reaches the end, wrap around by default.
252
   * Setting skip_instead_of_rotate to true stops the output at the
253
   * end, effectively discarding the earlier part of the output
254
   * before <file>'s diff (this is used to implement the
255
   * "--skip-to=<file>" option).
256
   *
257
   * When rotate_to_strict is set, it is an error if there is no
258
   * <file> in the diff.  Otherwise, the output starts at the
259
   * path that is the same as, or first path that sorts after,
260
   * <file>.  Because it is unreasonable to require the exact
261
   * match for "git log -p --rotate-to=<file>" (i.e. not all
262
   * commit would touch that single <file>), "git log" sets it
263
   * to false.  "git diff" sets it to true to detect an error
264
   * in the command line option.
265
   */
266
  const char *rotate_to;
267
  int skip_instead_of_rotate;
268
  int rotate_to_strict;
269
270
  /**
271
   * A constant string (can and typically does contain newlines to look for
272
   * a block of text, not just a single line) to filter out the filepairs
273
   * that do not change the number of strings contained in its preimage and
274
   * postimage of the diff_queue.
275
   */
276
  const char *pickaxe;
277
  unsigned pickaxe_opts;
278
279
  /* -I<regex> */
280
  regex_t **ignore_regex;
281
  size_t ignore_regex_nr, ignore_regex_alloc;
282
283
  const char *single_follow;
284
  const char *a_prefix, *b_prefix;
285
  const char *line_prefix;
286
287
  /**
288
   * collection of boolean options that affects the operation, but some do
289
   * not have anything to do with the diffcore library.
290
   */
291
  struct diff_flags flags;
292
293
  /* diff-filter bits */
294
  unsigned int filter, filter_not;
295
296
  enum git_colorbool use_color;
297
298
  /* Number of context lines to generate in patch output. */
299
  unsigned int context;
300
301
  unsigned int interhunkcontext;
302
303
  /* Affects the way detection logic for complete rewrites, renames and
304
   * copies.
305
   */
306
  int break_opt;
307
  int detect_rename;
308
309
  int irreversible_delete;
310
  int skip_stat_unmatch;
311
  int line_termination;
312
313
  /* The output format used when `diff_flush()` is run. */
314
  int output_format;
315
316
  /* Affects the way detection logic for complete rewrites, renames and
317
   * copies.
318
   */
319
  int rename_score;
320
  int rename_limit;
321
322
  int needed_rename_limit;
323
  int degraded_cc_to_c;
324
  int show_rename_progress;
325
  int dirstat_permille;
326
  int setup;
327
328
  /* Number of hexdigits to abbreviate raw format output to. */
329
  int abbrev;
330
331
  /* If non-zero, then stop computing after this many changes. */
332
  int max_changes;
333
334
  int ita_invisible_in_index;
335
/* white-space error highlighting */
336
0
#define WSEH_NEW        (1<<16)
337
0
#define WSEH_CONTEXT    (1<<17)
338
0
#define WSEH_OLD        (1<<18)
339
  unsigned ws_error_highlight;
340
  const char *prefix;
341
  int prefix_length;
342
  const char *stat_sep;
343
  int xdl_opts;
344
  int ignore_driver_algorithm;
345
346
  /* see Documentation/diff-options.adoc */
347
  char **anchors;
348
  size_t anchors_nr, anchors_alloc;
349
350
  int stat_width;
351
  int stat_name_width;
352
  int stat_graph_width;
353
  int stat_count;
354
  const char *word_regex;
355
  enum diff_words_type word_diff;
356
  enum diff_submodule_format submodule_format;
357
358
  struct oidset *objfind;
359
360
  /* this is set by diffcore for DIFF_FORMAT_PATCH */
361
  int found_changes;
362
363
  /* to support internal diff recursion by --follow hack*/
364
  int found_follow;
365
366
  /*
367
   * By default, diffcore_std() resolves the statuses for queued diff file
368
   * pairs by calling diff_resolve_rename_copy(). If status information
369
   * has already been manually set, this option prevents diffcore_std()
370
   * from resetting statuses.
371
   */
372
  int skip_resolving_statuses;
373
374
  /* Callback which allows tweaking the options in diff_setup_done(). */
375
  void (*set_default)(struct diff_options *);
376
377
  FILE *file;
378
  int close_file;
379
380
0
#define OUTPUT_INDICATOR_NEW 0
381
0
#define OUTPUT_INDICATOR_OLD 1
382
0
#define OUTPUT_INDICATOR_CONTEXT 2
383
  char output_indicators[3];
384
385
  struct pathspec pathspec;
386
  pathchange_fn_t pathchange;
387
  change_fn_t change;
388
  add_remove_fn_t add_remove;
389
  void *change_fn_data;
390
  diff_format_fn_t format_callback;
391
  void *format_callback_data;
392
  diff_prefix_fn_t output_prefix;
393
  void *output_prefix_data;
394
395
  int diff_path_counter;
396
397
  struct emitted_diff_symbols *emitted_symbols;
398
  enum {
399
    COLOR_MOVED_NO = 0,
400
    COLOR_MOVED_PLAIN = 1,
401
    COLOR_MOVED_BLOCKS = 2,
402
    COLOR_MOVED_ZEBRA = 3,
403
    COLOR_MOVED_ZEBRA_DIM = 4,
404
  } color_moved;
405
0
  #define COLOR_MOVED_DEFAULT COLOR_MOVED_ZEBRA
406
0
  #define COLOR_MOVED_MIN_ALNUM_COUNT 20
407
408
  /* XDF_WHITESPACE_FLAGS regarding block detection are set at 2, 3, 4 */
409
0
  #define COLOR_MOVED_WS_ALLOW_INDENTATION_CHANGE (1<<5)
410
0
  #define COLOR_MOVED_WS_ERROR (1<<0)
411
  unsigned color_moved_ws_handling;
412
413
  struct repository *repo;
414
  struct strmap *additional_path_headers;
415
416
  int no_free;
417
418
  /*
419
   * The value '0' is a valid max-depth (for no recursion), and value '-1'
420
   * also (for unlimited recursion), so the extra "valid" flag is used to
421
   * determined whether the user specified option --max-depth.
422
   */
423
  int max_depth;
424
  int max_depth_valid;
425
};
426
427
unsigned diff_filter_bit(char status);
428
429
void diff_emit_submodule_del(struct diff_options *o, const char *line);
430
void diff_emit_submodule_add(struct diff_options *o, const char *line);
431
void diff_emit_submodule_untracked(struct diff_options *o, const char *path);
432
void diff_emit_submodule_modified(struct diff_options *o, const char *path);
433
void diff_emit_submodule_header(struct diff_options *o, const char *header);
434
void diff_emit_submodule_error(struct diff_options *o, const char *err);
435
void diff_emit_submodule_pipethrough(struct diff_options *o,
436
             const char *line, int len);
437
438
struct diffstat_t {
439
  int nr;
440
  int alloc;
441
  struct diffstat_file {
442
    char *from_name;
443
    char *name;
444
    char *print_name;
445
    const char *comments;
446
    unsigned is_unmerged:1;
447
    unsigned is_binary:1;
448
    unsigned is_renamed:1;
449
    unsigned is_interesting:1;
450
    uintmax_t added, deleted;
451
  } **files;
452
};
453
454
enum color_diff {
455
  DIFF_RESET = 0,
456
  DIFF_CONTEXT = 1,
457
  DIFF_METAINFO = 2,
458
  DIFF_FRAGINFO = 3,
459
  DIFF_FILE_OLD = 4,
460
  DIFF_FILE_NEW = 5,
461
  DIFF_COMMIT = 6,
462
  DIFF_WHITESPACE = 7,
463
  DIFF_FUNCINFO = 8,
464
  DIFF_FILE_OLD_MOVED = 9,
465
  DIFF_FILE_OLD_MOVED_ALT = 10,
466
  DIFF_FILE_OLD_MOVED_DIM = 11,
467
  DIFF_FILE_OLD_MOVED_ALT_DIM = 12,
468
  DIFF_FILE_NEW_MOVED = 13,
469
  DIFF_FILE_NEW_MOVED_ALT = 14,
470
  DIFF_FILE_NEW_MOVED_DIM = 15,
471
  DIFF_FILE_NEW_MOVED_ALT_DIM = 16,
472
  DIFF_CONTEXT_DIM = 17,
473
  DIFF_FILE_OLD_DIM = 18,
474
  DIFF_FILE_NEW_DIM = 19,
475
  DIFF_CONTEXT_BOLD = 20,
476
  DIFF_FILE_OLD_BOLD = 21,
477
  DIFF_FILE_NEW_BOLD = 22,
478
};
479
480
const char *diff_get_color(enum git_colorbool diff_use_color, enum color_diff ix);
481
#define diff_get_color_opt(o, ix) \
482
0
  diff_get_color((o)->use_color, ix)
483
484
485
const char *diff_line_prefix(struct diff_options *);
486
487
488
extern const char mime_boundary_leader[];
489
490
struct combine_diff_path *diff_tree_paths(
491
  const struct object_id *oid,
492
  const struct object_id **parents_oid, int nparent,
493
  struct strbuf *base, struct diff_options *opt);
494
void diff_tree_oid(const struct object_id *old_oid,
495
       const struct object_id *new_oid,
496
       const char *base, struct diff_options *opt);
497
void diff_root_tree_oid(const struct object_id *new_oid, const char *base,
498
      struct diff_options *opt);
499
500
struct combine_diff_path {
501
  struct combine_diff_path *next;
502
  char *path;
503
  unsigned int mode;
504
  struct object_id oid;
505
  struct combine_diff_parent {
506
    char status;
507
    unsigned int mode;
508
    struct object_id oid;
509
    /*
510
     * This per-parent path is filled only when doing a combined
511
     * diff with revs.combined_all_paths set, and only if the path
512
     * differs from the post-image (e.g., a rename or copy).
513
     * Otherwise it is left NULL.
514
     */
515
    char *path;
516
  } parent[FLEX_ARRAY];
517
};
518
struct combine_diff_path *combine_diff_path_new(const char *path,
519
            size_t path_len,
520
            unsigned int mode,
521
            const struct object_id *oid,
522
            size_t num_parents);
523
524
void show_combined_diff(struct combine_diff_path *elem, int num_parent,
525
      struct rev_info *);
526
527
void diff_tree_combined(const struct object_id *oid, const struct oid_array *parents, struct rev_info *rev);
528
529
void diff_tree_combined_merge(const struct commit *commit, struct rev_info *rev);
530
531
void diff_set_mnemonic_prefix(struct diff_options *options, const char *a, const char *b);
532
void diff_set_noprefix(struct diff_options *options);
533
void diff_set_default_prefix(struct diff_options *options);
534
535
int diff_can_quit_early(struct diff_options *);
536
537
/*
538
 * Stages changes in the provided diff queue for file additions and deletions.
539
 * If a file pair gets queued, it is returned.
540
 */
541
struct diff_filepair *diff_queue_addremove(struct diff_queue_struct *queue,
542
             struct diff_options *,
543
             int addremove, unsigned mode,
544
             const struct object_id *oid,
545
             int oid_valid, const char *fullpath,
546
             unsigned dirty_submodule);
547
548
/*
549
 * Stages changes in the provided diff queue for file modifications.
550
 * If a file pair gets queued, it is returned.
551
 */
552
struct diff_filepair *diff_queue_change(struct diff_queue_struct *queue,
553
          struct diff_options *,
554
          unsigned mode1, unsigned mode2,
555
          const struct object_id *old_oid,
556
          const struct object_id *new_oid,
557
          int old_oid_valid, int new_oid_valid,
558
          const char *fullpath,
559
          unsigned dirty_submodule1,
560
          unsigned dirty_submodule2);
561
562
void diff_addremove(struct diff_options *,
563
        int addremove,
564
        unsigned mode,
565
        const struct object_id *oid,
566
        int oid_valid,
567
        const char *fullpath, unsigned dirty_submodule);
568
569
void diff_change(struct diff_options *,
570
     unsigned mode1, unsigned mode2,
571
     const struct object_id *old_oid,
572
     const struct object_id *new_oid,
573
     int old_oid_valid, int new_oid_valid,
574
     const char *fullpath,
575
     unsigned dirty_submodule1, unsigned dirty_submodule2);
576
577
void diff_same(struct diff_options *,
578
         unsigned mode,
579
         const struct object_id *oid,
580
         const char *fullpath);
581
582
struct diff_filepair *diff_unmerge(struct diff_options *, const char *path);
583
584
void compute_diffstat(struct diff_options *options, struct diffstat_t *diffstat,
585
          struct diff_queue_struct *q);
586
void free_diffstat_info(struct diffstat_t *diffstat);
587
588
#define DIFF_SETUP_REVERSE        1
589
#define DIFF_SETUP_USE_SIZE_CACHE 4
590
591
/*
592
 * Poor man's alternative to parse-option, to allow both stuck form
593
 * (--option=value) and separate form (--option value).
594
 */
595
int parse_long_opt(const char *opt, const char **argv,
596
       const char **optarg);
597
598
struct config_context;
599
int git_diff_basic_config(const char *var, const char *value,
600
        const struct config_context *ctx, void *cb);
601
int git_diff_heuristic_config(const char *var, const char *value, void *cb);
602
void init_diff_ui_defaults(void);
603
int git_diff_ui_config(const char *var, const char *value,
604
           const struct config_context *ctx, void *cb);
605
void repo_diff_setup(struct repository *, struct diff_options *);
606
struct option *add_diff_options(const struct option *, struct diff_options *);
607
int diff_opt_parse(struct diff_options *, const char **, int, const char *);
608
void diff_setup_done(struct diff_options *);
609
610
/*
611
 * Returns true if the pathspec can work with --follow mode. If die_on_error is
612
 * set, die() with a specific error message rather than returning false.
613
 */
614
int diff_check_follow_pathspec(struct pathspec *ps, int die_on_error);
615
616
int git_config_rename(const char *var, const char *value);
617
618
0
#define DIFF_DETECT_RENAME  1
619
0
#define DIFF_DETECT_COPY  2
620
621
0
#define DIFF_PICKAXE_ALL  1
622
0
#define DIFF_PICKAXE_REGEX  2
623
624
0
#define DIFF_PICKAXE_KIND_S 4 /* traditional plumbing counter */
625
0
#define DIFF_PICKAXE_KIND_G 8 /* grep in the patch */
626
0
#define DIFF_PICKAXE_KIND_OBJFIND 16 /* specific object IDs */
627
628
0
#define DIFF_PICKAXE_KINDS_MASK (DIFF_PICKAXE_KIND_S | \
629
0
         DIFF_PICKAXE_KIND_G | \
630
0
         DIFF_PICKAXE_KIND_OBJFIND)
631
#define DIFF_PICKAXE_KINDS_G_REGEX_MASK (DIFF_PICKAXE_KIND_G | \
632
           DIFF_PICKAXE_REGEX)
633
#define DIFF_PICKAXE_KINDS_ALL_OBJFIND_MASK (DIFF_PICKAXE_ALL | \
634
               DIFF_PICKAXE_KIND_OBJFIND)
635
636
0
#define DIFF_PICKAXE_IGNORE_CASE  32
637
638
void init_diffstat_widths(struct diff_options *);
639
void diffcore_std(struct diff_options *);
640
void diffcore_fix_diff_index(void);
641
642
#define COMMON_DIFF_OPTIONS_HELP \
643
"\ncommon diff options:\n" \
644
"  -z            output diff-raw with lines terminated with NUL.\n" \
645
"  -p            output patch format.\n" \
646
"  -u            synonym for -p.\n" \
647
"  --patch-with-raw\n" \
648
"                output both a patch and the diff-raw format.\n" \
649
"  --stat        show diffstat instead of patch.\n" \
650
"  --numstat     show numeric diffstat instead of patch.\n" \
651
"  --patch-with-stat\n" \
652
"                output a patch and prepend its diffstat.\n" \
653
"  --name-only   show only names of changed files.\n" \
654
"  --name-status show names and status of changed files.\n" \
655
"  --full-index  show full object name on index lines.\n" \
656
"  --abbrev=<n>  abbreviate object names in diff-tree header and diff-raw.\n" \
657
"  -R            swap input file pairs.\n" \
658
"  -B            detect complete rewrites.\n" \
659
"  -M            detect renames.\n" \
660
"  -C            detect copies.\n" \
661
"  --find-copies-harder\n" \
662
"                try unchanged files as candidate for copy detection.\n" \
663
"  -l<n>         limit rename attempts up to <n> paths.\n" \
664
"  -O<file>      reorder diffs according to the <file>.\n" \
665
"  -S<string>    find filepair whose only one side contains the string.\n" \
666
"  --pickaxe-all\n" \
667
"                show all files diff when -S is used and hit is found.\n" \
668
"  -a  --text    treat all files as text.\n"
669
670
int diff_queue_is_empty(struct diff_options *o);
671
void diff_flush(struct diff_options*);
672
void diff_free(struct diff_options*);
673
void diff_warn_rename_limit(const char *varname, int needed, int degraded_cc);
674
675
/* diff-raw status letters */
676
0
#define DIFF_STATUS_ADDED   'A'
677
0
#define DIFF_STATUS_COPIED    'C'
678
0
#define DIFF_STATUS_DELETED   'D'
679
0
#define DIFF_STATUS_MODIFIED    'M'
680
0
#define DIFF_STATUS_RENAMED   'R'
681
0
#define DIFF_STATUS_TYPE_CHANGED  'T'
682
0
#define DIFF_STATUS_UNKNOWN   'X'
683
0
#define DIFF_STATUS_UNMERGED    'U'
684
685
/* these are not diff-raw status letters proper, but used by
686
 * diffcore-filter insn to specify additional restrictions.
687
 */
688
0
#define DIFF_STATUS_FILTER_AON    '*'
689
0
#define DIFF_STATUS_FILTER_BROKEN 'B'
690
691
/*
692
 * This is different from repo_find_unique_abbrev() in that
693
 * it stuffs the result with dots for alignment.
694
 */
695
const char *diff_aligned_abbrev(const struct object_id *sha1, int);
696
697
void diff_get_merge_base(const struct rev_info *revs, struct object_id *mb);
698
699
/* do not report anything on removed paths */
700
#define DIFF_SILENT_ON_REMOVED 01
701
/* report racily-clean paths as modified */
702
0
#define DIFF_RACY_IS_MODIFIED 02
703
void run_diff_files(struct rev_info *revs, unsigned int option);
704
705
0
#define DIFF_INDEX_CACHED 01
706
0
#define DIFF_INDEX_MERGE_BASE 02
707
void run_diff_index(struct rev_info *revs, unsigned int option);
708
709
int do_diff_cache(const struct object_id *, struct diff_options *);
710
int diff_flush_patch_id(struct diff_options *, struct object_id *, int);
711
void flush_one_hunk(struct object_id *result, struct git_hash_ctx *ctx);
712
713
int diff_result_code(struct rev_info *);
714
715
int diff_no_index(struct rev_info *, const struct git_hash_algo *algop,
716
      int implicit_no_index, int, const char **);
717
718
int index_differs_from(struct repository *r, const char *def,
719
           const struct diff_flags *flags,
720
           int ita_invisible_in_index);
721
722
/*
723
 * Emit an interdiff of two object ID's to 'diff_options.file' optionally
724
 * indented by 'indent' spaces.
725
 */
726
void show_interdiff(const struct object_id *, const struct object_id *,
727
        int indent, struct diff_options *);
728
729
/*
730
 * Fill the contents of the filespec "df", respecting any textconv defined by
731
 * its userdiff driver.  The "driver" parameter must come from a
732
 * previous call to get_textconv(), and therefore should either be NULL or have
733
 * textconv enabled.
734
 *
735
 * Note that the memory ownership of the resulting buffer depends on whether
736
 * the driver field is NULL. If it is, then the memory belongs to the filespec
737
 * struct. If it is non-NULL, then "outbuf" points to a newly allocated buffer
738
 * that should be freed by the caller.
739
 */
740
size_t fill_textconv(struct repository *r,
741
         struct userdiff_driver *driver,
742
         struct diff_filespec *df,
743
         char **outbuf);
744
745
/*
746
 * Look up the userdiff driver for the given filespec, and return it if
747
 * and only if it has textconv enabled (otherwise return NULL). The result
748
 * can be passed to fill_textconv().
749
 */
750
struct userdiff_driver *get_textconv(struct repository *r,
751
             struct diff_filespec *one);
752
753
/*
754
 * Prepare diff_filespec and convert it using diff textconv API
755
 * if the textconv driver exists.
756
 * Return 1 if the conversion succeeds, 0 otherwise.
757
 */
758
int textconv_object(struct repository *repo,
759
        const char *path,
760
        unsigned mode,
761
        const struct object_id *oid, int oid_valid,
762
        char **buf, unsigned long *buf_size);
763
764
int parse_rename_score(const char **cp_p);
765
766
long parse_algorithm_value(const char *value);
767
768
void print_stat_summary(FILE *fp, int files,
769
      int insertions, int deletions);
770
void setup_diff_pager(struct diff_options *);
771
772
extern int diff_auto_refresh_index;
773
774
#endif /* DIFF_H */