Skip to content

Commit 750f646

Browse files
Lukas Fleischerzx2c4
Lukas Fleischer
authored andcommitted
Allow for creating patch series
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 <[email protected]>
1 parent 455b598 commit 750f646

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

Diff for: cmd.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ static void repolist_fn(struct cgit_context *ctx)
9898

9999
static void patch_fn(struct cgit_context *ctx)
100100
{
101-
cgit_print_patch(ctx->qry.sha1, ctx->qry.path);
101+
cgit_print_patch(ctx->qry.sha1, ctx->qry.sha2, ctx->qry.path);
102102
}
103103

104104
static void plain_fn(struct cgit_context *ctx)

Diff for: ui-patch.c

+18-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "html.h"
1212
#include "ui-shared.h"
1313

14-
void cgit_print_patch(char *hex, const char *prefix)
14+
void cgit_print_patch(char *hex, const char *old_rev, const char *prefix)
1515
{
1616
struct rev_info rev;
1717
struct commit *commit;
@@ -33,16 +33,29 @@ void cgit_print_patch(char *hex, const char *prefix)
3333
return;
3434
}
3535

36-
if (commit->parents && commit->parents->item) {
36+
if (old_rev) {
37+
if (get_sha1(old_rev, old_sha1)) {
38+
cgit_print_error("Bad object id: %s", old_rev);
39+
return;
40+
}
41+
if (!lookup_commit_reference(old_sha1)) {
42+
cgit_print_error("Bad commit reference: %s", old_rev);
43+
return;
44+
}
45+
} else if (commit->parents && commit->parents->item) {
3746
hashcpy(old_sha1, commit->parents->item->object.sha1);
38-
sprintf(rev_range, "%s..%s", sha1_to_hex(old_sha1),
39-
sha1_to_hex(sha1));
4047
} else {
4148
hashclr(old_sha1);
49+
}
50+
51+
if (is_null_sha1(old_sha1)) {
4252
memcpy(rev_range, sha1_to_hex(sha1), 41);
53+
} else {
54+
sprintf(rev_range, "%s..%s", sha1_to_hex(old_sha1),
55+
sha1_to_hex(sha1));
4356
}
4457

45-
patchname = fmt("%s.patch", sha1_to_hex(sha1));
58+
patchname = fmt("%s.patch", rev_range);
4659
ctx.page.mimetype = "text/plain";
4760
ctx.page.filename = patchname;
4861
cgit_print_http_headers(&ctx);

Diff for: ui-patch.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#ifndef UI_PATCH_H
22
#define UI_PATCH_H
33

4-
extern void cgit_print_patch(char *hex, const char *prefix);
4+
extern void cgit_print_patch(char *hex, const char *old_rev, const char *prefix);
55

66
#endif /* UI_PATCH_H */

0 commit comments

Comments
 (0)