aboutsummaryrefslogtreecommitdiffstats
path: root/ui-patch.c
diff options
context:
space:
mode:
Diffstat (limited to 'ui-patch.c')
-rw-r--r--ui-patch.c74
1 files changed, 1 insertions, 73 deletions
diff --git a/ui-patch.c b/ui-patch.c
index fbb92cc..3922a44 100644
--- a/ui-patch.c
+++ b/ui-patch.c
@@ -11,78 +11,6 @@
11#include "html.h" 11#include "html.h"
12#include "ui-shared.h" 12#include "ui-shared.h"
13 13
14static void print_line(char *line, int len)
15{
16 char c = line[len-1];
17
18 line[len-1] = '\0';
19 htmlf("%s\n", line);
20 line[len-1] = c;
21}
22
23static void header(unsigned char *sha1, char *path1, int mode1,
24 unsigned char *sha2, char *path2, int mode2)
25{
26 char *abbrev1, *abbrev2;
27 int subproject;
28
29 subproject = (S_ISGITLINK(mode1) || S_ISGITLINK(mode2));
30 htmlf("diff --git a/%s b/%s\n", path1, path2);
31
32 if (mode1 == 0)
33 htmlf("new file mode %.6o\n", mode2);
34
35 if (mode2 == 0)
36 htmlf("deleted file mode %.6o\n", mode1);
37
38 if (!subproject) {
39 abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV));
40 abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV));
41 htmlf("index %s..%s", abbrev1, abbrev2);
42 free(abbrev1);
43 free(abbrev2);
44 if (mode1 != 0 && mode2 != 0) {
45 htmlf(" %.6o", mode1);
46 if (mode2 != mode1)
47 htmlf("..%.6o", mode2);
48 }
49
50 if (is_null_sha1(sha1)) {
51 path1 = "dev/null";
52 htmlf("\n--- /%s\n", path1);
53 } else
54 htmlf("\n--- a/%s\n", path1);
55
56 if (is_null_sha1(sha2)) {
57 path2 = "dev/null";
58 htmlf("+++ /%s\n", path2);
59 } else
60 htmlf("+++ b/%s\n", path2);
61 }
62}
63
64static void filepair_cb(struct diff_filepair *pair)
65{
66 unsigned long old_size = 0;
67 unsigned long new_size = 0;
68 int binary = 0;
69
70 header(pair->one->sha1, pair->one->path, pair->one->mode,
71 pair->two->sha1, pair->two->path, pair->two->mode);
72 if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) {
73 if (S_ISGITLINK(pair->one->mode))
74 print_line(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52);
75 if (S_ISGITLINK(pair->two->mode))
76 print_line(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52);
77 return;
78 }
79 if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size,
80 &new_size, &binary, 0, 0, print_line))
81 html("Error running diff");
82 if (binary)
83 html("Binary files differ\n");
84}
85
86void cgit_print_patch(char *hex, const char *prefix) 14void cgit_print_patch(char *hex, const char *prefix)
87{ 15{
88 struct commit *commit; 16 struct commit *commit;
@@ -130,7 +58,7 @@ void cgit_print_patch(char *hex, const char *prefix)
130 html("---\n"); 58 html("---\n");
131 if (prefix) 59 if (prefix)
132 htmlf("(limited to '%s')\n\n", prefix); 60 htmlf("(limited to '%s')\n\n", prefix);
133 cgit_diff_tree(old_sha1, sha1, filepair_cb, prefix, 0); 61 cgit_diff_tree(old_sha1, sha1, filepair_cb_raw, prefix, 0);
134 html("--\n"); 62 html("--\n");
135 htmlf("cgit %s\n", cgit_version); 63 htmlf("cgit %s\n", cgit_version);
136 cgit_free_commitinfo(info); 64 cgit_free_commitinfo(info);