All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukas Fleischer <git@cryptocrack.de>
To: git@vger.kernel.org
Subject: [PATCH v2 3/3] convert.c: Remove duplicate code
Date: Sat, 13 Apr 2013 15:28:32 +0200	[thread overview]
Message-ID: <1365859712-8400-3-git-send-email-git@cryptocrack.de> (raw)
In-Reply-To: <1365859712-8400-1-git-send-email-git@cryptocrack.de>

has_cr_in_index() is an almost 1:1 copy of
read_blob_data_from_index_path() with some additions. Invoke
read_blob_data_from_index_path() instead of using copy-pasted code.

Signed-off-by: Lukas Fleischer <git@cryptocrack.de>
---
 convert.c | 27 ++-------------------------
 1 file changed, 2 insertions(+), 25 deletions(-)

diff --git a/convert.c b/convert.c
index 3520252..a12bc78 100644
--- a/convert.c
+++ b/convert.c
@@ -153,36 +153,13 @@ static void check_safe_crlf(const char *path, enum crlf_action crlf_action,
 
 static int has_cr_in_index(const char *path)
 {
-	int pos, len;
 	unsigned long sz;
-	enum object_type type;
 	void *data;
 	int has_cr;
-	struct index_state *istate = &the_index;
 
-	len = strlen(path);
-	pos = index_name_pos(istate, path, len);
-	if (pos < 0) {
-		/*
-		 * We might be in the middle of a merge, in which
-		 * case we would read stage #2 (ours).
-		 */
-		int i;
-		for (i = -pos - 1;
-		     (pos < 0 && i < istate->cache_nr &&
-		      !strcmp(istate->cache[i]->name, path));
-		     i++)
-			if (ce_stage(istate->cache[i]) == 2)
-				pos = i;
-	}
-	if (pos < 0)
+	data = read_blob_data_from_index_path(path, NULL, &sz);
+	if (!data)
 		return 0;
-	data = read_sha1_file(istate->cache[pos]->sha1, &type, &sz);
-	if (!data || type != OBJ_BLOB) {
-		free(data);
-		return 0;
-	}
-
 	has_cr = memchr(data, '\r', sz) != NULL;
 	free(data);
 	return has_cr;
-- 
1.8.2.675.gda3bb24.dirty

  parent reply	other threads:[~2013-04-13 13:28 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-12 17:26 [PATCH 0/3] Remove ~25 lines of duplicate code Lukas Fleischer
2013-04-12 17:26 ` [PATCH 1/3] Make read_index_data() public Lukas Fleischer
2013-04-12 19:40   ` Jeff King
2013-04-13  8:23     ` Lukas Fleischer
2013-04-12 17:26 ` [PATCH 2/3] Add size parameter to read_index_data() Lukas Fleischer
2013-04-12 17:26 ` [PATCH 3/3] convert.c: Remove duplicate code Lukas Fleischer
2013-04-13 13:28 ` [PATCH v2 1/3] Add public function read_blob_data_from_index_path() Lukas Fleischer
2013-04-13 13:28   ` [PATCH v2 2/3] Add size parameter to read_blob_data_from_index_path() Lukas Fleischer
2013-04-13 13:28   ` Lukas Fleischer [this message]
2013-04-14  5:49   ` [PATCH v2 1/3] Add public function read_blob_data_from_index_path() Junio C Hamano
2013-04-14  6:55     ` Junio C Hamano
2013-04-14 20:14     ` Lukas Fleischer

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=1365859712-8400-3-git-send-email-git@cryptocrack.de \
    --to=git@cryptocrack.de \
    --cc=git@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.