List for cgit developers and users
 help / color / mirror / Atom feed
From: cgit at cryptocrack.de (Lukas Fleischer)
Subject: [PATCH v4 1/4] ui-diff: Check the return value of get_sha1()
Date: Tue, 20 Aug 2013 18:56:12 +0200	[thread overview]
Message-ID: <1377017775-29848-2-git-send-email-cgit@cryptocrack.de> (raw)
In-Reply-To: <1377017775-29848-1-git-send-email-cgit@cryptocrack.de>

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



  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 ` cgit [this message]
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

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-2-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).