Blame


1 7d283eee 2017-11-29 stsp /*
2 0c60ce5a 2018-04-02 stsp * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
3 7d283eee 2017-11-29 stsp *
4 7d283eee 2017-11-29 stsp * Permission to use, copy, modify, and distribute this software for any
5 7d283eee 2017-11-29 stsp * purpose with or without fee is hereby granted, provided that the above
6 7d283eee 2017-11-29 stsp * copyright notice and this permission notice appear in all copies.
7 7d283eee 2017-11-29 stsp *
8 7d283eee 2017-11-29 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 7d283eee 2017-11-29 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 7d283eee 2017-11-29 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 7d283eee 2017-11-29 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 7d283eee 2017-11-29 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 7d283eee 2017-11-29 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 7d283eee 2017-11-29 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 7d283eee 2017-11-29 stsp */
16 7d283eee 2017-11-29 stsp
17 0c60ce5a 2018-04-02 stsp /*
18 0c60ce5a 2018-04-02 stsp * Compute the differences between two blobs and write unified diff text
19 0c60ce5a 2018-04-02 stsp * to the provided output FILE. Two const char * diff header labels may
20 0c60ce5a 2018-04-02 stsp * be provided which will be used to identify each blob in the diff output.
21 0c60ce5a 2018-04-02 stsp * If a label is NULL, use the blob's SHA1 checksum instead.
22 df2871d2 2018-10-18 stsp * The number of context lines to show in the diff must be specified as well.
23 63035f9f 2019-10-06 stsp * Whitespace differences may optionally be ignored.
24 0c60ce5a 2018-04-02 stsp */
25 ed9e98a8 2017-11-29 stsp const struct got_error *got_diff_blob(struct got_blob_object *,
26 63035f9f 2019-10-06 stsp struct got_blob_object *, const char *, const char *, int, int, FILE *);
27 0c60ce5a 2018-04-02 stsp
28 0c60ce5a 2018-04-02 stsp /*
29 b72f483a 2019-02-05 stsp * Compute the differences between a blob and a file and write unified diff
30 b72f483a 2019-02-05 stsp * text to the provided output file. The file's size must be provided, as
31 b72f483a 2019-02-05 stsp * well as a const char * diff header label which identifies the file.
32 4ce46740 2019-08-08 stsp * An optional const char * diff header label for the blob may be provided, too.
33 b72f483a 2019-02-05 stsp * The number of context lines to show in the diff must be specified as well.
34 63035f9f 2019-10-06 stsp * Whitespace differences may optionally be ignored.
35 b72f483a 2019-02-05 stsp */
36 4ce46740 2019-08-08 stsp const struct got_error *got_diff_blob_file(struct got_blob_object *,
37 63035f9f 2019-10-06 stsp const char *, FILE *, size_t, const char *, int, int, FILE *);
38 b72f483a 2019-02-05 stsp
39 b72f483a 2019-02-05 stsp /*
40 aaa13589 2019-06-01 stsp * A callback function invoked to handle the differences between two blobs
41 aaa13589 2019-06-01 stsp * when diffing trees with got_diff_tree(). This callback receives two blobs,
42 aaa13589 2019-06-01 stsp * their respective IDs, and two corresponding paths within the diffed trees.
43 aaa13589 2019-06-01 stsp * The first blob contains content from the old side of the diff, and
44 aaa13589 2019-06-01 stsp * the second blob contains content on the new side of the diff.
45 aaa13589 2019-06-01 stsp * The set of arguments relating to either blob may be NULL to indicate
46 aaa13589 2019-06-01 stsp * that no content is present on its respective side of the diff.
47 46f68b20 2019-10-19 stsp * File modes from relevant tree objects which contain the blobs may
48 46f68b20 2019-10-19 stsp * also be passed. These will be zero if not available.
49 0c60ce5a 2018-04-02 stsp */
50 aaa13589 2019-06-01 stsp typedef const struct got_error *(*got_diff_blob_cb)(void *,
51 aaa13589 2019-06-01 stsp struct got_blob_object *, struct got_blob_object *,
52 aaa13589 2019-06-01 stsp struct got_object_id *, struct got_object_id *,
53 46f68b20 2019-10-19 stsp const char *, const char *, mode_t, mode_t, struct got_repository *);
54 aaa13589 2019-06-01 stsp
55 aaa13589 2019-06-01 stsp /*
56 aaa13589 2019-06-01 stsp * A pre-defined implementation of got_diff_blob_cb() which appends unidiff
57 aaa13589 2019-06-01 stsp * output to a file. The caller must allocate and fill in the argument
58 aaa13589 2019-06-01 stsp * structure.
59 aaa13589 2019-06-01 stsp */
60 aaa13589 2019-06-01 stsp struct got_diff_blob_output_unidiff_arg {
61 aaa13589 2019-06-01 stsp FILE *outfile; /* Unidiff text will be written here. */
62 aaa13589 2019-06-01 stsp int diff_context; /* Sets the number of context lines. */
63 63035f9f 2019-10-06 stsp int ignore_whitespace; /* Ignore whitespace differences. */
64 aaa13589 2019-06-01 stsp };
65 aaa13589 2019-06-01 stsp const struct got_error *got_diff_blob_output_unidiff(void *,
66 aaa13589 2019-06-01 stsp struct got_blob_object *, struct got_blob_object *,
67 aaa13589 2019-06-01 stsp struct got_object_id *, struct got_object_id *,
68 46f68b20 2019-10-19 stsp const char *, const char *, mode_t, mode_t, struct got_repository *);
69 aaa13589 2019-06-01 stsp
70 aaa13589 2019-06-01 stsp /*
71 aaa13589 2019-06-01 stsp * Compute the differences between two trees and invoke the provided
72 aaa13589 2019-06-01 stsp * got_diff_blob_cb() callback when content differs.
73 31b4484f 2019-07-27 stsp * Diffing of blob content can be suppressed by passing zero for the
74 31b4484f 2019-07-27 stsp * 'diff_content' parameter. The callback will then only receive blob
75 31b4484f 2019-07-27 stsp * object IDs and diff labels, but NULL pointers instead of blob objects.
76 aaa13589 2019-06-01 stsp */
77 474b4f94 2017-11-30 stsp const struct got_error *got_diff_tree(struct got_tree_object *,
78 aaa13589 2019-06-01 stsp struct got_tree_object *, const char *, const char *,
79 31b4484f 2019-07-27 stsp struct got_repository *, got_diff_blob_cb cb, void *cb_arg, int);
80 11528a82 2018-05-19 stsp
81 11528a82 2018-05-19 stsp /*
82 f6861a81 2018-09-13 stsp * Diff two objects, assuming both objects are blobs. Two const char * diff
83 f6861a81 2018-09-13 stsp * header labels may be provided which will be used to identify each blob in
84 f6861a81 2018-09-13 stsp * the diff output. If a label is NULL, use the blob's SHA1 checksum instead.
85 df2871d2 2018-10-18 stsp * The number of context lines to show in the diff must be specified as well.
86 11528a82 2018-05-19 stsp * Write unified diff text to the provided output FILE.
87 11528a82 2018-05-19 stsp */
88 15a94983 2018-12-23 stsp const struct got_error *got_diff_objects_as_blobs(struct got_object_id *,
89 63035f9f 2019-10-06 stsp struct got_object_id *, const char *, const char *, int, int,
90 54156555 2018-12-24 stsp struct got_repository *, FILE *);
91 11528a82 2018-05-19 stsp
92 11528a82 2018-05-19 stsp /*
93 f6861a81 2018-09-13 stsp * Diff two objects, assuming both objects are trees. Two const char * diff
94 f6861a81 2018-09-13 stsp * header labels may be provided which will be used to identify each blob in
95 f6861a81 2018-09-13 stsp * the trees. If a label is NULL, use the blob's SHA1 checksum instead.
96 df2871d2 2018-10-18 stsp * The number of context lines to show in diffs must be specified.
97 11528a82 2018-05-19 stsp * Write unified diff text to the provided output FILE.
98 11528a82 2018-05-19 stsp */
99 15a94983 2018-12-23 stsp const struct got_error *got_diff_objects_as_trees(struct got_object_id *,
100 63035f9f 2019-10-06 stsp struct got_object_id *, char *, char *, int, int,
101 63035f9f 2019-10-06 stsp struct got_repository *, FILE *);
102 11528a82 2018-05-19 stsp
103 11528a82 2018-05-19 stsp /*
104 11528a82 2018-05-19 stsp * Diff two objects, assuming both objects are commits.
105 df2871d2 2018-10-18 stsp * The number of context lines to show in diffs must be specified.
106 11528a82 2018-05-19 stsp * Write unified diff text to the provided output FILE.
107 11528a82 2018-05-19 stsp */
108 15a94983 2018-12-23 stsp const struct got_error *got_diff_objects_as_commits(struct got_object_id *,
109 63035f9f 2019-10-06 stsp struct got_object_id *, int, int, struct got_repository *, FILE *);
110 4a8520aa 2018-10-18 stsp
111 4a8520aa 2018-10-18 stsp #define GOT_DIFF_MAX_CONTEXT 64