14
14
#include "commit-slab.h"
15
15
#include "revision.h"
16
16
#include "list-objects.h"
17
+ #include "repository.h"
17
18
18
- static int is_shallow = -1 ;
19
- static struct stat_validity shallow_stat ;
20
- static char * alternate_shallow_file ;
21
-
22
- void set_alternate_shallow_file_the_repository (const char * path , int override )
19
+ void set_alternate_shallow_file (struct repository * r , const char * path , int override )
23
20
{
24
- if (is_shallow != -1 )
21
+ if (r -> parsed_objects -> is_shallow != -1 )
25
22
die ("BUG: is_repository_shallow must not be called before set_alternate_shallow_file" );
26
- if (alternate_shallow_file && !override )
23
+ if (r -> parsed_objects -> alternate_shallow_file && !override )
27
24
return ;
28
- free (alternate_shallow_file );
29
- alternate_shallow_file = xstrdup_or_null (path );
25
+ free (r -> parsed_objects -> alternate_shallow_file );
26
+ r -> parsed_objects -> alternate_shallow_file = xstrdup_or_null (path );
30
27
}
31
28
32
- int register_shallow_the_repository ( const struct object_id * oid )
29
+ int register_shallow ( struct repository * r , const struct object_id * oid )
33
30
{
34
31
struct commit_graft * graft =
35
32
xmalloc (sizeof (struct commit_graft ));
@@ -39,41 +36,41 @@ int register_shallow_the_repository(const struct object_id *oid)
39
36
graft -> nr_parent = -1 ;
40
37
if (commit && commit -> object .parsed )
41
38
commit -> parents = NULL ;
42
- return register_commit_graft (the_repository , graft , 0 );
39
+ return register_commit_graft (r , graft , 0 );
43
40
}
44
41
45
- int is_repository_shallow_the_repository ( void )
42
+ int is_repository_shallow ( struct repository * r )
46
43
{
47
44
FILE * fp ;
48
45
char buf [1024 ];
49
- const char * path = alternate_shallow_file ;
46
+ const char * path = r -> parsed_objects -> alternate_shallow_file ;
50
47
51
- if (is_shallow >= 0 )
52
- return is_shallow ;
48
+ if (r -> parsed_objects -> is_shallow >= 0 )
49
+ return r -> parsed_objects -> is_shallow ;
53
50
54
51
if (!path )
55
- path = git_path_shallow (the_repository );
52
+ path = git_path_shallow (r );
56
53
/*
57
54
* fetch-pack sets '--shallow-file ""' as an indicator that no
58
55
* shallow file should be used. We could just open it and it
59
56
* will likely fail. But let's do an explicit check instead.
60
57
*/
61
58
if (!* path || (fp = fopen (path , "r" )) == NULL ) {
62
- stat_validity_clear (& shallow_stat );
63
- is_shallow = 0 ;
64
- return is_shallow ;
59
+ stat_validity_clear (r -> parsed_objects -> shallow_stat );
60
+ r -> parsed_objects -> is_shallow = 0 ;
61
+ return r -> parsed_objects -> is_shallow ;
65
62
}
66
- stat_validity_update (& shallow_stat , fileno (fp ));
67
- is_shallow = 1 ;
63
+ stat_validity_update (r -> parsed_objects -> shallow_stat , fileno (fp ));
64
+ r -> parsed_objects -> is_shallow = 1 ;
68
65
69
66
while (fgets (buf , sizeof (buf ), fp )) {
70
67
struct object_id oid ;
71
68
if (get_oid_hex (buf , & oid ))
72
69
die ("bad shallow line: %s" , buf );
73
- register_shallow (the_repository , & oid );
70
+ register_shallow (r , & oid );
74
71
}
75
72
fclose (fp );
76
- return is_shallow ;
73
+ return r -> parsed_objects -> is_shallow ;
77
74
}
78
75
79
76
struct commit_list * get_shallow_commits (struct object_array * heads , int depth ,
@@ -217,13 +214,12 @@ struct commit_list *get_shallow_commits_by_rev_list(int ac, const char **av,
217
214
return result ;
218
215
}
219
216
220
- #define check_shallow_file_for_update (r ) check_shallow_file_for_update_##r()
221
- static void check_shallow_file_for_update_the_repository (void )
217
+ static void check_shallow_file_for_update (struct repository * r )
222
218
{
223
- if (is_shallow == -1 )
219
+ if (r -> parsed_objects -> is_shallow == -1 )
224
220
die ("BUG: shallow must be initialized by now" );
225
221
226
- if (!stat_validity_check (& shallow_stat , git_path_shallow (the_repository )))
222
+ if (!stat_validity_check (r -> parsed_objects -> shallow_stat , git_path_shallow (the_repository )))
227
223
die ("shallow file has changed since we read it" );
228
224
}
229
225
0 commit comments