1414#include "commit-slab.h"
1515#include "revision.h"
1616#include "list-objects.h"
17+ #include "repository.h"
1718
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 )
2320{
24- if (is_shallow != -1 )
21+ if (r -> parsed_objects -> is_shallow != -1 )
2522 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 )
2724 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 );
3027}
3128
32- int register_shallow_the_repository ( const struct object_id * oid )
29+ int register_shallow ( struct repository * r , const struct object_id * oid )
3330{
3431 struct commit_graft * graft =
3532 xmalloc (sizeof (struct commit_graft ));
@@ -39,41 +36,41 @@ int register_shallow_the_repository(const struct object_id *oid)
3936 graft -> nr_parent = -1 ;
4037 if (commit && commit -> object .parsed )
4138 commit -> parents = NULL ;
42- return register_commit_graft (the_repository , graft , 0 );
39+ return register_commit_graft (r , graft , 0 );
4340}
4441
45- int is_repository_shallow_the_repository ( void )
42+ int is_repository_shallow ( struct repository * r )
4643{
4744 FILE * fp ;
4845 char buf [1024 ];
49- const char * path = alternate_shallow_file ;
46+ const char * path = r -> parsed_objects -> alternate_shallow_file ;
5047
51- if (is_shallow >= 0 )
52- return is_shallow ;
48+ if (r -> parsed_objects -> is_shallow >= 0 )
49+ return r -> parsed_objects -> is_shallow ;
5350
5451 if (!path )
55- path = git_path_shallow (the_repository );
52+ path = git_path_shallow (r );
5653 /*
5754 * fetch-pack sets '--shallow-file ""' as an indicator that no
5855 * shallow file should be used. We could just open it and it
5956 * will likely fail. But let's do an explicit check instead.
6057 */
6158 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 ;
6562 }
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 ;
6865
6966 while (fgets (buf , sizeof (buf ), fp )) {
7067 struct object_id oid ;
7168 if (get_oid_hex (buf , & oid ))
7269 die ("bad shallow line: %s" , buf );
73- register_shallow (the_repository , & oid );
70+ register_shallow (r , & oid );
7471 }
7572 fclose (fp );
76- return is_shallow ;
73+ return r -> parsed_objects -> is_shallow ;
7774}
7875
7976struct 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,
217214 return result ;
218215}
219216
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 )
222218{
223- if (is_shallow == -1 )
219+ if (r -> parsed_objects -> is_shallow == -1 )
224220 die ("BUG: shallow must be initialized by now" );
225221
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 )))
227223 die ("shallow file has changed since we read it" );
228224}
229225
0 commit comments