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>
This commit is contained in:
parent
148bc06b91
commit
571998921d
@ -129,3 +129,6 @@ For C programs:
|
||||
used in the git core command set (unless your command is clearly
|
||||
separate from it, such as an importer to convert random-scm-X
|
||||
repositories to git).
|
||||
|
||||
- When we pass <string, length> pair to functions, we should try to
|
||||
pass them in that order.
|
||||
|
@ -148,7 +148,7 @@ static const char **validate_pathspec(int argc, const char **argv, const char *p
|
||||
if (pathspec) {
|
||||
const char **p;
|
||||
for (p = pathspec; *p; p++) {
|
||||
if (has_symlink_leading_path(strlen(*p), *p)) {
|
||||
if (has_symlink_leading_path(*p, strlen(*p))) {
|
||||
int len = prefix ? strlen(prefix) : 0;
|
||||
die("'%s' is beyond a symbolic link", *p + len);
|
||||
}
|
||||
|
@ -2360,7 +2360,7 @@ static int check_to_create_blob(const char *new_name, int ok_if_exists)
|
||||
* In such a case, path "new_name" does not exist as
|
||||
* far as git is concerned.
|
||||
*/
|
||||
if (has_symlink_leading_path(strlen(new_name), new_name))
|
||||
if (has_symlink_leading_path(new_name, strlen(new_name)))
|
||||
return 0;
|
||||
|
||||
return error("%s: already exists in working directory", new_name);
|
||||
|
@ -195,7 +195,7 @@ static int process_path(const char *path)
|
||||
struct stat st;
|
||||
|
||||
len = strlen(path);
|
||||
if (has_symlink_leading_path(len, path))
|
||||
if (has_symlink_leading_path(path, len))
|
||||
return error("'%s' is beyond a symbolic link", path);
|
||||
|
||||
/*
|
||||
|
8
cache.h
8
cache.h
@ -724,10 +724,10 @@ struct checkout {
|
||||
};
|
||||
|
||||
extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath);
|
||||
extern int has_symlink_leading_path(int len, const char *name);
|
||||
extern int has_symlink_or_noent_leading_path(int len, const char *name);
|
||||
extern int has_dirs_only_path(int len, const char *name, int prefix_len);
|
||||
extern void invalidate_lstat_cache(int len, const char *name);
|
||||
extern int has_symlink_leading_path(const char *name, int len);
|
||||
extern int has_symlink_or_noent_leading_path(const char *name, int len);
|
||||
extern int has_dirs_only_path(const char *name, int len, int prefix_len);
|
||||
extern void invalidate_lstat_cache(const char *name, int len);
|
||||
extern void clear_lstat_cache(void);
|
||||
|
||||
extern struct alternate_object_database {
|
||||
|
@ -31,7 +31,7 @@ static int check_removed(const struct cache_entry *ce, struct stat *st)
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
if (has_symlink_leading_path(ce_namelen(ce), ce->name))
|
||||
if (has_symlink_leading_path(ce->name, ce_namelen(ce)))
|
||||
return 1;
|
||||
if (S_ISDIR(st->st_mode)) {
|
||||
unsigned char sub[20];
|
||||
|
2
dir.c
2
dir.c
@ -720,7 +720,7 @@ int read_directory(struct dir_struct *dir, const char *path, const char *base, i
|
||||
{
|
||||
struct path_simplify *simplify;
|
||||
|
||||
if (has_symlink_leading_path(strlen(path), path))
|
||||
if (has_symlink_leading_path(path, strlen(path)))
|
||||
return dir->nr;
|
||||
|
||||
simplify = create_simplify(pathspec);
|
||||
|
2
entry.c
2
entry.c
@ -20,7 +20,7 @@ static void create_directories(const char *path, const struct checkout *state)
|
||||
* we test the path components of the prefix with the
|
||||
* stat() function instead of the lstat() function.
|
||||
*/
|
||||
if (has_dirs_only_path(len, buf, state->base_dir_len))
|
||||
if (has_dirs_only_path(buf, len, state->base_dir_len))
|
||||
continue; /* ok, it is already a directory. */
|
||||
|
||||
/*
|
||||
|
16
symlinks.c
16
symlinks.c
@ -70,7 +70,7 @@ static inline void reset_lstat_cache(void)
|
||||
* of the prefix, where the cache should use the stat() function
|
||||
* instead of the lstat() function to test each path component.
|
||||
*/
|
||||
static int lstat_cache(int len, const char *name,
|
||||
static int lstat_cache(const char *name, int len,
|
||||
int track_flags, int prefix_len_stat_func)
|
||||
{
|
||||
int match_len, last_slash, last_slash_dir, previous_slash;
|
||||
@ -185,7 +185,7 @@ static int lstat_cache(int len, const char *name,
|
||||
* Invalidate the given 'name' from the cache, if 'name' matches
|
||||
* completely with the cache.
|
||||
*/
|
||||
void invalidate_lstat_cache(int len, const char *name)
|
||||
void invalidate_lstat_cache(const char *name, int len)
|
||||
{
|
||||
int match_len, previous_slash;
|
||||
|
||||
@ -214,9 +214,9 @@ void clear_lstat_cache(void)
|
||||
/*
|
||||
* Return non-zero if path 'name' has a leading symlink component
|
||||
*/
|
||||
int has_symlink_leading_path(int len, const char *name)
|
||||
int has_symlink_leading_path(const char *name, int len)
|
||||
{
|
||||
return lstat_cache(len, name,
|
||||
return lstat_cache(name, len,
|
||||
FL_SYMLINK|FL_DIR, USE_ONLY_LSTAT) &
|
||||
FL_SYMLINK;
|
||||
}
|
||||
@ -225,9 +225,9 @@ int has_symlink_leading_path(int len, const char *name)
|
||||
* Return non-zero if path 'name' has a leading symlink component or
|
||||
* if some leading path component does not exists.
|
||||
*/
|
||||
int has_symlink_or_noent_leading_path(int len, const char *name)
|
||||
int has_symlink_or_noent_leading_path(const char *name, int len)
|
||||
{
|
||||
return lstat_cache(len, name,
|
||||
return lstat_cache(name, len,
|
||||
FL_SYMLINK|FL_NOENT|FL_DIR, USE_ONLY_LSTAT) &
|
||||
(FL_SYMLINK|FL_NOENT);
|
||||
}
|
||||
@ -239,9 +239,9 @@ int has_symlink_or_noent_leading_path(int len, const char *name)
|
||||
* 'prefix_len', thus we then allow for symlinks in the prefix part as
|
||||
* long as those points to real existing directories.
|
||||
*/
|
||||
int has_dirs_only_path(int len, const char *name, int prefix_len)
|
||||
int has_dirs_only_path(const char *name, int len, int prefix_len)
|
||||
{
|
||||
return lstat_cache(len, name,
|
||||
return lstat_cache(name, len,
|
||||
FL_DIR|FL_FULLPATH, prefix_len) &
|
||||
FL_DIR;
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ static void unlink_entry(struct cache_entry *ce)
|
||||
char *cp, *prev;
|
||||
char *name = ce->name;
|
||||
|
||||
if (has_symlink_or_noent_leading_path(ce_namelen(ce), ce->name))
|
||||
if (has_symlink_or_noent_leading_path(ce->name, ce_namelen(ce)))
|
||||
return;
|
||||
if (unlink(name))
|
||||
return;
|
||||
@ -583,7 +583,7 @@ static int verify_absent(struct cache_entry *ce, const char *action,
|
||||
if (o->index_only || o->reset || !o->update)
|
||||
return 0;
|
||||
|
||||
if (has_symlink_or_noent_leading_path(ce_namelen(ce), ce->name))
|
||||
if (has_symlink_or_noent_leading_path(ce->name, ce_namelen(ce)))
|
||||
return 0;
|
||||
|
||||
if (!lstat(ce->name, &st)) {
|
||||
|
Loading…
Reference in New Issue
Block a user