Thread (9 messages) flat view 9 messages, 2 authors, 2016-06-16

Re: [PATCH v1 3/3] convert: ce_compare_data() checks for a sha1 of a path

From: Junio C Hamano <hidden>
Date: 2016-06-16 02:19:24

Possibly related (same subject, not in this thread)

tboegi@web.de writes:
-static int has_cr_in_index(const char *path)
+static int has_cr_in_index(const char *path, const unsigned char *sha1)
 {
 	unsigned long sz;
 	void *data;
 	int has_cr;
-
-	data = read_blob_data_from_cache(path, &sz);
-	if (!data)
+	enum object_type type;
+	if (!sha1)
+		sha1 = get_sha1_from_cache(path);
+	if (!sha1)
+		return 0;
+	data = read_sha1_file(sha1, &type, &sz);
+	if (!data || type != OBJ_BLOB) {
+		free(data);
 		return 0;
+	}
+
 	has_cr = memchr(data, '\r', sz) != NULL;
 	free(data);
 	return has_cr;
 }
Does this really need 2/3?  Wouldn't this be equivalent to

	if (!sha1) {
        	data = read_blob_data_from_cache(path, &sz);
	} else {
        	data = read_sha1_file(sha1, &type, &sz);
	}
	if (!data || type != OBJ_BLOB) {
        	free(data);
                return 0;
	}

        has_cr = ...
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help