diff options
author | Lukas Fleischer <cgit@cryptocrack.de> | 2013-08-14 17:50:31 (JST) |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2013-08-17 04:15:37 (JST) |
commit | 747b035dda97ae359ed00d84744acfa8cc009fb2 (patch) | |
tree | 145fa574deaaca9c5a3dc04855c582a3f89001c2 | |
parent | cf152604c3e28810d7e4c4a67b9814ab3e401cb0 (diff) | |
download | cgit-747b035dda97ae359ed00d84744acfa8cc009fb2.zip cgit-747b035dda97ae359ed00d84744acfa8cc009fb2.tar.gz |
Extract filepair_cb from ui-patch.c
Move filepair_cb() from ui-patch.c to ui-shared.c and rename it to
filepair_cb_raw(). This callback will be used in ui-diff.c in a
follow-up patch.
Note that it is not straightforward to extract filepair_cb() from
ui-diff.c which is why it is not done here as well.
Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
-rw-r--r-- | ui-patch.c | 74 | ||||
-rw-r--r-- | ui-shared.c | 72 | ||||
-rw-r--r-- | ui-shared.h | 1 |
3 files changed, 74 insertions, 73 deletions
@@ -11,78 +11,6 @@ | |||
11 | #include "html.h" | 11 | #include "html.h" |
12 | #include "ui-shared.h" | 12 | #include "ui-shared.h" |
13 | 13 | ||
14 | static 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 | |||
23 | static 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 | |||
64 | static 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 | |||
86 | void cgit_print_patch(char *hex, const char *prefix) | 14 | void 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); |
diff --git a/ui-shared.c b/ui-shared.c index 7ab2ab1..1e19421 100644 --- a/ui-shared.c +++ b/ui-shared.c | |||
@@ -950,3 +950,75 @@ void cgit_print_snapshot_links(const char *repo, const char *head, | |||
950 | } | 950 | } |
951 | strbuf_release(&filename); | 951 | strbuf_release(&filename); |
952 | } | 952 | } |
953 | |||
954 | static void print_line_raw(char *line, int len) | ||
955 | { | ||
956 | char c = line[len-1]; | ||
957 | |||
958 | line[len-1] = '\0'; | ||
959 | htmlf("%s\n", line); | ||
960 | line[len-1] = c; | ||
961 | } | ||
962 | |||
963 | static void header_raw(unsigned char *sha1, char *path1, int mode1, | ||
964 | unsigned char *sha2, char *path2, int mode2) | ||
965 | { | ||
966 | char *abbrev1, *abbrev2; | ||
967 | int subproject; | ||
968 | |||
969 | subproject = (S_ISGITLINK(mode1) || S_ISGITLINK(mode2)); | ||
970 | htmlf("diff --git a/%s b/%s\n", path1, path2); | ||
971 | |||
972 | if (mode1 == 0) | ||
973 | htmlf("new file mode %.6o\n", mode2); | ||
974 | |||
975 | if (mode2 == 0) | ||
976 | htmlf("deleted file mode %.6o\n", mode1); | ||
977 | |||
978 | if (!subproject) { | ||
979 | abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); | ||
980 | abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV)); | ||
981 | htmlf("index %s..%s", abbrev1, abbrev2); | ||
982 | free(abbrev1); | ||
983 | free(abbrev2); | ||
984 | if (mode1 != 0 && mode2 != 0) { | ||
985 | htmlf(" %.6o", mode1); | ||
986 | if (mode2 != mode1) | ||
987 | htmlf("..%.6o", mode2); | ||
988 | } | ||
989 | |||
990 | if (is_null_sha1(sha1)) { | ||
991 | path1 = "dev/null"; | ||
992 | htmlf("\n--- /%s\n", path1); | ||
993 | } else | ||
994 | htmlf("\n--- a/%s\n", path1); | ||
995 | |||
996 | if (is_null_sha1(sha2)) { | ||
997 | path2 = "dev/null"; | ||
998 | htmlf("+++ /%s\n", path2); | ||
999 | } else | ||
1000 | htmlf("+++ b/%s\n", path2); | ||
1001 | } | ||
1002 | } | ||
1003 | |||
1004 | void filepair_cb_raw(struct diff_filepair *pair) | ||
1005 | { | ||
1006 | unsigned long old_size = 0; | ||
1007 | unsigned long new_size = 0; | ||
1008 | int binary = 0; | ||
1009 | |||
1010 | header_raw(pair->one->sha1, pair->one->path, pair->one->mode, | ||
1011 | pair->two->sha1, pair->two->path, pair->two->mode); | ||
1012 | if (S_ISGITLINK(pair->one->mode) || S_ISGITLINK(pair->two->mode)) { | ||
1013 | if (S_ISGITLINK(pair->one->mode)) | ||
1014 | print_line_raw(fmt("-Subproject %s", sha1_to_hex(pair->one->sha1)), 52); | ||
1015 | if (S_ISGITLINK(pair->two->mode)) | ||
1016 | print_line_raw(fmt("+Subproject %s", sha1_to_hex(pair->two->sha1)), 52); | ||
1017 | return; | ||
1018 | } | ||
1019 | if (cgit_diff_files(pair->one->sha1, pair->two->sha1, &old_size, | ||
1020 | &new_size, &binary, 0, 0, print_line_raw)) | ||
1021 | html("Error running diff"); | ||
1022 | if (binary) | ||
1023 | html("Binary files differ\n"); | ||
1024 | } | ||
diff --git a/ui-shared.h b/ui-shared.h index 5987e77..a337dce 100644 --- a/ui-shared.h +++ b/ui-shared.h | |||
@@ -67,4 +67,5 @@ extern void cgit_print_snapshot_links(const char *repo, const char *head, | |||
67 | const char *hex, int snapshots); | 67 | const char *hex, int snapshots); |
68 | extern void cgit_add_hidden_formfields(int incl_head, int incl_search, | 68 | extern void cgit_add_hidden_formfields(int incl_head, int incl_search, |
69 | const char *page); | 69 | const char *page); |
70 | extern void filepair_cb_raw(struct diff_filepair *pair); | ||
70 | #endif /* UI_SHARED_H */ | 71 | #endif /* UI_SHARED_H */ |