From: cgit at cryptocrack.de (Lukas Fleischer)
Subject: [PATCH v4 3/4] Allow for creating patch series
Date: Tue, 20 Aug 2013 18:56:14 +0200 [thread overview]
Message-ID: <1377017775-29848-4-git-send-email-cgit@cryptocrack.de> (raw)
In-Reply-To: <1377017775-29848-1-git-send-email-cgit@cryptocrack.de>
This allows for specifying a revision range using the id2 parameter of
/patch/. The output that is produced is similar to
$ git format-patch --stdout id2..id
Signed-off-by: Lukas Fleischer <cgit at cryptocrack.de>
---
cmd.c | 2 +-
ui-patch.c | 23 ++++++++++++++++++-----
ui-patch.h | 2 +-
3 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/cmd.c b/cmd.c
index 9893710..0202917 100644
--- a/cmd.c
+++ b/cmd.c
@@ -98,7 +98,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 72c9749..bb39294 100644
--- a/ui-patch.c
+++ b/ui-patch.c
@@ -11,7 +11,7 @@
#include "html.h"
#include "ui-shared.h"
-void cgit_print_patch(char *hex, const char *prefix)
+void cgit_print_patch(char *hex, const char *old_rev, const char *prefix)
{
struct rev_info rev;
struct commit *commit;
@@ -33,16 +33,29 @@ void cgit_print_patch(char *hex, const char *prefix)
return;
}
- if (commit->parents && commit->parents->item) {
+ if (old_rev) {
+ if (get_sha1(old_rev, old_sha1)) {
+ cgit_print_error("Bad object id: %s", old_rev);
+ return;
+ }
+ if (!lookup_commit_reference(old_sha1)) {
+ cgit_print_error("Bad commit reference: %s", old_rev);
+ return;
+ }
+ } else if (commit->parents && commit->parents->item) {
hashcpy(old_sha1, commit->parents->item->object.sha1);
- sprintf(rev_range, "%s..%s", sha1_to_hex(old_sha1),
- sha1_to_hex(sha1));
} else {
hashclr(old_sha1);
+ }
+
+ if (is_null_sha1(old_sha1)) {
memcpy(rev_range, sha1_to_hex(sha1), 41);
+ } else {
+ sprintf(rev_range, "%s..%s", sha1_to_hex(old_sha1),
+ sha1_to_hex(sha1));
}
- patchname = fmt("%s.patch", sha1_to_hex(sha1));
+ patchname = fmt("%s.patch", rev_range);
ctx.page.mimetype = "text/plain";
ctx.page.filename = patchname;
cgit_print_http_headers(&ctx);
diff --git a/ui-patch.h b/ui-patch.h
index 1641cea..acd37fd 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 *hex, const char *old_rev, const char *prefix);
#endif /* UI_PATCH_H */
--
1.8.4.rc3.500.gc3113b0
next prev parent reply other threads:[~2013-08-20 16:56 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-20 16:56 [PATCH v4 0/4] `git format-patch --stdout id2..id` cgit
2013-08-20 16:56 ` [PATCH v4 1/4] ui-diff: Check the return value of get_sha1() cgit
2013-08-20 16:56 ` [PATCH v4 2/4] ui-patch.c: Use log_tree_commit() to generate diffs cgit
2013-08-20 16:56 ` cgit [this message]
2013-08-20 16:56 ` [PATCH v4 4/4] ui-patch: Rename variables cgit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1377017775-29848-4-git-send-email-cgit@cryptocrack.de \
--to=cgit@lists.zx2c4.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).