diff options
| author | KatolaZ <katolaz@freaknet.org> | 2018-07-29 06:16:42 +0100 | 
|---|---|---|
| committer | KatolaZ <katolaz@freaknet.org> | 2018-07-29 06:16:42 +0100 | 
| commit | 09dc60b4d73f290ccad37a086a6f867fe11efa44 (patch) | |
| tree | 58bc1c5d752fec9a9f3bd590da1602e1d79d5093 | |
| parent | 21a23a12ffa5513248eecc5444dc396c5ba0b443 (diff) | |
patch and plain diff works
| -rw-r--r-- | Makefile | 8 | ||||
| -rw-r--r-- | cgit-70.c (renamed from cgit_70.c) | 0 | ||||
| -rw-r--r-- | cgit_70.mk | 9 | ||||
| -rw-r--r-- | ui_70-commit.c | 4 | ||||
| -rw-r--r-- | ui_70-diff.c | 15 | ||||
| -rw-r--r-- | ui_70-patch.c | 91 | ||||
| -rw-r--r-- | ui_70-shared.h | 1 | 
7 files changed, 117 insertions, 11 deletions
| @@ -2,7 +2,7 @@ all::  CGIT_VERSION = v1.2  CGIT_SCRIPT_NAME = cgit.cgi -CGIT_SCRIPT_PATH = /var/www/htdocs/cgit_70 +CGIT_SCRIPT_PATH = /var/www/htdocs/cgit-70  CGIT_DATA_PATH = $(CGIT_SCRIPT_PATH)  CGIT_CONFIG = /var/www/htdocs/etc/cgitrc  CACHE_ROOT = /var/cache/cgit @@ -78,7 +78,7 @@ endif  all:: cgit  cgit:  -	$(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) -f ../cgit_70.mk ../cgit_70 $(EXTRA_GIT_TARGETS) NO_CURL=1 +	$(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) -f ../cgit_70.mk ../cgit-70 $(EXTRA_GIT_TARGETS) NO_CURL=1  sparse:  	$(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) -f ../cgit.mk NO_CURL=1 cgit-sparse @@ -152,7 +152,7 @@ $(DOC_PDF): %.pdf : %.txt  	a2x -f pdf cgitrc.5.txt  clean: clean-doc -	$(RM) cgit VERSION CGIT-CFLAGS *.o tags +	$(RM) cgit-70 VERSION CGIT-CFLAGS *.o tags  	$(RM) -r .deps  cleanall: clean @@ -168,7 +168,7 @@ tags:  	$(QUIET_TAGS)find . -name '*.[ch]' | xargs ctags  #.PHONY: all cgit git get-git -.PHONY: all cgit_70 git get-git +.PHONY: all cgit-70 git get-git  .PHONY: clean clean-doc cleanall  .PHONY: doc doc-html doc-man doc-pdf  .PHONY: install install-doc install-html install-man install-pdf @@ -69,7 +69,7 @@ ifdef HAVE_LINUX_SENDFILE  endif  #CGIT_OBJ_NAMES += cgit.o -CGIT_OBJ_NAMES += cgit_70.o +CGIT_OBJ_NAMES += cgit-70.o  CGIT_OBJ_NAMES += cache.o  #CGIT_OBJ_NAMES += cmd.o  CGIT_OBJ_NAMES += cmd_70.o @@ -89,7 +89,8 @@ CGIT_OBJ_NAMES += ui_70-commit.o  CGIT_OBJ_NAMES += ui_70-diff.o  ##CGIT_OBJ_NAMES += ui-log.o  CGIT_OBJ_NAMES += ui_70-log.o -CGIT_OBJ_NAMES += ui-patch.o +##CGIT_OBJ_NAMES += ui-patch.o +CGIT_OBJ_NAMES += ui_70-patch.o  CGIT_OBJ_NAMES += ui-plain.o  ##CGIT_OBJ_NAMES += ui-refs.o  CGIT_OBJ_NAMES += ui_70-refs.o @@ -111,7 +112,7 @@ CGIT_OBJS := $(addprefix $(CGIT_PREFIX),$(CGIT_OBJ_NAMES))  # Only cgit.c reference CGIT_VERSION so we only rebuild its objects when the  # version changes.  ##CGIT_VERSION_OBJS := $(addprefix $(CGIT_PREFIX),cgit.o cgit.sp) -CGIT_VERSION_OBJS := $(addprefix $(CGIT_PREFIX),cgit_70.o cgit.sp) +CGIT_VERSION_OBJS := $(addprefix $(CGIT_PREFIX),cgit-70.o cgit.sp)  $(CGIT_VERSION_OBJS): $(CGIT_PREFIX)VERSION  $(CGIT_VERSION_OBJS): EXTRA_CPPFLAGS = \  	-DCGIT_VERSION='"$(CGIT_VERSION)"' @@ -141,7 +142,7 @@ $(CGIT_PREFIX)CGIT-CFLAGS: FORCE  $(CGIT_OBJS): %.o: %.c GIT-CFLAGS $(CGIT_PREFIX)CGIT-CFLAGS $(missing_dep_dirs)  	$(QUIET_CC)$(CC) -o $*.o -c $(dep_args) $(ALL_CFLAGS) $(EXTRA_CPPFLAGS) $(CGIT_CFLAGS) $< -$(CGIT_PREFIX)cgit_70: $(CGIT_OBJS) GIT-LDFLAGS $(GITLIBS) +$(CGIT_PREFIX)cgit-70: $(CGIT_OBJS) GIT-LDFLAGS $(GITLIBS)  	@echo 1>&1 "    * $(LUA_MESSAGE)"  	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) $(CGIT_LIBS) diff --git a/ui_70-commit.c b/ui_70-commit.c index 7e6d84a..d89f1b2 100644 --- a/ui_70-commit.c +++ b/ui_70-commit.c @@ -42,7 +42,7 @@ void cgit_print_commit(char *hex, const char *prefix)  	load_ref_decorations(NULL, DECORATE_FULL_REFS);  	cgit_print_layout_start(); -	cgit_print_diff_ctrls(); +	/*cgit_print_diff_ctrls();*/  	cgit_gopher_start_selector(GOPHER_INFO);  	cgit_gopher_text("author: "); @@ -80,7 +80,7 @@ void cgit_print_commit(char *hex, const char *prefix)  	cgit_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, prefix);  	cgit_gopher_end_selector(); -	cgit_gopher_start_selector(GOPHER_MENU); +	cgit_gopher_start_selector(GOPHER_TXT);  	cgit_gopher_text("patch ");  	cgit_gopher_tab();  	cgit_patch_link("patch", NULL, NULL, NULL, tmp, prefix); diff --git a/ui_70-diff.c b/ui_70-diff.c index 999c629..46e729d 100644 --- a/ui_70-diff.c +++ b/ui_70-diff.c @@ -381,9 +381,21 @@ void cgit_print_diff_ctrls(void)  	html("</div>");  } -typedef struct strbuf* cgit_gopher_add_info_tag(struct diff_options *opt, void *data){ +struct strbuf* cgit_gopher_add_info_tag(struct diff_options *opt, void *data){ +	struct strbuf* buff; +	char *str; + + +	buff = malloc(sizeof(struct strbuf));	 +	str = malloc(2 * sizeof(char)); +	str[0]= 'i'; +	str[1]= '\0'; +	strbuf_init(buff, 2); +	strbuf_attach(buff, str, 2, 2); + +	return buff;	  }  @@ -448,6 +460,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev,  		diff_setup(&diffopt);  		diffopt.output_format = DIFF_FORMAT_PATCH; +		/*diffopt.output_format = DIFF_FORMAT_RAW;*/  		diffopt.flags.recursive = 1;  		diffopt.output_prefix=cgit_gopher_add_info_tag;  		diff_setup_done(&diffopt); diff --git a/ui_70-patch.c b/ui_70-patch.c new file mode 100644 index 0000000..2e5a5d7 --- /dev/null +++ b/ui_70-patch.c @@ -0,0 +1,91 @@ +/* ui-patch.c: generate patch view + * + * Copyright (C) 2006-2014 cgit Development Team <cgit@lists.zx2c4.com> + * + * Licensed under GNU General Public License v2 + *   (see COPYING for full license text) + */ + +#include "cgit.h" +#include "ui-patch.h" +#include "html.h" +#include "ui_70-shared.h" + +void cgit_print_patch(const char *new_rev, const char *old_rev, +		      const char *prefix) +{ +	struct rev_info rev; +	struct commit *commit; +	struct object_id new_rev_oid, old_rev_oid; +	char rev_range[2 * 40 + 3]; +	const char *rev_argv[] = { NULL, "--reverse", "--format=email", rev_range, "--", prefix, NULL }; +	int rev_argc = ARRAY_SIZE(rev_argv) - 1; +	char *patchname; + +	if (!prefix) +		rev_argc--; + +	if (!new_rev) +		new_rev = ctx.qry.head; + +	if (get_oid(new_rev, &new_rev_oid)) { +		cgit_gopher_error("Bad object id"); +		return; +	} +	commit = lookup_commit_reference(&new_rev_oid); +	if (!commit) { +		cgit_gopher_error("Bad commit reference"); +		return; +	} + +	if (old_rev) { +		if (get_oid(old_rev, &old_rev_oid)) { +			cgit_gopher_error("Bad object id"); +			return; +		} +		if (!lookup_commit_reference(&old_rev_oid)) { +			cgit_gopher_error("Bad commit reference"); +			return; +		} +	} else if (commit->parents && commit->parents->item) { +		oidcpy(&old_rev_oid, &commit->parents->item->object.oid); +	} else { +		oidclr(&old_rev_oid); +	} + +	if (is_null_oid(&old_rev_oid)) { +		memcpy(rev_range, oid_to_hex(&new_rev_oid), GIT_SHA1_HEXSZ + 1); +	} else { +		sprintf(rev_range, "%s..%s", oid_to_hex(&old_rev_oid), +			oid_to_hex(&new_rev_oid)); +	} + +	patchname = fmt("%s.patch", rev_range); +	ctx.page.mimetype = "text/plain"; +	ctx.page.filename = patchname; +	/*cgit_print_http_headers();*/ + +	if (ctx.cfg.noplainemail) { +		rev_argv[2] = "--format=format:From %H Mon Sep 17 00:00:00 " +			      "2001%nFrom: %an%nDate: %aD%n%w(78,0,1)Subject: " +			      "%s%n%n%w(0)%b"; +	} + +	init_revisions(&rev, NULL); +	rev.abbrev = DEFAULT_ABBREV; +	rev.verbose_header = 1; +	rev.diff = 1; +	rev.show_root_diff = 1; +	rev.max_parents = 1; +	rev.diffopt.output_format |= DIFF_FORMAT_DIFFSTAT | +			DIFF_FORMAT_PATCH | DIFF_FORMAT_SUMMARY; +	if (prefix) +		rev.diffopt.stat_sep = fmt("(limited to '%s')\n\n", prefix); +	setup_revisions(rev_argc, rev_argv, &rev, NULL); +	prepare_revision_walk(&rev); + +	while ((commit = get_revision(&rev)) != NULL) { +		log_tree_commit(&rev, commit); +		/*printf("-- \ncgit %s\n\n", cgit_version);*/ +	} +} diff --git a/ui_70-shared.h b/ui_70-shared.h index 8abc3c6..c793950 100644 --- a/ui_70-shared.h +++ b/ui_70-shared.h @@ -43,6 +43,7 @@ void cgit_gopher_text(const char *txt);  void cgit_gopher_tab();  void cgit_gopher_text_pad(const char *txt, int len);  void cgit_gopher_end_selector(); +void gopherf(const char *format, ...); | 
