Skip to content

Commit ac48adf

Browse files
newrengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a64215b commit ac48adf

File tree

5 files changed

+43
-35
lines changed

5 files changed

+43
-35
lines changed

cache.h

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
#include "pack-revindex.h"
1515
#include "hash.h"
1616
#include "path.h"
17+
#include "pathspec.h"
1718
#include "object.h"
1819
#include "oid-array.h"
1920
#include "repository.h"
21+
#include "statinfo.h"
2022
#include "mem-pool.h"
2123

2224
typedef struct git_zstream {
@@ -119,26 +121,6 @@ struct cache_header {
119121
#define INDEX_FORMAT_LB 2
120122
#define INDEX_FORMAT_UB 4
121123

122-
/*
123-
* The "cache_time" is just the low 32 bits of the
124-
* time. It doesn't matter if it overflows - we only
125-
* check it for equality in the 32 bits we save.
126-
*/
127-
struct cache_time {
128-
uint32_t sec;
129-
uint32_t nsec;
130-
};
131-
132-
struct stat_data {
133-
struct cache_time sd_ctime;
134-
struct cache_time sd_mtime;
135-
unsigned int sd_dev;
136-
unsigned int sd_ino;
137-
unsigned int sd_uid;
138-
unsigned int sd_gid;
139-
unsigned int sd_size;
140-
};
141-
142124
struct cache_entry {
143125
struct hashmap_entry ent;
144126
struct stat_data ce_stat_data;
@@ -294,6 +276,15 @@ static inline unsigned int canon_mode(unsigned int mode)
294276
return S_IFGITLINK;
295277
}
296278

279+
static inline int ce_path_match(struct index_state *istate,
280+
const struct cache_entry *ce,
281+
const struct pathspec *pathspec,
282+
char *seen)
283+
{
284+
return match_pathspec(istate, pathspec, ce->name, ce_namelen(ce), 0, seen,
285+
S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode));
286+
}
287+
297288
#define cache_entry_size(len) (offsetof(struct cache_entry,name) + (len) + 1)
298289

299290
#define SOMETHING_CHANGED (1 << 0) /* unclassified changes go here */

dir.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#ifndef DIR_H
22
#define DIR_H
33

4-
#include "cache.h"
54
#include "hashmap.h"
5+
#include "pathspec.h"
6+
#include "statinfo.h"
67
#include "strbuf.h"
78

89
/**
@@ -363,10 +364,6 @@ int count_slashes(const char *s);
363364
int simple_length(const char *match);
364365
int no_wildcard(const char *string);
365366
char *common_prefix(const struct pathspec *pathspec);
366-
int match_pathspec(struct index_state *istate,
367-
const struct pathspec *pathspec,
368-
const char *name, int namelen,
369-
int prefix, char *seen, int is_dir);
370367
int report_path_error(const char *ps_matched, const struct pathspec *pathspec);
371368
int within_depth(const char *name, int namelen, int depth, int max_depth);
372369

@@ -533,15 +530,6 @@ int submodule_path_match(struct index_state *istate,
533530
const char *submodule_name,
534531
char *seen);
535532

536-
static inline int ce_path_match(struct index_state *istate,
537-
const struct cache_entry *ce,
538-
const struct pathspec *pathspec,
539-
char *seen)
540-
{
541-
return match_pathspec(istate, pathspec, ce->name, ce_namelen(ce), 0, seen,
542-
S_ISDIR(ce->ce_mode) || S_ISGITLINK(ce->ce_mode));
543-
}
544-
545533
static inline int dir_path_match(struct index_state *istate,
546534
const struct dir_entry *ent,
547535
const struct pathspec *pathspec,

pathspec.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ int match_pathspec_attrs(struct index_state *istate,
171171
const char *name, int namelen,
172172
const struct pathspec_item *item);
173173

174+
int match_pathspec(struct index_state *istate,
175+
const struct pathspec *pathspec,
176+
const char *name, int namelen,
177+
int prefix, char *seen, int is_dir);
178+
174179
/*
175180
* Determine whether a pathspec will match only entire index entries (non-sparse
176181
* files and/or entire sparse directories). If the pathspec has the potential to

statinfo.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#ifndef STATINFO_H
2+
#define STATINFO_H
3+
4+
/*
5+
* The "cache_time" is just the low 32 bits of the
6+
* time. It doesn't matter if it overflows - we only
7+
* check it for equality in the 32 bits we save.
8+
*/
9+
struct cache_time {
10+
uint32_t sec;
11+
uint32_t nsec;
12+
};
13+
14+
struct stat_data {
15+
struct cache_time sd_ctime;
16+
struct cache_time sd_mtime;
17+
unsigned int sd_dev;
18+
unsigned int sd_ino;
19+
unsigned int sd_uid;
20+
unsigned int sd_gid;
21+
unsigned int sd_size;
22+
};
23+
24+
#endif

trace2/tr2_sysenv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "cache.h"
1+
#include "git-compat-util.h"
22
#include "config.h"
33
#include "dir.h"
44
#include "tr2_sysenv.h"

0 commit comments

Comments
 (0)