convert.c: remove duplicate code
The has_cr_in_index() function is an almost 1:1 copy of read_blob_data_from_index() with some additions. Use the latter instead of using copy-pasted code. Signed-off-by: Lukas Fleischer <git@cryptocrack.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Lukas Fleischer committed
Apr 13, 2013 at 15:28 UTC
4982fd78f61db69504f91151f94fce9914d610b6
1 file changed
+2
-25
convert.c
+2
-25
@@ -153,36 +153,13 @@ static void check_safe_crlf(const char *path, enum crlf_action crlf_action,
153
154
static int has_cr_in_index(const char *path)
155
{
156
- int pos, len;
156
unsigned long sz;
158
- enum object_type type;
157
void *data;
158
int has_cr;
161
- struct index_state *istate = &the_index;
159
163
- len = strlen(path);
164
- pos = index_name_pos(istate, path, len);
165
- if (pos < 0) {
166
- /*
167
- * We might be in the middle of a merge, in which
168
- * case we would read stage #2 (ours).
169
- */
170
- int i;
171
- for (i = -pos - 1;
172
- (pos < 0 && i < istate->cache_nr &&
173
- !strcmp(istate->cache[i]->name, path));
174
- i++)
175
- if (ce_stage(istate->cache[i]) == 2)
176
- pos = i;
177
- }
178
- if (pos < 0)
160
+ data = read_blob_data_from_cache(path, &sz);
161
+ if (!data)
162
return 0;
180
- data = read_sha1_file(istate->cache[pos]->sha1, &type, &sz);
181
- if (!data || type != OBJ_BLOB) {
182
- free(data);
183
- return 0;
184
- }
185
-
163
has_cr = memchr(data, '\r', sz) != NULL;
164
free(data);
165
return has_cr;