author | Lars Hjemli <hjemli@gmail.com> | 2008-01-13 18:16:23 (UTC) |
---|---|---|
committer | Lars Hjemli <hjemli@gmail.com> | 2008-01-21 07:52:09 (UTC) |
commit | 776200b1c10536174f68fc6599fc709ae620db54 (patch) (unidiff) | |
tree | d5b24090675c5ac7b0ca29459d3246dcb0d7c8af | |
parent | 2122c696a34133a616b9ec6d72abe9eb89e728aa (diff) | |
download | cgit-776200b1c10536174f68fc6599fc709ae620db54.zip cgit-776200b1c10536174f68fc6599fc709ae620db54.tar.gz cgit-776200b1c10536174f68fc6599fc709ae620db54.tar.bz2 |
Use GIT-1.5.4.rc4
-rw-r--r-- | Makefile | 2 | ||||
m--------- | git | 0 | ||||
-rw-r--r-- | shared.c | 2 |
3 files changed, 2 insertions, 2 deletions
@@ -1,83 +1,83 @@ | |||
1 | CGIT_VERSION = v0.7.2 | 1 | CGIT_VERSION = v0.7.2 |
2 | CGIT_SCRIPT_NAME = cgit.cgi | 2 | CGIT_SCRIPT_NAME = cgit.cgi |
3 | CGIT_SCRIPT_PATH = /var/www/htdocs/cgit | 3 | CGIT_SCRIPT_PATH = /var/www/htdocs/cgit |
4 | CGIT_CONFIG = /etc/cgitrc | 4 | CGIT_CONFIG = /etc/cgitrc |
5 | CACHE_ROOT = /var/cache/cgit | 5 | CACHE_ROOT = /var/cache/cgit |
6 | SHA1_HEADER = <openssl/sha.h> | 6 | SHA1_HEADER = <openssl/sha.h> |
7 | GIT_VER = 1.5.3.8 | 7 | GIT_VER = 1.5.4.rc4 |
8 | GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2 | 8 | GIT_URL = http://www.kernel.org/pub/software/scm/git/git-$(GIT_VER).tar.bz2 |
9 | 9 | ||
10 | # | 10 | # |
11 | # Let the user override the above settings. | 11 | # Let the user override the above settings. |
12 | # | 12 | # |
13 | -include cgit.conf | 13 | -include cgit.conf |
14 | 14 | ||
15 | 15 | ||
16 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto | 16 | EXTLIBS = git/libgit.a git/xdiff/lib.a -lz -lcrypto |
17 | OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ | 17 | OBJECTS = shared.o cache.o parsing.o html.o ui-shared.o ui-repolist.o \ |
18 | ui-summary.o ui-log.o ui-tree.o ui-commit.o ui-diff.o \ | 18 | ui-summary.o ui-log.o ui-tree.o ui-commit.o ui-diff.o \ |
19 | ui-snapshot.o ui-blob.o ui-tag.o ui-refs.o ui-patch.o | 19 | ui-snapshot.o ui-blob.o ui-tag.o ui-refs.o ui-patch.o |
20 | 20 | ||
21 | 21 | ||
22 | ifdef NEEDS_LIBICONV | 22 | ifdef NEEDS_LIBICONV |
23 | EXTLIBS += -liconv | 23 | EXTLIBS += -liconv |
24 | endif | 24 | endif |
25 | 25 | ||
26 | 26 | ||
27 | .PHONY: all git test install clean distclean emptycache force-version get-git | 27 | .PHONY: all git test install clean distclean emptycache force-version get-git |
28 | 28 | ||
29 | all: cgit git | 29 | all: cgit git |
30 | 30 | ||
31 | VERSION: force-version | 31 | VERSION: force-version |
32 | @./gen-version.sh "$(CGIT_VERSION)" | 32 | @./gen-version.sh "$(CGIT_VERSION)" |
33 | -include VERSION | 33 | -include VERSION |
34 | 34 | ||
35 | 35 | ||
36 | CFLAGS += -g -Wall -Igit | 36 | CFLAGS += -g -Wall -Igit |
37 | CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' | 37 | CFLAGS += -DSHA1_HEADER='$(SHA1_HEADER)' |
38 | CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' | 38 | CFLAGS += -DCGIT_VERSION='"$(CGIT_VERSION)"' |
39 | CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' | 39 | CFLAGS += -DCGIT_CONFIG='"$(CGIT_CONFIG)"' |
40 | CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' | 40 | CFLAGS += -DCGIT_SCRIPT_NAME='"$(CGIT_SCRIPT_NAME)"' |
41 | CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' | 41 | CFLAGS += -DCGIT_CACHE_ROOT='"$(CACHE_ROOT)"' |
42 | 42 | ||
43 | 43 | ||
44 | cgit: cgit.c $(OBJECTS) | 44 | cgit: cgit.c $(OBJECTS) |
45 | $(CC) $(CFLAGS) cgit.c -o cgit $(OBJECTS) $(EXTLIBS) | 45 | $(CC) $(CFLAGS) cgit.c -o cgit $(OBJECTS) $(EXTLIBS) |
46 | 46 | ||
47 | $(OBJECTS): cgit.h git/xdiff/lib.a git/libgit.a VERSION | 47 | $(OBJECTS): cgit.h git/xdiff/lib.a git/libgit.a VERSION |
48 | 48 | ||
49 | git/xdiff/lib.a: | git | 49 | git/xdiff/lib.a: | git |
50 | 50 | ||
51 | git/libgit.a: | git | 51 | git/libgit.a: | git |
52 | 52 | ||
53 | git: | 53 | git: |
54 | cd git && $(MAKE) xdiff/lib.a | 54 | cd git && $(MAKE) xdiff/lib.a |
55 | cd git && $(MAKE) libgit.a | 55 | cd git && $(MAKE) libgit.a |
56 | 56 | ||
57 | test: all | 57 | test: all |
58 | $(MAKE) -C tests | 58 | $(MAKE) -C tests |
59 | 59 | ||
60 | install: all | 60 | install: all |
61 | mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH) | 61 | mkdir -p $(DESTDIR)$(CGIT_SCRIPT_PATH) |
62 | install cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) | 62 | install cgit $(DESTDIR)$(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) |
63 | install cgit.css $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.css | 63 | install cgit.css $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.css |
64 | install cgit.png $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.png | 64 | install cgit.png $(DESTDIR)$(CGIT_SCRIPT_PATH)/cgit.png |
65 | 65 | ||
66 | uninstall: | 66 | uninstall: |
67 | rm -f $(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) | 67 | rm -f $(CGIT_SCRIPT_PATH)/$(CGIT_SCRIPT_NAME) |
68 | rm -f $(CGIT_SCRIPT_PATH)/cgit.css | 68 | rm -f $(CGIT_SCRIPT_PATH)/cgit.css |
69 | rm -f $(CGIT_SCRIPT_PATH)/cgit.png | 69 | rm -f $(CGIT_SCRIPT_PATH)/cgit.png |
70 | 70 | ||
71 | clean: | 71 | clean: |
72 | rm -f cgit VERSION *.o | 72 | rm -f cgit VERSION *.o |
73 | cd git && $(MAKE) clean | 73 | cd git && $(MAKE) clean |
74 | 74 | ||
75 | distclean: clean | 75 | distclean: clean |
76 | git clean -d -x | 76 | git clean -d -x |
77 | cd git && git clean -d -x | 77 | cd git && git clean -d -x |
78 | 78 | ||
79 | emptycache: | 79 | emptycache: |
80 | rm -rf $(DESTDIR)$(CACHE_ROOT)/* | 80 | rm -rf $(DESTDIR)$(CACHE_ROOT)/* |
81 | 81 | ||
82 | get-git: | 82 | get-git: |
83 | curl $(GIT_URL) | tar -xj && rm -rf git && mv git-$(GIT_VER) git | 83 | curl $(GIT_URL) | tar -xj && rm -rf git && mv git-$(GIT_VER) git |
diff --git a/git b/git | |||
Subproject aadd4efa715f56e0eac5ac459c8ff4933b56d4c | Subproject ce33288ea6b81a2f4f5aecd72177bcc8174562a | ||
@@ -239,283 +239,283 @@ void cgit_global_config_cb(const char *name, const char *value) | |||
239 | void cgit_querystring_cb(const char *name, const char *value) | 239 | void cgit_querystring_cb(const char *name, const char *value) |
240 | { | 240 | { |
241 | if (!strcmp(name,"r")) { | 241 | if (!strcmp(name,"r")) { |
242 | cgit_query_repo = xstrdup(value); | 242 | cgit_query_repo = xstrdup(value); |
243 | cgit_repo = cgit_get_repoinfo(value); | 243 | cgit_repo = cgit_get_repoinfo(value); |
244 | } else if (!strcmp(name, "p")) { | 244 | } else if (!strcmp(name, "p")) { |
245 | cgit_query_page = xstrdup(value); | 245 | cgit_query_page = xstrdup(value); |
246 | cgit_cmd = cgit_get_cmd_index(value); | 246 | cgit_cmd = cgit_get_cmd_index(value); |
247 | } else if (!strcmp(name, "url")) { | 247 | } else if (!strcmp(name, "url")) { |
248 | cgit_parse_url(value); | 248 | cgit_parse_url(value); |
249 | } else if (!strcmp(name, "qt")) { | 249 | } else if (!strcmp(name, "qt")) { |
250 | cgit_query_grep = xstrdup(value); | 250 | cgit_query_grep = xstrdup(value); |
251 | } else if (!strcmp(name, "q")) { | 251 | } else if (!strcmp(name, "q")) { |
252 | cgit_query_search = xstrdup(value); | 252 | cgit_query_search = xstrdup(value); |
253 | } else if (!strcmp(name, "h")) { | 253 | } else if (!strcmp(name, "h")) { |
254 | cgit_query_head = xstrdup(value); | 254 | cgit_query_head = xstrdup(value); |
255 | cgit_query_has_symref = 1; | 255 | cgit_query_has_symref = 1; |
256 | } else if (!strcmp(name, "id")) { | 256 | } else if (!strcmp(name, "id")) { |
257 | cgit_query_sha1 = xstrdup(value); | 257 | cgit_query_sha1 = xstrdup(value); |
258 | cgit_query_has_sha1 = 1; | 258 | cgit_query_has_sha1 = 1; |
259 | } else if (!strcmp(name, "id2")) { | 259 | } else if (!strcmp(name, "id2")) { |
260 | cgit_query_sha2 = xstrdup(value); | 260 | cgit_query_sha2 = xstrdup(value); |
261 | cgit_query_has_sha1 = 1; | 261 | cgit_query_has_sha1 = 1; |
262 | } else if (!strcmp(name, "ofs")) { | 262 | } else if (!strcmp(name, "ofs")) { |
263 | cgit_query_ofs = atoi(value); | 263 | cgit_query_ofs = atoi(value); |
264 | } else if (!strcmp(name, "path")) { | 264 | } else if (!strcmp(name, "path")) { |
265 | cgit_query_path = trim_end(value, '/'); | 265 | cgit_query_path = trim_end(value, '/'); |
266 | } else if (!strcmp(name, "name")) { | 266 | } else if (!strcmp(name, "name")) { |
267 | cgit_query_name = xstrdup(value); | 267 | cgit_query_name = xstrdup(value); |
268 | } | 268 | } |
269 | } | 269 | } |
270 | 270 | ||
271 | void *cgit_free_commitinfo(struct commitinfo *info) | 271 | void *cgit_free_commitinfo(struct commitinfo *info) |
272 | { | 272 | { |
273 | free(info->author); | 273 | free(info->author); |
274 | free(info->author_email); | 274 | free(info->author_email); |
275 | free(info->committer); | 275 | free(info->committer); |
276 | free(info->committer_email); | 276 | free(info->committer_email); |
277 | free(info->subject); | 277 | free(info->subject); |
278 | free(info->msg); | 278 | free(info->msg); |
279 | free(info->msg_encoding); | 279 | free(info->msg_encoding); |
280 | free(info); | 280 | free(info); |
281 | return NULL; | 281 | return NULL; |
282 | } | 282 | } |
283 | 283 | ||
284 | int hextoint(char c) | 284 | int hextoint(char c) |
285 | { | 285 | { |
286 | if (c >= 'a' && c <= 'f') | 286 | if (c >= 'a' && c <= 'f') |
287 | return 10 + c - 'a'; | 287 | return 10 + c - 'a'; |
288 | else if (c >= 'A' && c <= 'F') | 288 | else if (c >= 'A' && c <= 'F') |
289 | return 10 + c - 'A'; | 289 | return 10 + c - 'A'; |
290 | else if (c >= '0' && c <= '9') | 290 | else if (c >= '0' && c <= '9') |
291 | return c - '0'; | 291 | return c - '0'; |
292 | else | 292 | else |
293 | return -1; | 293 | return -1; |
294 | } | 294 | } |
295 | 295 | ||
296 | char *trim_end(const char *str, char c) | 296 | char *trim_end(const char *str, char c) |
297 | { | 297 | { |
298 | int len; | 298 | int len; |
299 | char *s, *t; | 299 | char *s, *t; |
300 | 300 | ||
301 | if (str == NULL) | 301 | if (str == NULL) |
302 | return NULL; | 302 | return NULL; |
303 | t = (char *)str; | 303 | t = (char *)str; |
304 | len = strlen(t); | 304 | len = strlen(t); |
305 | while(len > 0 && t[len - 1] == c) | 305 | while(len > 0 && t[len - 1] == c) |
306 | len--; | 306 | len--; |
307 | 307 | ||
308 | if (len == 0) | 308 | if (len == 0) |
309 | return NULL; | 309 | return NULL; |
310 | 310 | ||
311 | c = t[len]; | 311 | c = t[len]; |
312 | t[len] = '\0'; | 312 | t[len] = '\0'; |
313 | s = xstrdup(t); | 313 | s = xstrdup(t); |
314 | t[len] = c; | 314 | t[len] = c; |
315 | return s; | 315 | return s; |
316 | } | 316 | } |
317 | 317 | ||
318 | char *strlpart(char *txt, int maxlen) | 318 | char *strlpart(char *txt, int maxlen) |
319 | { | 319 | { |
320 | char *result; | 320 | char *result; |
321 | 321 | ||
322 | if (!txt) | 322 | if (!txt) |
323 | return txt; | 323 | return txt; |
324 | 324 | ||
325 | if (strlen(txt) <= maxlen) | 325 | if (strlen(txt) <= maxlen) |
326 | return txt; | 326 | return txt; |
327 | result = xmalloc(maxlen + 1); | 327 | result = xmalloc(maxlen + 1); |
328 | memcpy(result, txt, maxlen - 3); | 328 | memcpy(result, txt, maxlen - 3); |
329 | result[maxlen-1] = result[maxlen-2] = result[maxlen-3] = '.'; | 329 | result[maxlen-1] = result[maxlen-2] = result[maxlen-3] = '.'; |
330 | result[maxlen] = '\0'; | 330 | result[maxlen] = '\0'; |
331 | return result; | 331 | return result; |
332 | } | 332 | } |
333 | 333 | ||
334 | char *strrpart(char *txt, int maxlen) | 334 | char *strrpart(char *txt, int maxlen) |
335 | { | 335 | { |
336 | char *result; | 336 | char *result; |
337 | 337 | ||
338 | if (!txt) | 338 | if (!txt) |
339 | return txt; | 339 | return txt; |
340 | 340 | ||
341 | if (strlen(txt) <= maxlen) | 341 | if (strlen(txt) <= maxlen) |
342 | return txt; | 342 | return txt; |
343 | result = xmalloc(maxlen + 1); | 343 | result = xmalloc(maxlen + 1); |
344 | memcpy(result + 3, txt + strlen(txt) - maxlen + 4, maxlen - 3); | 344 | memcpy(result + 3, txt + strlen(txt) - maxlen + 4, maxlen - 3); |
345 | result[0] = result[1] = result[2] = '.'; | 345 | result[0] = result[1] = result[2] = '.'; |
346 | return result; | 346 | return result; |
347 | } | 347 | } |
348 | 348 | ||
349 | void cgit_add_ref(struct reflist *list, struct refinfo *ref) | 349 | void cgit_add_ref(struct reflist *list, struct refinfo *ref) |
350 | { | 350 | { |
351 | size_t size; | 351 | size_t size; |
352 | 352 | ||
353 | if (list->count >= list->alloc) { | 353 | if (list->count >= list->alloc) { |
354 | list->alloc += (list->alloc ? list->alloc : 4); | 354 | list->alloc += (list->alloc ? list->alloc : 4); |
355 | size = list->alloc * sizeof(struct refinfo *); | 355 | size = list->alloc * sizeof(struct refinfo *); |
356 | list->refs = xrealloc(list->refs, size); | 356 | list->refs = xrealloc(list->refs, size); |
357 | } | 357 | } |
358 | list->refs[list->count++] = ref; | 358 | list->refs[list->count++] = ref; |
359 | } | 359 | } |
360 | 360 | ||
361 | struct refinfo *cgit_mk_refinfo(const char *refname, const unsigned char *sha1) | 361 | struct refinfo *cgit_mk_refinfo(const char *refname, const unsigned char *sha1) |
362 | { | 362 | { |
363 | struct refinfo *ref; | 363 | struct refinfo *ref; |
364 | 364 | ||
365 | ref = xmalloc(sizeof (struct refinfo)); | 365 | ref = xmalloc(sizeof (struct refinfo)); |
366 | ref->refname = xstrdup(refname); | 366 | ref->refname = xstrdup(refname); |
367 | ref->object = parse_object(sha1); | 367 | ref->object = parse_object(sha1); |
368 | switch (ref->object->type) { | 368 | switch (ref->object->type) { |
369 | case OBJ_TAG: | 369 | case OBJ_TAG: |
370 | ref->tag = cgit_parse_tag((struct tag *)ref->object); | 370 | ref->tag = cgit_parse_tag((struct tag *)ref->object); |
371 | break; | 371 | break; |
372 | case OBJ_COMMIT: | 372 | case OBJ_COMMIT: |
373 | ref->commit = cgit_parse_commit((struct commit *)ref->object); | 373 | ref->commit = cgit_parse_commit((struct commit *)ref->object); |
374 | break; | 374 | break; |
375 | } | 375 | } |
376 | return ref; | 376 | return ref; |
377 | } | 377 | } |
378 | 378 | ||
379 | int cgit_refs_cb(const char *refname, const unsigned char *sha1, int flags, | 379 | int cgit_refs_cb(const char *refname, const unsigned char *sha1, int flags, |
380 | void *cb_data) | 380 | void *cb_data) |
381 | { | 381 | { |
382 | struct reflist *list = (struct reflist *)cb_data; | 382 | struct reflist *list = (struct reflist *)cb_data; |
383 | struct refinfo *info = cgit_mk_refinfo(refname, sha1); | 383 | struct refinfo *info = cgit_mk_refinfo(refname, sha1); |
384 | 384 | ||
385 | if (info) | 385 | if (info) |
386 | cgit_add_ref(list, info); | 386 | cgit_add_ref(list, info); |
387 | return 0; | 387 | return 0; |
388 | } | 388 | } |
389 | 389 | ||
390 | void cgit_diff_tree_cb(struct diff_queue_struct *q, | 390 | void cgit_diff_tree_cb(struct diff_queue_struct *q, |
391 | struct diff_options *options, void *data) | 391 | struct diff_options *options, void *data) |
392 | { | 392 | { |
393 | int i; | 393 | int i; |
394 | 394 | ||
395 | for (i = 0; i < q->nr; i++) { | 395 | for (i = 0; i < q->nr; i++) { |
396 | if (q->queue[i]->status == 'U') | 396 | if (q->queue[i]->status == 'U') |
397 | continue; | 397 | continue; |
398 | ((filepair_fn)data)(q->queue[i]); | 398 | ((filepair_fn)data)(q->queue[i]); |
399 | } | 399 | } |
400 | } | 400 | } |
401 | 401 | ||
402 | static int load_mmfile(mmfile_t *file, const unsigned char *sha1) | 402 | static int load_mmfile(mmfile_t *file, const unsigned char *sha1) |
403 | { | 403 | { |
404 | enum object_type type; | 404 | enum object_type type; |
405 | 405 | ||
406 | if (is_null_sha1(sha1)) { | 406 | if (is_null_sha1(sha1)) { |
407 | file->ptr = (char *)""; | 407 | file->ptr = (char *)""; |
408 | file->size = 0; | 408 | file->size = 0; |
409 | } else { | 409 | } else { |
410 | file->ptr = read_sha1_file(sha1, &type, | 410 | file->ptr = read_sha1_file(sha1, &type, |
411 | (unsigned long *)&file->size); | 411 | (unsigned long *)&file->size); |
412 | } | 412 | } |
413 | return 1; | 413 | return 1; |
414 | } | 414 | } |
415 | 415 | ||
416 | /* | 416 | /* |
417 | * Receive diff-buffers from xdiff and concatenate them as | 417 | * Receive diff-buffers from xdiff and concatenate them as |
418 | * needed across multiple callbacks. | 418 | * needed across multiple callbacks. |
419 | * | 419 | * |
420 | * This is basically a copy of xdiff-interface.c/xdiff_outf(), | 420 | * This is basically a copy of xdiff-interface.c/xdiff_outf(), |
421 | * ripped from git and modified to use globals instead of | 421 | * ripped from git and modified to use globals instead of |
422 | * a special callback-struct. | 422 | * a special callback-struct. |
423 | */ | 423 | */ |
424 | char *diffbuf = NULL; | 424 | char *diffbuf = NULL; |
425 | int buflen = 0; | 425 | int buflen = 0; |
426 | 426 | ||
427 | int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf) | 427 | int filediff_cb(void *priv, mmbuffer_t *mb, int nbuf) |
428 | { | 428 | { |
429 | int i; | 429 | int i; |
430 | 430 | ||
431 | for (i = 0; i < nbuf; i++) { | 431 | for (i = 0; i < nbuf; i++) { |
432 | if (mb[i].ptr[mb[i].size-1] != '\n') { | 432 | if (mb[i].ptr[mb[i].size-1] != '\n') { |
433 | /* Incomplete line */ | 433 | /* Incomplete line */ |
434 | diffbuf = xrealloc(diffbuf, buflen + mb[i].size); | 434 | diffbuf = xrealloc(diffbuf, buflen + mb[i].size); |
435 | memcpy(diffbuf + buflen, mb[i].ptr, mb[i].size); | 435 | memcpy(diffbuf + buflen, mb[i].ptr, mb[i].size); |
436 | buflen += mb[i].size; | 436 | buflen += mb[i].size; |
437 | continue; | 437 | continue; |
438 | } | 438 | } |
439 | 439 | ||
440 | /* we have a complete line */ | 440 | /* we have a complete line */ |
441 | if (!diffbuf) { | 441 | if (!diffbuf) { |
442 | ((linediff_fn)priv)(mb[i].ptr, mb[i].size); | 442 | ((linediff_fn)priv)(mb[i].ptr, mb[i].size); |
443 | continue; | 443 | continue; |
444 | } | 444 | } |
445 | diffbuf = xrealloc(diffbuf, buflen + mb[i].size); | 445 | diffbuf = xrealloc(diffbuf, buflen + mb[i].size); |
446 | memcpy(diffbuf + buflen, mb[i].ptr, mb[i].size); | 446 | memcpy(diffbuf + buflen, mb[i].ptr, mb[i].size); |
447 | ((linediff_fn)priv)(diffbuf, buflen + mb[i].size); | 447 | ((linediff_fn)priv)(diffbuf, buflen + mb[i].size); |
448 | free(diffbuf); | 448 | free(diffbuf); |
449 | diffbuf = NULL; | 449 | diffbuf = NULL; |
450 | buflen = 0; | 450 | buflen = 0; |
451 | } | 451 | } |
452 | if (diffbuf) { | 452 | if (diffbuf) { |
453 | ((linediff_fn)priv)(diffbuf, buflen); | 453 | ((linediff_fn)priv)(diffbuf, buflen); |
454 | free(diffbuf); | 454 | free(diffbuf); |
455 | diffbuf = NULL; | 455 | diffbuf = NULL; |
456 | buflen = 0; | 456 | buflen = 0; |
457 | } | 457 | } |
458 | return 0; | 458 | return 0; |
459 | } | 459 | } |
460 | 460 | ||
461 | int cgit_diff_files(const unsigned char *old_sha1, | 461 | int cgit_diff_files(const unsigned char *old_sha1, |
462 | const unsigned char *new_sha1, | 462 | const unsigned char *new_sha1, |
463 | linediff_fn fn) | 463 | linediff_fn fn) |
464 | { | 464 | { |
465 | mmfile_t file1, file2; | 465 | mmfile_t file1, file2; |
466 | xpparam_t diff_params; | 466 | xpparam_t diff_params; |
467 | xdemitconf_t emit_params; | 467 | xdemitconf_t emit_params; |
468 | xdemitcb_t emit_cb; | 468 | xdemitcb_t emit_cb; |
469 | 469 | ||
470 | if (!load_mmfile(&file1, old_sha1) || !load_mmfile(&file2, new_sha1)) | 470 | if (!load_mmfile(&file1, old_sha1) || !load_mmfile(&file2, new_sha1)) |
471 | return 1; | 471 | return 1; |
472 | 472 | ||
473 | diff_params.flags = XDF_NEED_MINIMAL; | 473 | diff_params.flags = XDF_NEED_MINIMAL; |
474 | emit_params.ctxlen = 3; | 474 | emit_params.ctxlen = 3; |
475 | emit_params.flags = XDL_EMIT_FUNCNAMES; | 475 | emit_params.flags = XDL_EMIT_FUNCNAMES; |
476 | emit_params.find_func = NULL; | 476 | emit_params.find_func = NULL; |
477 | emit_cb.outf = filediff_cb; | 477 | emit_cb.outf = filediff_cb; |
478 | emit_cb.priv = fn; | 478 | emit_cb.priv = fn; |
479 | xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb); | 479 | xdl_diff(&file1, &file2, &diff_params, &emit_params, &emit_cb); |
480 | return 0; | 480 | return 0; |
481 | } | 481 | } |
482 | 482 | ||
483 | void cgit_diff_tree(const unsigned char *old_sha1, | 483 | void cgit_diff_tree(const unsigned char *old_sha1, |
484 | const unsigned char *new_sha1, | 484 | const unsigned char *new_sha1, |
485 | filepair_fn fn, const char *prefix) | 485 | filepair_fn fn, const char *prefix) |
486 | { | 486 | { |
487 | struct diff_options opt; | 487 | struct diff_options opt; |
488 | int ret; | 488 | int ret; |
489 | int prefixlen; | 489 | int prefixlen; |
490 | 490 | ||
491 | diff_setup(&opt); | 491 | diff_setup(&opt); |
492 | opt.output_format = DIFF_FORMAT_CALLBACK; | 492 | opt.output_format = DIFF_FORMAT_CALLBACK; |
493 | opt.detect_rename = 1; | 493 | opt.detect_rename = 1; |
494 | opt.rename_limit = cgit_renamelimit; | 494 | opt.rename_limit = cgit_renamelimit; |
495 | opt.recursive = 1; | 495 | DIFF_OPT_SET(&opt, RECURSIVE); |
496 | opt.format_callback = cgit_diff_tree_cb; | 496 | opt.format_callback = cgit_diff_tree_cb; |
497 | opt.format_callback_data = fn; | 497 | opt.format_callback_data = fn; |
498 | if (prefix) { | 498 | if (prefix) { |
499 | opt.nr_paths = 1; | 499 | opt.nr_paths = 1; |
500 | opt.paths = &prefix; | 500 | opt.paths = &prefix; |
501 | prefixlen = strlen(prefix); | 501 | prefixlen = strlen(prefix); |
502 | opt.pathlens = &prefixlen; | 502 | opt.pathlens = &prefixlen; |
503 | } | 503 | } |
504 | diff_setup_done(&opt); | 504 | diff_setup_done(&opt); |
505 | 505 | ||
506 | if (old_sha1 && !is_null_sha1(old_sha1)) | 506 | if (old_sha1 && !is_null_sha1(old_sha1)) |
507 | ret = diff_tree_sha1(old_sha1, new_sha1, "", &opt); | 507 | ret = diff_tree_sha1(old_sha1, new_sha1, "", &opt); |
508 | else | 508 | else |
509 | ret = diff_root_tree_sha1(new_sha1, "", &opt); | 509 | ret = diff_root_tree_sha1(new_sha1, "", &opt); |
510 | diffcore_std(&opt); | 510 | diffcore_std(&opt); |
511 | diff_flush(&opt); | 511 | diff_flush(&opt); |
512 | } | 512 | } |
513 | 513 | ||
514 | void cgit_diff_commit(struct commit *commit, filepair_fn fn) | 514 | void cgit_diff_commit(struct commit *commit, filepair_fn fn) |
515 | { | 515 | { |
516 | unsigned char *old_sha1 = NULL; | 516 | unsigned char *old_sha1 = NULL; |
517 | 517 | ||
518 | if (commit->parents) | 518 | if (commit->parents) |
519 | old_sha1 = commit->parents->item->object.sha1; | 519 | old_sha1 = commit->parents->item->object.sha1; |
520 | cgit_diff_tree(old_sha1, commit->object.sha1, fn, NULL); | 520 | cgit_diff_tree(old_sha1, commit->object.sha1, fn, NULL); |
521 | } | 521 | } |