author | Lars Hjemli <hjemli@gmail.com> | 2007-05-15 07:27:27 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2007-05-15 07:27:27 (UTC) |
commit | c94afaacf4f996e3c983bcc150a2bacde2b00f20 (patch) (unidiff) | |
tree | 44cd81246b5f90f10da90d7186b6f24e9156d93c /ui-diff.c | |
parent | e903011c4457c24c0095f270ca5e78c40729434f (diff) | |
download | cgit-c94afaacf4f996e3c983bcc150a2bacde2b00f20.zip cgit-c94afaacf4f996e3c983bcc150a2bacde2b00f20.tar.gz cgit-c94afaacf4f996e3c983bcc150a2bacde2b00f20.tar.bz2 |
ui-diff: show /dev/null as filename for add/delete
The diff headers showed an invalid filename when a patch created or
deleted a file. Fix it.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
-rw-r--r-- | ui-diff.c | 5 |
1 files changed, 4 insertions, 1 deletions
@@ -1,102 +1,105 @@ | |||
1 | /* ui-diff.c: show diff between two blobs | 1 | /* ui-diff.c: show diff between two blobs |
2 | * | 2 | * |
3 | * Copyright (C) 2006 Lars Hjemli | 3 | * Copyright (C) 2006 Lars Hjemli |
4 | * | 4 | * |
5 | * Licensed under GNU General Public License v2 | 5 | * Licensed under GNU General Public License v2 |
6 | * (see COPYING for full license text) | 6 | * (see COPYING for full license text) |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include "cgit.h" | 9 | #include "cgit.h" |
10 | 10 | ||
11 | 11 | ||
12 | /* | 12 | /* |
13 | * print a single line returned from xdiff | 13 | * print a single line returned from xdiff |
14 | */ | 14 | */ |
15 | static void print_line(char *line, int len) | 15 | static void print_line(char *line, int len) |
16 | { | 16 | { |
17 | char *class = "ctx"; | 17 | char *class = "ctx"; |
18 | char c = line[len-1]; | 18 | char c = line[len-1]; |
19 | 19 | ||
20 | if (line[0] == '+') | 20 | if (line[0] == '+') |
21 | class = "add"; | 21 | class = "add"; |
22 | else if (line[0] == '-') | 22 | else if (line[0] == '-') |
23 | class = "del"; | 23 | class = "del"; |
24 | else if (line[0] == '@') | 24 | else if (line[0] == '@') |
25 | class = "hunk"; | 25 | class = "hunk"; |
26 | 26 | ||
27 | htmlf("<div class='%s'>", class); | 27 | htmlf("<div class='%s'>", class); |
28 | line[len-1] = '\0'; | 28 | line[len-1] = '\0'; |
29 | html_txt(line); | 29 | html_txt(line); |
30 | html("</div>"); | 30 | html("</div>"); |
31 | line[len-1] = c; | 31 | line[len-1] = c; |
32 | } | 32 | } |
33 | 33 | ||
34 | static void header(unsigned char *sha1, char *path1, | 34 | static void header(unsigned char *sha1, char *path1, |
35 | unsigned char *sha2, char *path2) | 35 | unsigned char *sha2, char *path2) |
36 | { | 36 | { |
37 | char *abbrev1, *abbrev2; | 37 | char *abbrev1, *abbrev2; |
38 | 38 | if (is_null_sha1(sha1)) | |
39 | path1 = "dev/null"; | ||
40 | if (is_null_sha1(sha2)) | ||
41 | path2 = "dev/null"; | ||
39 | html("<tr><td>"); | 42 | html("<tr><td>"); |
40 | html("<div class='head'>"); | 43 | html("<div class='head'>"); |
41 | html("diff --git a/"); | 44 | html("diff --git a/"); |
42 | html_txt(path1); | 45 | html_txt(path1); |
43 | html(" b/"); | 46 | html(" b/"); |
44 | html_txt(path2); | 47 | html_txt(path2); |
45 | abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); | 48 | abbrev1 = xstrdup(find_unique_abbrev(sha1, DEFAULT_ABBREV)); |
46 | abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV)); | 49 | abbrev2 = xstrdup(find_unique_abbrev(sha2, DEFAULT_ABBREV)); |
47 | htmlf("\nindex %s..%s", abbrev1, abbrev2); | 50 | htmlf("\nindex %s..%s", abbrev1, abbrev2); |
48 | free(abbrev1); | 51 | free(abbrev1); |
49 | free(abbrev2); | 52 | free(abbrev2); |
50 | html("\n--- a/"); | 53 | html("\n--- a/"); |
51 | html_txt(path1); | 54 | html_txt(path1); |
52 | html("\n+++ b/"); | 55 | html("\n+++ b/"); |
53 | html_txt(path2); | 56 | html_txt(path2); |
54 | html("</div>"); | 57 | html("</div>"); |
55 | } | 58 | } |
56 | 59 | ||
57 | static void filepair_cb(struct diff_filepair *pair) | 60 | static void filepair_cb(struct diff_filepair *pair) |
58 | { | 61 | { |
59 | header(pair->one->sha1, pair->one->path, | 62 | header(pair->one->sha1, pair->one->path, |
60 | pair->two->sha1, pair->two->path); | 63 | pair->two->sha1, pair->two->path); |
61 | if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line)) | 64 | if (cgit_diff_files(pair->one->sha1, pair->two->sha1, print_line)) |
62 | cgit_print_error("Error running diff"); | 65 | cgit_print_error("Error running diff"); |
63 | html("</tr></td>"); | 66 | html("</tr></td>"); |
64 | } | 67 | } |
65 | 68 | ||
66 | void cgit_print_diff(const char *old_hex, const char *new_hex, char *path) | 69 | void cgit_print_diff(const char *old_hex, const char *new_hex, char *path) |
67 | { | 70 | { |
68 | unsigned char sha1[20], sha2[20]; | 71 | unsigned char sha1[20], sha2[20]; |
69 | enum object_type type; | 72 | enum object_type type; |
70 | unsigned long size; | 73 | unsigned long size; |
71 | 74 | ||
72 | get_sha1(old_hex, sha1); | 75 | get_sha1(old_hex, sha1); |
73 | get_sha1(new_hex, sha2); | 76 | get_sha1(new_hex, sha2); |
74 | 77 | ||
75 | type = sha1_object_info(sha1, &size); | 78 | type = sha1_object_info(sha1, &size); |
76 | if (type == OBJ_BAD) { | 79 | if (type == OBJ_BAD) { |
77 | type = sha1_object_info(sha2, &size); | 80 | type = sha1_object_info(sha2, &size); |
78 | if (type == OBJ_BAD) { | 81 | if (type == OBJ_BAD) { |
79 | cgit_print_error(fmt("Bad object names: %s, %s", old_hex, new_hex)); | 82 | cgit_print_error(fmt("Bad object names: %s, %s", old_hex, new_hex)); |
80 | return; | 83 | return; |
81 | } | 84 | } |
82 | } | 85 | } |
83 | 86 | ||
84 | html("<table class='diff'>"); | 87 | html("<table class='diff'>"); |
85 | switch(type) { | 88 | switch(type) { |
86 | case OBJ_BLOB: | 89 | case OBJ_BLOB: |
87 | html("<tr><td>"); | 90 | html("<tr><td>"); |
88 | header(sha1, path, sha2, path); | 91 | header(sha1, path, sha2, path); |
89 | if (cgit_diff_files(sha1, sha2, print_line)) | 92 | if (cgit_diff_files(sha1, sha2, print_line)) |
90 | cgit_print_error("Error running diff"); | 93 | cgit_print_error("Error running diff"); |
91 | html("</tr></td>"); | 94 | html("</tr></td>"); |
92 | break; | 95 | break; |
93 | case OBJ_TREE: | 96 | case OBJ_TREE: |
94 | cgit_diff_tree(sha1, sha2, filepair_cb); | 97 | cgit_diff_tree(sha1, sha2, filepair_cb); |
95 | break; | 98 | break; |
96 | default: | 99 | default: |
97 | cgit_print_error(fmt("Unhandled object type: %s", | 100 | cgit_print_error(fmt("Unhandled object type: %s", |
98 | typename(type))); | 101 | typename(type))); |
99 | break; | 102 | break; |
100 | } | 103 | } |
101 | html("</td></tr></table>"); | 104 | html("</td></tr></table>"); |
102 | } | 105 | } |