patch and plain diff works

gopher
KatolaZ 7 years ago
parent 21a23a12ff
commit 09dc60b4d7
  1. 8
      Makefile
  2. 0
      cgit-70.c
  3. 9
      cgit_70.mk
  4. 4
      ui_70-commit.c
  5. 15
      ui_70-diff.c
  6. 91
      ui_70-patch.c
  7. 1
      ui_70-shared.h

@ -2,7 +2,7 @@ all::
CGIT_VERSION = v1.2 CGIT_VERSION = v1.2
CGIT_SCRIPT_NAME = cgit.cgi 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_DATA_PATH = $(CGIT_SCRIPT_PATH)
CGIT_CONFIG = /var/www/htdocs/etc/cgitrc CGIT_CONFIG = /var/www/htdocs/etc/cgitrc
CACHE_ROOT = /var/cache/cgit CACHE_ROOT = /var/cache/cgit
@ -78,7 +78,7 @@ endif
all:: cgit all:: cgit
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: sparse:
$(QUIET_SUBDIR0)git $(QUIET_SUBDIR1) -f ../cgit.mk NO_CURL=1 cgit-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 a2x -f pdf cgitrc.5.txt
clean: clean-doc clean: clean-doc
$(RM) cgit VERSION CGIT-CFLAGS *.o tags $(RM) cgit-70 VERSION CGIT-CFLAGS *.o tags
$(RM) -r .deps $(RM) -r .deps
cleanall: clean cleanall: clean
@ -168,7 +168,7 @@ tags:
$(QUIET_TAGS)find . -name '*.[ch]' | xargs ctags $(QUIET_TAGS)find . -name '*.[ch]' | xargs ctags
#.PHONY: all cgit git get-git #.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: clean clean-doc cleanall
.PHONY: doc doc-html doc-man doc-pdf .PHONY: doc doc-html doc-man doc-pdf
.PHONY: install install-doc install-html install-man install-pdf .PHONY: install install-doc install-html install-man install-pdf

@ -69,7 +69,7 @@ ifdef HAVE_LINUX_SENDFILE
endif endif
#CGIT_OBJ_NAMES += cgit.o #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 += cache.o
#CGIT_OBJ_NAMES += cmd.o #CGIT_OBJ_NAMES += cmd.o
CGIT_OBJ_NAMES += cmd_70.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_70-diff.o
##CGIT_OBJ_NAMES += ui-log.o ##CGIT_OBJ_NAMES += ui-log.o
CGIT_OBJ_NAMES += ui_70-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-plain.o
##CGIT_OBJ_NAMES += ui-refs.o ##CGIT_OBJ_NAMES += ui-refs.o
CGIT_OBJ_NAMES += ui_70-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 # Only cgit.c reference CGIT_VERSION so we only rebuild its objects when the
# version changes. # version changes.
##CGIT_VERSION_OBJS := $(addprefix $(CGIT_PREFIX),cgit.o cgit.sp) ##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): $(CGIT_PREFIX)VERSION
$(CGIT_VERSION_OBJS): EXTRA_CPPFLAGS = \ $(CGIT_VERSION_OBJS): EXTRA_CPPFLAGS = \
-DCGIT_VERSION='"$(CGIT_VERSION)"' -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) $(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) $< $(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)" @echo 1>&1 " * $(LUA_MESSAGE)"
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) $(CGIT_LIBS) $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) $(CGIT_LIBS)

@ -42,7 +42,7 @@ void cgit_print_commit(char *hex, const char *prefix)
load_ref_decorations(NULL, DECORATE_FULL_REFS); load_ref_decorations(NULL, DECORATE_FULL_REFS);
cgit_print_layout_start(); cgit_print_layout_start();
cgit_print_diff_ctrls(); /*cgit_print_diff_ctrls();*/
cgit_gopher_start_selector(GOPHER_INFO); cgit_gopher_start_selector(GOPHER_INFO);
cgit_gopher_text("author: "); 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_commit_link(tmp, NULL, NULL, ctx.qry.head, tmp, prefix);
cgit_gopher_end_selector(); cgit_gopher_end_selector();
cgit_gopher_start_selector(GOPHER_MENU); cgit_gopher_start_selector(GOPHER_TXT);
cgit_gopher_text("patch "); cgit_gopher_text("patch ");
cgit_gopher_tab(); cgit_gopher_tab();
cgit_patch_link("patch", NULL, NULL, NULL, tmp, prefix); cgit_patch_link("patch", NULL, NULL, NULL, tmp, prefix);

@ -381,10 +381,22 @@ void cgit_print_diff_ctrls(void)
html("</div>"); 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;
} }
void cgit_print_diff(const char *new_rev, const char *old_rev, void cgit_print_diff(const char *new_rev, const char *old_rev,
@ -448,6 +460,7 @@ void cgit_print_diff(const char *new_rev, const char *old_rev,
diff_setup(&diffopt); diff_setup(&diffopt);
diffopt.output_format = DIFF_FORMAT_PATCH; diffopt.output_format = DIFF_FORMAT_PATCH;
/*diffopt.output_format = DIFF_FORMAT_RAW;*/
diffopt.flags.recursive = 1; diffopt.flags.recursive = 1;
diffopt.output_prefix=cgit_gopher_add_info_tag; diffopt.output_prefix=cgit_gopher_add_info_tag;
diff_setup_done(&diffopt); diff_setup_done(&diffopt);

@ -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);*/
}
}

@ -43,6 +43,7 @@ void cgit_gopher_text(const char *txt);
void cgit_gopher_tab(); void cgit_gopher_tab();
void cgit_gopher_text_pad(const char *txt, int len); void cgit_gopher_text_pad(const char *txt, int len);
void cgit_gopher_end_selector(); void cgit_gopher_end_selector();
void gopherf(const char *format, ...);

Loading…
Cancel
Save