Skip to content

Commit

Permalink
lstat_cache(): swap func(length, string) into func(string, length)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Kjetil Barvik authored and Junio C Hamano committed Feb 10, 2009
1 parent 148bc06 commit 5719989
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 20 deletions.
3 changes: 3 additions & 0 deletions Documentation/CodingGuidelines
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion builtin-add.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion builtin-apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion builtin-update-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/*
Expand Down
8 changes: 4 additions & 4 deletions cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion diff-lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
2 changes: 1 addition & 1 deletion dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */

/*
Expand Down
16 changes: 8 additions & 8 deletions symlinks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand All @@ -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;
}
4 changes: 2 additions & 2 deletions unpack-trees.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 5719989

Please sign in to comment.