|
10 | 10 | #include "commit-slab.h"
|
11 | 11 |
|
12 | 12 | static int is_shallow = -1;
|
13 |
| -static struct stat shallow_stat; |
| 13 | +static struct stat_validity shallow_stat; |
14 | 14 | static char *alternate_shallow_file;
|
15 | 15 |
|
16 | 16 | void set_alternate_shallow_file(const char *path, int override)
|
@@ -52,12 +52,12 @@ int is_repository_shallow(void)
|
52 | 52 | * shallow file should be used. We could just open it and it
|
53 | 53 | * will likely fail. But let's do an explicit check instead.
|
54 | 54 | */
|
55 |
| - if (!*path || |
56 |
| - stat(path, &shallow_stat) || |
57 |
| - (fp = fopen(path, "r")) == NULL) { |
| 55 | + if (!*path || (fp = fopen(path, "r")) == NULL) { |
| 56 | + stat_validity_clear(&shallow_stat); |
58 | 57 | is_shallow = 0;
|
59 | 58 | return is_shallow;
|
60 | 59 | }
|
| 60 | + stat_validity_update(&shallow_stat, fileno(fp)); |
61 | 61 | is_shallow = 1;
|
62 | 62 |
|
63 | 63 | while (fgets(buf, sizeof(buf), fp)) {
|
@@ -137,21 +137,11 @@ struct commit_list *get_shallow_commits(struct object_array *heads, int depth,
|
137 | 137 |
|
138 | 138 | void check_shallow_file_for_update(void)
|
139 | 139 | {
|
140 |
| - struct stat st; |
141 |
| - |
142 |
| - if (!is_shallow) |
143 |
| - return; |
144 |
| - else if (is_shallow == -1) |
| 140 | + if (is_shallow == -1) |
145 | 141 | die("BUG: shallow must be initialized by now");
|
146 | 142 |
|
147 |
| - if (stat(git_path("shallow"), &st)) |
148 |
| - die("shallow file was removed during fetch"); |
149 |
| - else if (st.st_mtime != shallow_stat.st_mtime |
150 |
| -#ifdef USE_NSEC |
151 |
| - || ST_MTIME_NSEC(st) != ST_MTIME_NSEC(shallow_stat) |
152 |
| -#endif |
153 |
| - ) |
154 |
| - die("shallow file was changed during fetch"); |
| 143 | + if (!stat_validity_check(&shallow_stat, git_path("shallow"))) |
| 144 | + die("shallow file has changed since we read it"); |
155 | 145 | }
|
156 | 146 |
|
157 | 147 | #define SEEN_ONLY 1
|
|
0 commit comments