stagit

detect binary diff, comment index + delta header for now (broken)

Hiltjo Posthuma contact@arjunchoudhary.com

commit: 9426932 parent: a2d1a95
1 files changed, 25 insertions(+), 11 deletions(-)
Murmoms.c+25-11
M · urmoms.c +25, -11
 1@@ -257,19 +257,33 @@ printshowfile(git_commit *commit)
 2 			relpath, delta->old_file.path, delta->old_file.path,
 3 			relpath, delta->new_file.path, delta->new_file.path);
 4 
 5-		/* TODO: add --- and +++ lines */
 6+		/* TODO: "new file mode <mode>". */
 7+		/* TODO: add indexfrom...indexto + flags */
 8 
 9 #if 0
10-		switch (delta->flags) {
11-		case GIT_DIFF_FLAG_BINARY:
12-			/* "Binary files /dev/null and b/favicon.png differ" or so */
13-			continue; /* TODO: binary data */
14-		case GIT_DIFF_FLAG_NOT_BINARY:   break;
15-		case GIT_DIFF_FLAG_VALID_ID:     break; /* TODO: check */
16-		case GIT_DIFF_FLAG_EXISTS:       break; /* TODO: check */
17-		}
18+		fputs("<b>--- ", fp);
19+		if (delta->status & GIT_DELTA_ADDED)
20+			fputs("/dev/null", fp);
21+		else
22+			fprintf(fp, "a/<a href=\"%sfile/%s\">%s</a>",
23+				relpath, delta->old_file.path, delta->old_file.path);
24+
25+		fputs("\n+++ ", fp);
26+		if (delta->status & GIT_DELTA_DELETED)
27+			fputs("/dev/null", fp);
28+		else
29+			fprintf(fp, "b/<a href=\"%sfile/%s\">%s</a>",
30+				relpath, delta->new_file.path, delta->new_file.path);
31+		fputs("</b>\n", fp);
32 #endif
33 
34+		/* check binary data */
35+		if (delta->flags & GIT_DIFF_FLAG_BINARY) {
36+			fputs("Binary files differ\n", fp);
37+			git_patch_free(patch);
38+			continue;
39+		}
40+
41 		nhunks = git_patch_num_hunks(patch);
42 		for (j = 0; j < nhunks; j++) {
43 			if (git_patch_get_hunk(&hunk, &nhunklines, patch, j))
44@@ -333,8 +347,8 @@ writelog(FILE *fp)
45 	      "<td align=\"right\">Files</td><td align=\"right\">+</td><td align=\"right\">-</td></tr>\n</thead><tbody>\n", fp);
46 	while (!git_revwalk_next(&id, w)) {
47 		/* DEBUG */
48-		if (i++ > 100)
49-			break;
50+/*		if (i++ > 100)
51+			break;*/
52 
53 		relpath = "";
54