@matheusbsbs / matheus-bagliano / commits / 6073ee8571
Fork 0

convert.c: restructure the attribute checking part.

This separates the checkattr() call and interpretation of the returned value specific to the 'crlf' attribute into separate routines, so that we can run a single call to checkattr() to check for more than one attributes, and then interprete what the returned settings mean separately. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Apr 20, 2007 at 23:44 UTC 6073ee85719be6d959e74aa667024fcbec44a588
1 file changed +28 -20
convert.c
+28 -20
@@ -200,7 +200,7 @@ static char *crlf_to_worktree(const char *path, const char *src, unsigned long *
200 return buffer;
201 }
202
203 -static void setup_crlf_check(struct git_attr_check *check)
203 +static void setup_convert_check(struct git_attr_check *check)
204 {
205 static struct git_attr *attr_crlf;
206
@@ -209,33 +209,41 @@ static void setup_crlf_check(struct git_attr_check *check)
209 check->attr = attr_crlf;
210 }
211
212 -static int git_path_check_crlf(const char *path)
212 +static int git_path_check_crlf(const char *path, struct git_attr_check *check)
213 {
214 - struct git_attr_check attr_crlf_check;
215 -
216 - setup_crlf_check(&attr_crlf_check);
217 -
218 - if (!git_checkattr(path, 1, &attr_crlf_check)) {
219 - const char *value = attr_crlf_check.value;
220 - if (ATTR_TRUE(value))
221 - return CRLF_TEXT;
222 - else if (ATTR_FALSE(value))
223 - return CRLF_BINARY;
224 - else if (ATTR_UNSET(value))
225 - ;
226 - else if (!strcmp(value, "input"))
227 - return CRLF_INPUT;
228 - /* fallthru */
229 - }
214 + const char *value = check->value;
215 +
216 + if (ATTR_TRUE(value))
217 + return CRLF_TEXT;
218 + else if (ATTR_FALSE(value))
219 + return CRLF_BINARY;
220 + else if (ATTR_UNSET(value))
221 + ;
222 + else if (!strcmp(value, "input"))
223 + return CRLF_INPUT;
224 return CRLF_GUESS;
225 }
226
227 char *convert_to_git(const char *path, const char *src, unsigned long *sizep)
228 {
235 - return crlf_to_git(path, src, sizep, git_path_check_crlf(path));
229 + struct git_attr_check check[1];
230 + int crlf = CRLF_GUESS;
231 +
232 + setup_convert_check(check);
233 + if (!git_checkattr(path, 1, check)) {
234 + crlf = git_path_check_crlf(path, check);
235 + }
236 + return crlf_to_git(path, src, sizep, crlf);
237 }
238
239 char *convert_to_working_tree(const char *path, const char *src, unsigned long *sizep)
240 {
240 - return crlf_to_worktree(path, src, sizep, git_path_check_crlf(path));
241 + struct git_attr_check check[1];
242 + int crlf = CRLF_GUESS;
243 +
244 + setup_convert_check(check);
245 + if (!git_checkattr(path, 1, check)) {
246 + crlf = git_path_check_crlf(path, check);
247 + }
248 + return crlf_to_worktree(path, src, sizep, crlf);
249 }