dir.h: refactor to no longer need to include cache.h

Moving a few functions around allows us to make dir.h no longer need to
include cache.h.  This commit is best viewed with:
    git log -1 -p --color-moved

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Elijah Newren 2023-02-24 00:09:31 +00:00 committed by Junio C Hamano
parent a64215b6cd
commit ac48adf488
5 changed files with 43 additions and 35 deletions

31
cache.h
View File

@ -14,9 +14,11 @@
#include "pack-revindex.h" #include "pack-revindex.h"
#include "hash.h" #include "hash.h"
#include "path.h" #include "path.h"
#include "pathspec.h"
#include "object.h" #include "object.h"
#include "oid-array.h" #include "oid-array.h"
#include "repository.h" #include "repository.h"
#include "statinfo.h"
#include "mem-pool.h" #include "mem-pool.h"
typedef struct git_zstream { typedef struct git_zstream {
@ -119,26 +121,6 @@ struct cache_header {
#define INDEX_FORMAT_LB 2 #define INDEX_FORMAT_LB 2
#define INDEX_FORMAT_UB 4 #define INDEX_FORMAT_UB 4
/*
* The "cache_time" is just the low 32 bits of the
* time. It doesn't matter if it overflows - we only
* check it for equality in the 32 bits we save.
*/
struct cache_time {
uint32_t sec;
uint32_t nsec;
};
struct stat_data {
struct cache_time sd_ctime;
struct cache_time sd_mtime;
unsigned int sd_dev;
unsigned int sd_ino;
unsigned int sd_uid;
unsigned int sd_gid;
unsigned int sd_size;
};
struct cache_entry { struct cache_entry {
struct hashmap_entry ent; struct hashmap_entry ent;
struct stat_data ce_stat_data; struct stat_data ce_stat_data;
@ -294,6 +276,15 @@ static inline unsigned int canon_mode(unsigned int mode)
return S_IFGITLINK; return S_IFGITLINK;
} }
static inline int ce_path_match(struct index_state *istate,
const struct cache_entry *ce,
const struct pathspec *pathspec,
char *seen)
{
return match_pathspec(istate, pathspec, ce->name, ce_namelen(ce), 0, seen,
S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode));
}
#define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1) #define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1)
#define SOMETHING_CHANGED (1 << 0) /* unclassified changes go here */ #define SOMETHING_CHANGED (1 << 0) /* unclassified changes go here */

16
dir.h
View File

@ -1,8 +1,9 @@
#ifndef DIR_H #ifndef DIR_H
#define DIR_H #define DIR_H
#include "cache.h"
#include "hashmap.h" #include "hashmap.h"
#include "pathspec.h"
#include "statinfo.h"
#include "strbuf.h" #include "strbuf.h"
/** /**
@ -363,10 +364,6 @@ int count_slashes(const char *s);
int simple_length(const char *match); int simple_length(const char *match);
int no_wildcard(const char *string); int no_wildcard(const char *string);
char *common_prefix(const struct pathspec *pathspec); char *common_prefix(const struct pathspec *pathspec);
int match_pathspec(struct index_state *istate,
const struct pathspec *pathspec,
const char *name, int namelen,
int prefix, char *seen, int is_dir);
int report_path_error(const char *ps_matched, const struct pathspec *pathspec); int report_path_error(const char *ps_matched, const struct pathspec *pathspec);
int within_depth(const char *name, int namelen, int depth, int max_depth); int within_depth(const char *name, int namelen, int depth, int max_depth);
@ -533,15 +530,6 @@ int submodule_path_match(struct index_state *istate,
const char *submodule_name, const char *submodule_name,
char *seen); char *seen);
static inline int ce_path_match(struct index_state *istate,
const struct cache_entry *ce,
const struct pathspec *pathspec,
char *seen)
{
return match_pathspec(istate, pathspec, ce->name, ce_namelen(ce), 0, seen,
S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode));
}
static inline int dir_path_match(struct index_state *istate, static inline int dir_path_match(struct index_state *istate,
const struct dir_entry *ent, const struct dir_entry *ent,
const struct pathspec *pathspec, const struct pathspec *pathspec,

View File

@ -171,6 +171,11 @@ int match_pathspec_attrs(struct index_state *istate,
const char *name, int namelen, const char *name, int namelen,
const struct pathspec_item *item); const struct pathspec_item *item);
int match_pathspec(struct index_state *istate,
const struct pathspec *pathspec,
const char *name, int namelen,
int prefix, char *seen, int is_dir);
/* /*
* Determine whether a pathspec will match only entire index entries (non-sparse * Determine whether a pathspec will match only entire index entries (non-sparse
* files and/or entire sparse directories). If the pathspec has the potential to * files and/or entire sparse directories). If the pathspec has the potential to

24
statinfo.h Normal file
View File

@ -0,0 +1,24 @@
#ifndef STATINFO_H
#define STATINFO_H
/*
* The "cache_time" is just the low 32 bits of the
* time. It doesn't matter if it overflows - we only
* check it for equality in the 32 bits we save.
*/
struct cache_time {
uint32_t sec;
uint32_t nsec;
};
struct stat_data {
struct cache_time sd_ctime;
struct cache_time sd_mtime;
unsigned int sd_dev;
unsigned int sd_ino;
unsigned int sd_uid;
unsigned int sd_gid;
unsigned int sd_size;
};
#endif

View File

@ -1,4 +1,4 @@
#include "cache.h" #include "git-compat-util.h"
#include "config.h" #include "config.h"
#include "dir.h" #include "dir.h"
#include "tr2_sysenv.h" #include "tr2_sysenv.h"