@@ -49,7 +49,7 @@ struct ref_cache *create_ref_cache(struct ref_store *refs,
4949
5050 ret -> ref_store = refs ;
5151 ret -> fill_ref_dir = fill_ref_dir ;
52- ret -> root = create_dir_entry (ret , "" , 0 , 1 );
52+ ret -> root = create_dir_entry (ret , "" , 0 );
5353 return ret ;
5454}
5555
@@ -86,14 +86,13 @@ static void clear_ref_dir(struct ref_dir *dir)
8686}
8787
8888struct ref_entry * create_dir_entry (struct ref_cache * cache ,
89- const char * dirname , size_t len ,
90- int incomplete )
89+ const char * dirname , size_t len )
9190{
9291 struct ref_entry * direntry ;
9392
9493 FLEX_ALLOC_MEM (direntry , name , dirname , len );
9594 direntry -> u .subdir .cache = cache ;
96- direntry -> flag = REF_DIR | ( incomplete ? REF_INCOMPLETE : 0 ) ;
95+ direntry -> flag = REF_DIR | REF_INCOMPLETE ;
9796 return direntry ;
9897}
9998
@@ -144,30 +143,19 @@ int search_ref_dir(struct ref_dir *dir, const char *refname, size_t len)
144143/*
145144 * Search for a directory entry directly within dir (without
146145 * recursing). Sort dir if necessary. subdirname must be a directory
147- * name (i.e., end in '/'). If mkdir is set, then create the
148- * directory if it is missing; otherwise, return NULL if the desired
146+ * name (i.e., end in '/'). Returns NULL if the desired
149147 * directory cannot be found. dir must already be complete.
150148 */
151149static struct ref_dir * search_for_subdir (struct ref_dir * dir ,
152- const char * subdirname , size_t len ,
153- int mkdir )
150+ const char * subdirname , size_t len )
154151{
155152 int entry_index = search_ref_dir (dir , subdirname , len );
156153 struct ref_entry * entry ;
157- if (entry_index == -1 ) {
158- if (!mkdir )
159- return NULL ;
160- /*
161- * Since dir is complete, the absence of a subdir
162- * means that the subdir really doesn't exist;
163- * therefore, create an empty record for it but mark
164- * the record complete.
165- */
166- entry = create_dir_entry (dir -> cache , subdirname , len , 0 );
167- add_entry_to_dir (dir , entry );
168- } else {
169- entry = dir -> entries [entry_index ];
170- }
154+
155+ if (entry_index == -1 )
156+ return NULL ;
157+
158+ entry = dir -> entries [entry_index ];
171159 return get_ref_dir (entry );
172160}
173161
@@ -176,18 +164,17 @@ static struct ref_dir *search_for_subdir(struct ref_dir *dir,
176164 * tree that should hold refname. If refname is a directory name
177165 * (i.e., it ends in '/'), then return that ref_dir itself. dir must
178166 * represent the top-level directory and must already be complete.
179- * Sort ref_dirs and recurse into subdirectories as necessary. If
180- * mkdir is set, then create any missing directories; otherwise,
167+ * Sort ref_dirs and recurse into subdirectories as necessary. Will
181168 * return NULL if the desired directory cannot be found.
182169 */
183170static struct ref_dir * find_containing_dir (struct ref_dir * dir ,
184- const char * refname , int mkdir )
171+ const char * refname )
185172{
186173 const char * slash ;
187174 for (slash = strchr (refname , '/' ); slash ; slash = strchr (slash + 1 , '/' )) {
188175 size_t dirnamelen = slash - refname + 1 ;
189176 struct ref_dir * subdir ;
190- subdir = search_for_subdir (dir , refname , dirnamelen , mkdir );
177+ subdir = search_for_subdir (dir , refname , dirnamelen );
191178 if (!subdir ) {
192179 dir = NULL ;
193180 break ;
@@ -202,7 +189,7 @@ struct ref_entry *find_ref_entry(struct ref_dir *dir, const char *refname)
202189{
203190 int entry_index ;
204191 struct ref_entry * entry ;
205- dir = find_containing_dir (dir , refname , 0 );
192+ dir = find_containing_dir (dir , refname );
206193 if (!dir )
207194 return NULL ;
208195 entry_index = search_ref_dir (dir , refname , strlen (refname ));
@@ -212,50 +199,6 @@ struct ref_entry *find_ref_entry(struct ref_dir *dir, const char *refname)
212199 return (entry -> flag & REF_DIR ) ? NULL : entry ;
213200}
214201
215- int remove_entry_from_dir (struct ref_dir * dir , const char * refname )
216- {
217- int refname_len = strlen (refname );
218- int entry_index ;
219- struct ref_entry * entry ;
220- int is_dir = refname [refname_len - 1 ] == '/' ;
221- if (is_dir ) {
222- /*
223- * refname represents a reference directory. Remove
224- * the trailing slash; otherwise we will get the
225- * directory *representing* refname rather than the
226- * one *containing* it.
227- */
228- char * dirname = xmemdupz (refname , refname_len - 1 );
229- dir = find_containing_dir (dir , dirname , 0 );
230- free (dirname );
231- } else {
232- dir = find_containing_dir (dir , refname , 0 );
233- }
234- if (!dir )
235- return -1 ;
236- entry_index = search_ref_dir (dir , refname , refname_len );
237- if (entry_index == -1 )
238- return -1 ;
239- entry = dir -> entries [entry_index ];
240-
241- MOVE_ARRAY (& dir -> entries [entry_index ],
242- & dir -> entries [entry_index + 1 ], dir -> nr - entry_index - 1 );
243- dir -> nr -- ;
244- if (dir -> sorted > entry_index )
245- dir -> sorted -- ;
246- free_ref_entry (entry );
247- return dir -> nr ;
248- }
249-
250- int add_ref_entry (struct ref_dir * dir , struct ref_entry * ref )
251- {
252- dir = find_containing_dir (dir , ref -> name , 1 );
253- if (!dir )
254- return -1 ;
255- add_entry_to_dir (dir , ref );
256- return 0 ;
257- }
258-
259202/*
260203 * Emit a warning and return true iff ref1 and ref2 have the same name
261204 * and the same oid. Die if they have the same name but different
@@ -522,7 +465,7 @@ struct ref_iterator *cache_ref_iterator_begin(struct ref_cache *cache,
522465
523466 dir = get_ref_dir (cache -> root );
524467 if (prefix && * prefix )
525- dir = find_containing_dir (dir , prefix , 0 );
468+ dir = find_containing_dir (dir , prefix );
526469 if (!dir )
527470 /* There's nothing to iterate over. */
528471 return empty_ref_iterator_begin ();
0 commit comments