@matheusbsbs / matheus-bagliano / commits / 571998921d
Fork 0

lstat_cache(): swap func(length, string) into func(string, length)

Swap function argument pair (length, string) into (string, length) to conform with the commonly used order inside the GIT source code. Also, add a note about this fact into the coding guidelines. Signed-off-by: Kjetil Barvik <barvik@broadpark.no> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kjetil Barvik committed Feb 9, 2009 at 21:54 UTC 571998921d8fd4ee674545406aabb86987921252
10 files changed +23 -20
Documentation/CodingGuidelines
+3
@@ -129,3 +129,6 @@ For C programs:
129 used in the git core command set (unless your command is clearly
130 separate from it, such as an importer to convert random-scm-X
131 repositories to git).
132 +
133 + - When we pass <string, length> pair to functions, we should try to
134 + pass them in that order.
builtin-add.c
+1 -1
@@ -148,7 +148,7 @@ static const char **validate_pathspec(int argc, const char **argv, const char *p
148 if (pathspec) {
149 const char **p;
150 for (p = pathspec; *p; p++) {
151 - if (has_symlink_leading_path(strlen(*p), *p)) {
151 + if (has_symlink_leading_path(*p, strlen(*p))) {
152 int len = prefix ? strlen(prefix) : 0;
153 die("'%s' is beyond a symbolic link", *p + len);
154 }
builtin-apply.c
+1 -1
@@ -2360,7 +2360,7 @@ static int check_to_create_blob(const char *new_name, int ok_if_exists)
2360 * In such a case, path "new_name" does not exist as
2361 * far as git is concerned.
2362 */
2363 - if (has_symlink_leading_path(strlen(new_name), new_name))
2363 + if (has_symlink_leading_path(new_name, strlen(new_name)))
2364 return 0;
2365
2366 return error("%s: already exists in working directory", new_name);
builtin-update-index.c
+1 -1
@@ -195,7 +195,7 @@ static int process_path(const char *path)
195 struct stat st;
196
197 len = strlen(path);
198 - if (has_symlink_leading_path(len, path))
198 + if (has_symlink_leading_path(path, len))
199 return error("'%s' is beyond a symbolic link", path);
200
201 /*
cache.h
+4 -4
@@ -724,10 +724,10 @@ struct checkout {
724 };
725
726 extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath);
727 -extern int has_symlink_leading_path(int len, const char *name);
728 -extern int has_symlink_or_noent_leading_path(int len, const char *name);
729 -extern int has_dirs_only_path(int len, const char *name, int prefix_len);
730 -extern void invalidate_lstat_cache(int len, const char *name);
727 +extern int has_symlink_leading_path(const char *name, int len);
728 +extern int has_symlink_or_noent_leading_path(const char *name, int len);
729 +extern int has_dirs_only_path(const char *name, int len, int prefix_len);
730 +extern void invalidate_lstat_cache(const char *name, int len);
731 extern void clear_lstat_cache(void);
732
733 extern struct alternate_object_database {
diff-lib.c
+1 -1
@@ -31,7 +31,7 @@ static int check_removed(const struct cache_entry *ce, struct stat *st)
31 return -1;
32 return 1;
33 }
34 - if (has_symlink_leading_path(ce_namelen(ce), ce->name))
34 + if (has_symlink_leading_path(ce->name, ce_namelen(ce)))
35 return 1;
36 if (S_ISDIR(st->st_mode)) {
37 unsigned char sub[20];
dir.c
+1 -1
@@ -720,7 +720,7 @@ int read_directory(struct dir_struct *dir, const char *path, const char *base, i
720 {
721 struct path_simplify *simplify;
722
723 - if (has_symlink_leading_path(strlen(path), path))
723 + if (has_symlink_leading_path(path, strlen(path)))
724 return dir->nr;
725
726 simplify = create_simplify(pathspec);
entry.c
+1 -1
@@ -20,7 +20,7 @@ static void create_directories(const char *path, const struct checkout *state)
20 * we test the path components of the prefix with the
21 * stat() function instead of the lstat() function.
22 */
23 - if (has_dirs_only_path(len, buf, state->base_dir_len))
23 + if (has_dirs_only_path(buf, len, state->base_dir_len))
24 continue; /* ok, it is already a directory. */
25
26 /*
symlinks.c
+8 -8
@@ -70,7 +70,7 @@ static inline void reset_lstat_cache(void)
70 * of the prefix, where the cache should use the stat() function
71 * instead of the lstat() function to test each path component.
72 */
73 -static int lstat_cache(int len, const char *name,
73 +static int lstat_cache(const char *name, int len,
74 int track_flags, int prefix_len_stat_func)
75 {
76 int match_len, last_slash, last_slash_dir, previous_slash;
@@ -185,7 +185,7 @@ static int lstat_cache(int len, const char *name,
185 * Invalidate the given 'name' from the cache, if 'name' matches
186 * completely with the cache.
187 */
188 -void invalidate_lstat_cache(int len, const char *name)
188 +void invalidate_lstat_cache(const char *name, int len)
189 {
190 int match_len, previous_slash;
191
@@ -214,9 +214,9 @@ void clear_lstat_cache(void)
214 /*
215 * Return non-zero if path 'name' has a leading symlink component
216 */
217 -int has_symlink_leading_path(int len, const char *name)
217 +int has_symlink_leading_path(const char *name, int len)
218 {
219 - return lstat_cache(len, name,
219 + return lstat_cache(name, len,
220 FL_SYMLINK|FL_DIR, USE_ONLY_LSTAT) &
221 FL_SYMLINK;
222 }
@@ -225,9 +225,9 @@ int has_symlink_leading_path(int len, const char *name)
225 * Return non-zero if path 'name' has a leading symlink component or
226 * if some leading path component does not exists.
227 */
228 -int has_symlink_or_noent_leading_path(int len, const char *name)
228 +int has_symlink_or_noent_leading_path(const char *name, int len)
229 {
230 - return lstat_cache(len, name,
230 + return lstat_cache(name, len,
231 FL_SYMLINK|FL_NOENT|FL_DIR, USE_ONLY_LSTAT) &
232 (FL_SYMLINK|FL_NOENT);
233 }
@@ -239,9 +239,9 @@ int has_symlink_or_noent_leading_path(int len, const char *name)
239 * 'prefix_len', thus we then allow for symlinks in the prefix part as
240 * long as those points to real existing directories.
241 */
242 -int has_dirs_only_path(int len, const char *name, int prefix_len)
242 +int has_dirs_only_path(const char *name, int len, int prefix_len)
243 {
244 - return lstat_cache(len, name,
244 + return lstat_cache(name, len,
245 FL_DIR|FL_FULLPATH, prefix_len) &
246 FL_DIR;
247 }
unpack-trees.c
+2 -2
@@ -61,7 +61,7 @@ static void unlink_entry(struct cache_entry *ce)
61 char *cp, *prev;
62 char *name = ce->name;
63
64 - if (has_symlink_or_noent_leading_path(ce_namelen(ce), ce->name))
64 + if (has_symlink_or_noent_leading_path(ce->name, ce_namelen(ce)))
65 return;
66 if (unlink(name))
67 return;
@@ -583,7 +583,7 @@ static int verify_absent(struct cache_entry *ce, const char *action,
583 if (o->index_only || o->reset || !o->update)
584 return 0;
585
586 - if (has_symlink_or_noent_leading_path(ce_namelen(ce), ce->name))
586 + if (has_symlink_or_noent_leading_path(ce->name, ce_namelen(ce)))
587 return 0;
588
589 if (!lstat(ce->name, &st)) {