Skip to content

Commit 4982fd7

Browse files
Lukas Fleischergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ff36682 commit 4982fd7

File tree

1 file changed

+2
-25
lines changed

1 file changed

+2
-25
lines changed

convert.c

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -153,36 +153,13 @@ static void check_safe_crlf(const char *path, enum crlf_action crlf_action,
153153

154154
static int has_cr_in_index(const char *path)
155155
{
156-
int pos, len;
157156
unsigned long sz;
158-
enum object_type type;
159157
void *data;
160158
int has_cr;
161-
struct index_state *istate = &the_index;
162159

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)
179162
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-
186163
has_cr = memchr(data, '\r', sz) != NULL;
187164
free(data);
188165
return has_cr;

0 commit comments

Comments
 (0)