Blob


1 /*
2 * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
3 *
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.
7 *
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.
15 */
17 /*
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 */
24 const struct got_error *got_diff_blob(struct got_blob_object *,
25 struct got_blob_object *, const char *, const char *, int, FILE *);
27 /*
28 * Compute the differences between a blob and a file and write unified diff
29 * text to the provided output file. The file's size must be provided, as
30 * well as a const char * diff header label which identifies the file.
31 * The number of context lines to show in the diff must be specified as well.
32 */
33 const struct got_error *got_diff_blob_file(struct got_blob_object *, FILE *,
34 size_t, const char *, int, FILE *);
36 /*
37 * A callback function invoked to handle the differences between two blobs
38 * when diffing trees with got_diff_tree(). This callback receives two blobs,
39 * their respective IDs, and two corresponding paths within the diffed trees.
40 * The first blob contains content from the old side of the diff, and
41 * the second blob contains content on the new side of the diff.
42 * The set of arguments relating to either blob may be NULL to indicate
43 * that no content is present on its respective side of the diff.
44 */
45 typedef const struct got_error *(*got_diff_blob_cb)(void *,
46 struct got_blob_object *, struct got_blob_object *,
47 struct got_object_id *, struct got_object_id *,
48 const char *, const char *, struct got_repository *);
50 /*
51 * A pre-defined implementation of got_diff_blob_cb() which appends unidiff
52 * output to a file. The caller must allocate and fill in the argument
53 * structure.
54 */
55 struct got_diff_blob_output_unidiff_arg {
56 FILE *outfile; /* Unidiff text will be written here. */
57 int diff_context; /* Sets the number of context lines. */
58 };
59 const struct got_error *got_diff_blob_output_unidiff(void *,
60 struct got_blob_object *, struct got_blob_object *,
61 struct got_object_id *, struct got_object_id *,
62 const char *, const char *, struct got_repository *);
64 /*
65 * Compute the differences between two trees and invoke the provided
66 * got_diff_blob_cb() callback when content differs.
67 */
68 const struct got_error *got_diff_tree(struct got_tree_object *,
69 struct got_tree_object *, const char *, const char *,
70 struct got_repository *, got_diff_blob_cb cb, void *cb_arg);
72 /*
73 * Diff two objects, assuming both objects are blobs. Two const char * diff
74 * header labels may be provided which will be used to identify each blob in
75 * the diff output. If a label is NULL, use the blob's SHA1 checksum instead.
76 * The number of context lines to show in the diff must be specified as well.
77 * Write unified diff text to the provided output FILE.
78 */
79 const struct got_error *got_diff_objects_as_blobs(struct got_object_id *,
80 struct got_object_id *, const char *, const char *, int,
81 struct got_repository *, FILE *);
83 /*
84 * Diff two objects, assuming both objects are trees. Two const char * diff
85 * header labels may be provided which will be used to identify each blob in
86 * the trees. If a label is NULL, use the blob's SHA1 checksum instead.
87 * The number of context lines to show in diffs must be specified.
88 * Write unified diff text to the provided output FILE.
89 */
90 const struct got_error *got_diff_objects_as_trees(struct got_object_id *,
91 struct got_object_id *, char *, char *, int, struct got_repository *, FILE *);
93 /*
94 * Diff two objects, assuming both objects are commits.
95 * The number of context lines to show in diffs must be specified.
96 * Write unified diff text to the provided output FILE.
97 */
98 const struct got_error *got_diff_objects_as_commits(struct got_object_id *,
99 struct got_object_id *, int, struct got_repository *, FILE *);
101 #define GOT_DIFF_MAX_CONTEXT 64