* [PATCH v4 0/4] `git format-patch --stdout id2..id`
@ 2013-08-20 16:56 cgit
2013-08-20 16:56 ` [PATCH v4 1/4] ui-diff: Check the return value of get_sha1() cgit
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: cgit @ 2013-08-20 16:56 UTC (permalink / raw)
Fixed patch generation for root diffs.
Generate proper file names when specifying two revisions.
Lukas Fleischer (4):
ui-diff: Check the return value of get_sha1()
ui-patch.c: Use log_tree_commit() to generate diffs
Allow for creating patch series
ui-patch: Rename variables
cmd.c | 2 +-
ui-diff.c | 23 +++++++----------
ui-patch.c | 87 ++++++++++++++++++++++++++++++++++++++------------------------
ui-patch.h | 3 ++-
4 files changed, 65 insertions(+), 50 deletions(-)
--
1.8.4.rc3.500.gc3113b0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v4 1/4] ui-diff: Check the return value of get_sha1()
2013-08-20 16:56 [PATCH v4 0/4] `git format-patch --stdout id2..id` cgit
@ 2013-08-20 16:56 ` cgit
2013-08-20 16:56 ` [PATCH v4 2/4] ui-patch.c: Use log_tree_commit() to generate diffs cgit
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: cgit @ 2013-08-20 16:56 UTC (permalink / raw)
Sync with what we do everywhere else and check the return value of
get_sha1() instead of calling sha1_object_info() to validate the object.
Note that we later call lookup_commit_reference(), which checks that
both SHA1 values refer to commits, anyway.
Signed-off-by: Lukas Fleischer <cgit at cryptocrack.de>
---
ui-diff.c | 23 +++++++++--------------
1 file changed, 9 insertions(+), 14 deletions(-)
diff --git a/ui-diff.c b/ui-diff.c
index 838db8c..1209c47 100644
--- a/ui-diff.c
+++ b/ui-diff.c
@@ -360,15 +360,11 @@ void cgit_print_diff_ctrls()
void cgit_print_diff(const char *new_rev, const char *old_rev,
const char *prefix, int show_ctrls, int raw)
{
- enum object_type type;
- unsigned long size;
struct commit *commit, *commit2;
if (!new_rev)
new_rev = ctx.qry.head;
- get_sha1(new_rev, new_rev_sha1);
- type = sha1_object_info(new_rev_sha1, &size);
- if (type == OBJ_BAD) {
+ if (get_sha1(new_rev, new_rev_sha1)) {
cgit_print_error("Bad object name: %s", new_rev);
return;
}
@@ -378,19 +374,18 @@ void cgit_print_diff(const char *new_rev, const char *old_rev,
return;
}
- if (old_rev)
- get_sha1(old_rev, old_rev_sha1);
- else if (commit->parents && commit->parents->item)
+ if (old_rev) {
+ if (get_sha1(old_rev, old_rev_sha1)) {
+ cgit_print_error("Bad object name: %s", old_rev);
+ return;
+ }
+ } else if (commit->parents && commit->parents->item) {
hashcpy(old_rev_sha1, commit->parents->item->object.sha1);
- else
+ } else {
hashclr(old_rev_sha1);
+ }
if (!is_null_sha1(old_rev_sha1)) {
- type = sha1_object_info(old_rev_sha1, &size);
- if (type == OBJ_BAD) {
- cgit_print_error("Bad object name: %s", sha1_to_hex(old_rev_sha1));
- return;
- }
commit2 = lookup_commit_reference(old_rev_sha1);
if (!commit2 || parse_commit(commit2)) {
cgit_print_error("Bad commit: %s", sha1_to_hex(old_rev_sha1));
--
1.8.4.rc3.500.gc3113b0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v4 2/4] ui-patch.c: Use log_tree_commit() to generate diffs
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 ` cgit
2013-08-20 16:56 ` [PATCH v4 3/4] Allow for creating patch series cgit
2013-08-20 16:56 ` [PATCH v4 4/4] ui-patch: Rename variables cgit
3 siblings, 0 replies; 5+ messages in thread
From: cgit @ 2013-08-20 16:56 UTC (permalink / raw)
Instead of using our own formatting, use log_tree_commit() from Git to
create patches. This removes unnecessary duplicate code and also fixes a
bug with e-mail address formatting that existed in our own
implementation.
Signed-off-by: Lukas Fleischer <cgit at cryptocrack.de>
---
ui-patch.c | 51 ++++++++++++++++++++++++++++-----------------------
1 file changed, 28 insertions(+), 23 deletions(-)
diff --git a/ui-patch.c b/ui-patch.c
index 3922a44..72c9749 100644
--- a/ui-patch.c
+++ b/ui-patch.c
@@ -13,9 +13,11 @@
void cgit_print_patch(char *hex, const char *prefix)
{
+ struct rev_info rev;
struct commit *commit;
- struct commitinfo *info;
unsigned char sha1[20], old_sha1[20];
+ char rev_range[2 * 40 + 3];
+ char *rev_argv[] = { NULL, "--reverse", "--format=email", rev_range };
char *patchname;
if (!hex)
@@ -30,36 +32,39 @@ void cgit_print_patch(char *hex, const char *prefix)
cgit_print_error("Bad commit reference: %s", hex);
return;
}
- info = cgit_parse_commit(commit);
- if (commit->parents && commit->parents->item)
+ if (commit->parents && commit->parents->item) {
hashcpy(old_sha1, commit->parents->item->object.sha1);
- else
+ sprintf(rev_range, "%s..%s", sha1_to_hex(old_sha1),
+ sha1_to_hex(sha1));
+ } else {
hashclr(old_sha1);
+ memcpy(rev_range, sha1_to_hex(sha1), 41);
+ }
patchname = fmt("%s.patch", sha1_to_hex(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);
+
+ 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";
}
- 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");
+
+ init_revisions(&rev, NULL);
+ rev.abbrev = DEFAULT_ABBREV;
+ rev.verbose_header = 1;
+ rev.diff = 1;
+ rev.show_root_diff = 1;
+ rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
+ setup_revisions(ARRAY_SIZE(rev_argv), (const char **)rev_argv, &rev,
+ NULL);
+ prepare_revision_walk(&rev);
+
+ while ((commit = get_revision(&rev)) != NULL) {
+ log_tree_commit(&rev, commit);
+ printf("--\ncgit %s\n", cgit_version);
}
- html("---\n");
- if (prefix)
- htmlf("(limited to '%s')\n\n", prefix);
- cgit_diff_tree(old_sha1, sha1, filepair_cb_raw, prefix, 0);
- html("--\n");
- htmlf("cgit %s\n", cgit_version);
- cgit_free_commitinfo(info);
}
--
1.8.4.rc3.500.gc3113b0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v4 3/4] Allow for creating patch series
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
2013-08-20 16:56 ` [PATCH v4 4/4] ui-patch: Rename variables cgit
3 siblings, 0 replies; 5+ messages in thread
From: cgit @ 2013-08-20 16:56 UTC (permalink / raw)
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v4 4/4] ui-patch: Rename variables
2013-08-20 16:56 [PATCH v4 0/4] `git format-patch --stdout id2..id` cgit
` (2 preceding siblings ...)
2013-08-20 16:56 ` [PATCH v4 3/4] Allow for creating patch series cgit
@ 2013-08-20 16:56 ` cgit
3 siblings, 0 replies; 5+ messages in thread
From: cgit @ 2013-08-20 16:56 UTC (permalink / raw)
Rename parameters and local variables to match those from ui-diff. Also,
convert a "char *" to "const char *".
Signed-off-by: Lukas Fleischer <cgit at cryptocrack.de>
---
ui-patch.c | 33 +++++++++++++++++----------------
ui-patch.h | 3 ++-
2 files changed, 19 insertions(+), 17 deletions(-)
diff --git a/ui-patch.c b/ui-patch.c
index bb39294..1dbb39d 100644
--- a/ui-patch.c
+++ b/ui-patch.c
@@ -11,48 +11,49 @@
#include "html.h"
#include "ui-shared.h"
-void cgit_print_patch(char *hex, const char *old_rev, const char *prefix)
+void cgit_print_patch(const char *new_rev, const char *old_rev,
+ const char *prefix)
{
struct rev_info rev;
struct commit *commit;
- unsigned char sha1[20], old_sha1[20];
+ unsigned char new_rev_sha1[20], old_rev_sha1[20];
char rev_range[2 * 40 + 3];
char *rev_argv[] = { NULL, "--reverse", "--format=email", 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_rev_sha1)) {
+ cgit_print_error("Bad object id: %s", new_rev);
return;
}
- commit = lookup_commit_reference(sha1);
+ commit = lookup_commit_reference(new_rev_sha1);
if (!commit) {
- cgit_print_error("Bad commit reference: %s", hex);
+ cgit_print_error("Bad commit reference: %s", new_rev);
return;
}
if (old_rev) {
- if (get_sha1(old_rev, old_sha1)) {
+ if (get_sha1(old_rev, old_rev_sha1)) {
cgit_print_error("Bad object id: %s", old_rev);
return;
}
- if (!lookup_commit_reference(old_sha1)) {
+ if (!lookup_commit_reference(old_rev_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);
+ hashcpy(old_rev_sha1, commit->parents->item->object.sha1);
} else {
- hashclr(old_sha1);
+ hashclr(old_rev_sha1);
}
- if (is_null_sha1(old_sha1)) {
- memcpy(rev_range, sha1_to_hex(sha1), 41);
+ if (is_null_sha1(old_rev_sha1)) {
+ memcpy(rev_range, sha1_to_hex(new_rev_sha1), 41);
} else {
- sprintf(rev_range, "%s..%s", sha1_to_hex(old_sha1),
- sha1_to_hex(sha1));
+ sprintf(rev_range, "%s..%s", sha1_to_hex(old_rev_sha1),
+ sha1_to_hex(new_rev_sha1));
}
patchname = fmt("%s.patch", rev_range);
diff --git a/ui-patch.h b/ui-patch.h
index acd37fd..7a6cacd 100644
--- a/ui-patch.h
+++ b/ui-patch.h
@@ -1,6 +1,7 @@
#ifndef UI_PATCH_H
#define UI_PATCH_H
-extern void cgit_print_patch(char *hex, const char *old_rev, const char *prefix);
+extern void cgit_print_patch(const char *new_rev, const char *old_rev,
+ const char *prefix);
#endif /* UI_PATCH_H */
--
1.8.4.rc3.500.gc3113b0
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-08-20 16:56 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH v4 3/4] Allow for creating patch series cgit
2013-08-20 16:56 ` [PATCH v4 4/4] ui-patch: Rename variables cgit
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).