2 * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 * Compute the differences between two blobs and write unified diff text
19 * to the provided output FILE. Two const char * diff header labels may
20 * be provided which will be used to identify each blob in the diff output.
21 * If a label is NULL, use the blob's SHA1 checksum instead.
22 * The number of context lines to show in the diff must be specified as well.
23 * Whitespace differences may optionally be ignored.
24 * If not NULL, the two initial output arguments will be populated with an
25 * array of line offsets for, and the number of lines in, the unidiff text.
27 const struct got_error *got_diff_blob(off_t **, size_t *,
28 struct got_blob_object *, struct got_blob_object *,
29 const char *, const char *, int, int, int, FILE *);
32 * Compute the differences between a blob and a file and write unified diff
33 * text to the provided output file. The file's size must be provided, as
34 * well as a const char * diff header label which identifies the file.
35 * An optional const char * diff header label for the blob may be provided, too.
36 * The number of context lines to show in the diff must be specified as well.
37 * Whitespace differences may optionally be ignored.
39 const struct got_error *got_diff_blob_file(struct got_blob_object *,
40 const char *, FILE *, size_t, const char *, int, int, int, FILE *);
43 * A callback function invoked to handle the differences between two blobs
44 * when diffing trees with got_diff_tree(). This callback receives two blobs,
45 * their respective IDs, and two corresponding paths within the diffed trees.
46 * The first blob contains content from the old side of the diff, and
47 * the second blob contains content on the new side of the diff.
48 * The set of arguments relating to either blob may be NULL to indicate
49 * that no content is present on its respective side of the diff.
50 * File modes from relevant tree objects which contain the blobs may
51 * also be passed. These will be zero if not available.
53 typedef const struct got_error *(*got_diff_blob_cb)(void *,
54 struct got_blob_object *, struct got_blob_object *,
55 struct got_object_id *, struct got_object_id *,
56 const char *, const char *, mode_t, mode_t, struct got_repository *);
59 * A pre-defined implementation of got_diff_blob_cb() which appends unidiff
60 * output to a file. The caller must allocate and fill in the argument
63 struct got_diff_blob_output_unidiff_arg {
64 FILE *outfile; /* Unidiff text will be written here. */
65 int diff_context; /* Sets the number of context lines. */
66 int ignore_whitespace; /* Ignore whitespace differences. */
67 int force_text_diff; /* Assume text even if binary data detected. */
70 * The number of lines contained in produced unidiff text output,
71 * and an array of byte offsets to each line. May be initialized to
72 * zero and NULL to ignore line offsets. If not NULL, then the line
73 * offsets array will be populated. Optionally, the array can be
74 * pre-populated with line offsets, with nlines > 0 indicating
75 * the length of the pre-populated array. This is useful if the
76 * output file already contains some lines of text.
77 * The array will be grown as needed to accomodate additional line
78 * offsets, and the last offset found in a pre-populated array will
79 * be added to all subsequent offsets.
82 off_t *line_offsets; /* Dispose of with free(3) when done. */
84 const struct got_error *got_diff_blob_output_unidiff(void *,
85 struct got_blob_object *, struct got_blob_object *,
86 struct got_object_id *, struct got_object_id *,
87 const char *, const char *, mode_t, mode_t, struct got_repository *);
90 * Compute the differences between two trees and invoke the provided
91 * got_diff_blob_cb() callback when content differs.
92 * Diffing of blob content can be suppressed by passing zero for the
93 * 'diff_content' parameter. The callback will then only receive blob
94 * object IDs and diff labels, but NULL pointers instead of blob objects.
96 const struct got_error *got_diff_tree(struct got_tree_object *,
97 struct got_tree_object *, const char *, const char *,
98 struct got_repository *, got_diff_blob_cb cb, void *cb_arg, int);
101 * A pre-defined implementation of got_diff_blob_cb() which collects a list
102 * of file paths that differ between two trees.
103 * The caller must allocate and initialize a got_pathlist_head * argument.
104 * Data pointers of entries added to the path list will point to a struct
105 * got_diff_changed_path object.
106 * The caller is expected to free both the path and data pointers of all
107 * entries on the path list.
109 struct got_diff_changed_path {
111 * The modification status of this path. It can be GOT_STATUS_ADD,
112 * GOT_STATUS_DELETE, GOT_STATUS_MODIFY, or GOT_STATUS_MODE_CHANGE.
116 const struct got_error *got_diff_tree_collect_changed_paths(void *,
117 struct got_blob_object *, struct got_blob_object *,
118 struct got_object_id *, struct got_object_id *,
119 const char *, const char *, mode_t, mode_t, struct got_repository *);
122 * Diff two objects, assuming both objects are blobs. Two const char * diff
123 * header labels may be provided which will be used to identify each blob in
124 * the diff output. If a label is NULL, use the blob's SHA1 checksum instead.
125 * The number of context lines to show in the diff must be specified as well.
126 * Write unified diff text to the provided output FILE.
127 * If not NULL, the two initial output arguments will be populated with an
128 * array of line offsets for, and the number of lines in, the unidiff text.
130 const struct got_error *got_diff_objects_as_blobs(off_t **, size_t *,
131 struct got_object_id *, struct got_object_id *,
132 const char *, const char *, int, int, int,
133 struct got_repository *, FILE *);
136 * Diff two objects, assuming both objects are trees. Two const char * diff
137 * header labels may be provided which will be used to identify each blob in
138 * the trees. If a label is NULL, use the blob's SHA1 checksum instead.
139 * The number of context lines to show in diffs must be specified.
140 * Write unified diff text to the provided output FILE.
141 * If not NULL, the two initial output arguments will be populated with an
142 * array of line offsets for, and the number of lines in, the unidiff text.
144 const struct got_error *got_diff_objects_as_trees(off_t **, size_t *,
145 struct got_object_id *, struct got_object_id *, struct got_pathlist_head *,
146 char *, char *, int, int, int, struct got_repository *, FILE *);
149 * Diff two objects, assuming both objects are commits.
150 * The number of context lines to show in diffs must be specified.
151 * Write unified diff text to the provided output FILE.
152 * If not NULL, the two initial output arguments will be populated with an
153 * array of line offsets for, and the number of lines in, the unidiff text.
155 const struct got_error *got_diff_objects_as_commits(off_t **, size_t *,
156 struct got_object_id *, struct got_object_id *, struct got_pathlist_head *,
157 int, int, int, struct got_repository *, FILE *);
159 #define GOT_DIFF_MAX_CONTEXT 64