From mboxrd@z Thu Jan 1 00:00:00 1970 From: cgit at cryptocrack.de (Lukas Fleischer) Date: Thu, 15 Aug 2013 18:54:04 +0200 Subject: [PATCH/RFC] Allow for generating patch series In-Reply-To: <20130815114425.GO2337@serenity.lan> References: <1376563950-30423-1-git-send-email-cgit@cryptocrack.de> <20130815114425.GO2337@serenity.lan> Message-ID: <20130815165404.GA9638@blizzard> On Thu, Aug 15, 2013 at 12:44:25PM +0100, John Keeping wrote: > On Thu, Aug 15, 2013 at 12:52:30PM +0200, Lukas Fleischer wrote: > > Signed-off-by: Lukas Fleischer > > --- > > Note that this is a very first draft of a patch series introducing > > revision range support for /patch/. Also, the final series will contain > > an additional bug fix of an e-mail address encoding bug I noticed during > > testing this. > > > > Comments welcome. > > I wonder if it would be easier at this point to just use Git's > run_command API and call "git format-patch --stdout". That would mean that we would have to fork(), though... I had another idea that I will submit soon... See if you like it :) > > I haven't looked at that in detail, but it seems that we're duplicating > a lot of formatting here that Git already does. > > > cmd.c | 2 +- > > ui-patch.c | 85 +++++++++++++++++++++++++++++++++++++++----------------------- > > ui-patch.h | 2 +- > > 3 files changed, 56 insertions(+), 33 deletions(-) > > > > diff --git a/cmd.c b/cmd.c > > index abe8e46..7e8b168 100644 > > --- a/cmd.c > > +++ b/cmd.c > > @@ -93,7 +93,7 @@ static void repolist_fn(struct cgit_context *ctx) > > > > static void patch_fn(struct cgit_context *ctx) > > { > > - cgit_print_patch(ctx->qry.sha1, ctx->qry.path); > > + cgit_print_patch(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path); > > } > > > > static void plain_fn(struct cgit_context *ctx) > > diff --git a/ui-patch.c b/ui-patch.c > > index fbb92cc..0eb48bd 100644 > > --- a/ui-patch.c > > +++ b/ui-patch.c > > @@ -83,55 +83,78 @@ static void filepair_cb(struct diff_filepair *pair) > > html("Binary files differ\n"); > > } > > > > -void cgit_print_patch(char *hex, const char *prefix) > > +void cgit_print_patch(char *new_rev, char *old_rev, const char *prefix) > > { > > + struct rev_info rev; > > struct commit *commit; > > struct commitinfo *info; > > - unsigned char sha1[20], old_sha1[20]; > > + unsigned char new_sha1[20], old_sha1[20]; > > + char rev_range[2 * 20 + strlen("..") + 1]; > > + char *rev_argv[] = { NULL, "--reverse", rev_range }; > > char *patchname; > > > > - if (!hex) > > - hex = ctx.qry.head; > > + if (!new_rev) > > + new_rev = ctx.qry.head; > > > > - if (get_sha1(hex, sha1)) { > > - cgit_print_error("Bad object id: %s", hex); > > + if (get_sha1(new_rev, new_sha1)) { > > + cgit_print_error("Bad object id: %s", new_rev); > > return; > > } > > - commit = lookup_commit_reference(sha1); > > + commit = lookup_commit_reference(new_sha1); > > if (!commit) { > > - cgit_print_error("Bad commit reference: %s", hex); > > + cgit_print_error("Bad commit reference: %s", new_rev); > > return; > > } > > - info = cgit_parse_commit(commit); > > > > - if (commit->parents && commit->parents->item) > > + if (old_rev) > > + get_sha1(old_rev, old_sha1); > > + else if (commit->parents && commit->parents->item) > > hashcpy(old_sha1, commit->parents->item->object.sha1); > > else > > hashclr(old_sha1); > > > > - patchname = fmt("%s.patch", sha1_to_hex(sha1)); > > + if (old_rev) > > + patchname = fmt("%s..%s.patch", sha1_to_hex(old_sha1), sha1_to_hex(new_sha1)); > > + else > > + patchname = fmt("%s.patch", sha1_to_hex(new_sha1)); > > + > > ctx.page.mimetype = "text/plain"; > > ctx.page.filename = patchname; > > cgit_print_http_headers(&ctx); > > - htmlf("From %s Mon Sep 17 00:00:00 2001\n", sha1_to_hex(sha1)); > > - htmlf("From: %s", info->author); > > - if (!ctx.cfg.noplainemail) { > > - htmlf(" %s", info->author_email); > > - } > > - html("\n"); > > - html("Date: "); > > - cgit_print_date(info->author_date, "%a, %d %b %Y %H:%M:%S %z%n", ctx.cfg.local_time); > > - htmlf("Subject: %s\n\n", info->subject); > > - if (info->msg && *info->msg) { > > - htmlf("%s", info->msg); > > - if (info->msg[strlen(info->msg) - 1] != '\n') > > - html("\n"); > > + > > + sprintf(rev_range, "%s..%s", sha1_to_hex(old_sha1), > > + sha1_to_hex(new_sha1)); > > + > > + init_revisions(&rev, NULL); > > + rev.abbrev = DEFAULT_ABBREV; > > + rev.commit_format = CMIT_FMT_EMAIL; > > + rev.verbose_header = 1; > > + rev.show_root_diff = 0; > > + setup_revisions(3, rev_argv, &rev, NULL); > > + prepare_revision_walk(&rev); > > + > > + while ((commit = get_revision(&rev)) != NULL) { > > + info = cgit_parse_commit(commit); > > + htmlf("From %s Mon Sep 17 00:00:00 2001\n", sha1_to_hex(commit->object.sha1)); > > + htmlf("From: %s", info->author); > > + if (!ctx.cfg.noplainemail) { > > + htmlf(" %s", info->author_email); > > + } > > + html("\n"); > > + html("Date: "); > > + cgit_print_date(info->author_date, "%a, %d %b %Y %H:%M:%S %z%n", ctx.cfg.local_time); > > + htmlf("Subject: %s\n\n", info->subject); > > + if (info->msg && *info->msg) { > > + htmlf("%s", info->msg); > > + if (info->msg[strlen(info->msg) - 1] != '\n') > > + html("\n"); > > + } > > + html("---\n"); > > + if (prefix) > > + htmlf("(limited to '%s')\n\n", prefix); > > + cgit_diff_tree(commit->parents->item->object.sha1, commit->object.sha1, filepair_cb, prefix, 0); > > + html("--\n"); > > + htmlf("cgit %s\n\n", cgit_version); > > + cgit_free_commitinfo(info); > > } > > - html("---\n"); > > - if (prefix) > > - htmlf("(limited to '%s')\n\n", prefix); > > - cgit_diff_tree(old_sha1, sha1, filepair_cb, prefix, 0); > > - html("--\n"); > > - htmlf("cgit %s\n", cgit_version); > > - cgit_free_commitinfo(info); > > } > > diff --git a/ui-patch.h b/ui-patch.h > > index 1641cea..d65d594 100644 > > --- a/ui-patch.h > > +++ b/ui-patch.h > > @@ -1,6 +1,6 @@ > > #ifndef UI_PATCH_H > > #define UI_PATCH_H > > > > -extern void cgit_print_patch(char *hex, const char *prefix); > > +extern void cgit_print_patch(char *new_rev, char *old_rev, const char *prefix); > > > > #endif /* UI_PATCH_H */ > > -- > > 1.8.4.rc2.477.g1da3ebd > > > > _______________________________________________ > > CGit mailing list > > CGit at lists.zx2c4.com > > http://lists.zx2c4.com/mailman/listinfo/cgit