Skip to content

Remove submodule from files-backend.c

Nguyễn Thái Ngọc Duy git 7 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v7 Latest28 patches 9 repliesIn review
  2. v627 patches 20 repliesSuperseded
  3. v524 patches 36 repliesSuperseded
Earlier versions · 4
VersionPostedPatchesRepliesStatus
v415 patches11 repliesSuperseded
v316 patches3 repliesSuperseded
v216 patches6 repliesSuperseded
v111 patches21 repliesSuperseded

Patches in v7 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/28refs.h: add forward declaration for structs used in this filerefs.h+4 -00 replies
2/28files-backend: make files_log_ref_write() staticrefs/files-backend.c refs/refs-internal.h+6 -70 replies
3/28files-backend.c: delete dead code in files_ref_iterator_begin()refs/files-backend.c+0 -30 replies
4/28files-backend: delete dead code in files_init_db()refs/files-backend.c+0 -40 replies
5/28files-backend: add and use files_packed_refs_path()refs/files-backend.c+18 -110 replies
6/28files-backend: make sure files_rename_ref() always reach the endrefs/files-backend.c+28 -140 replies
7/28files-backend: convert git_path() to strbuf_git_path()refs/files-backend.c+97 -330 replies
8/28files-backend: move "logs/" out of TMP_RENAMED_LOGrefs/files-backend.c+5 -50 replies
9/28files-backend: add and use files_reflog_path()refs/files-backend.c+86 -560 replies
10/28files-backend: add and use files_ref_path()refs/files-backend.c+23 -240 replies
11/28files-backend: remove the use of git_path()refs/files-backend.c+38 -50 replies
12/28refs.c: introduce get_main_ref_store()refs.c+9 -40 replies
13/28refs: rename lookup_ref_store() to lookup_submodule_ref_store()refs.c+4 -90 replies
14/28refs.c: flatten get_ref_store() a bitrefs.c+13 -100 replies
15/28refs.c: kill register_ref_store(), add register_submodule_ref_store()refs.c+20 -250 replies
16/28refs.c: make get_main_ref_store() public and use itrefs.c refs.h refs/files-backend.c+22 -190 replies
17/28path.c: move some code out of strbuf_git_path_submodule()path.c submodule.c submodule.h+44 -280 replies
18/28refs: move submodule code out of files-backend.crefs.c refs/files-backend.c refs/refs-internal.h+20 -320 replies
19/28files-backend: replace submodule_allowed check in files_downcast()refs.c refs/files-backend.c refs/refs-internal.h+71 -344 replies
20/28refs: rename get_ref_store() to get_submodule_ref_store() and make it publicrefs.c refs.h refs/refs-internal.h+19 -160 replies
21/28refs: add new ref-store apirefs.c refs.h refs/files-backend.c +1 more+270 -990 replies
22/28refs: new transaction related ref-store apirefs.c refs.h refs/refs-internal.h+53 -122 replies
23/28files-backend: avoid ref api targetting main ref storerefs/files-backend.c+49 -351 reply
24/28refs: delete pack_refs() in favor of refs_pack_refs()builtin/pack-refs.c refs.c refs.h+1 -70 replies
25/28t/helper: add test-ref-store to test ref-store functionsMakefile t/helper/.gitignore t/helper/test-ref-store.c+279 -00 replies
26/28t1405: some basic tests on main ref storet/t1405-main-ref-store.sh+123 -00 replies
27/28t1406: new tests for submodule ref storet/t1406-submodule-ref-store.sh+95 -00 replies
28/28refs.h: add a note about sorting order of for_each_ref_*refs.h t/t1405-main-ref-store.sh t/t1406-submodule-ref-store.sh+14 -20 replies

Reviews trailers per patch

None of the 28 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchMichael Haggerty
SeriesR-b
1/28
2/28
3/28
4/28
5/28
6/28
7/28
8/28
9/28
10/28
11/28
12/28
13/28
14/28
15/28
16/28
17/28
18/28
19/28
20/28
21/28
22/28
23/28
24/28
25/28
26/28
27/28
28/28

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v7 thread

Cover letter [PATCH v7 00/28] Remove submodule from files-backend.c

v7 is mostly about style changes except the one bug in test-ref-store.c, missing setup_git_directory().

There's one new patch, 03/28, which maps to the "if (!refs)" deletion in the interdiff.

The one comment from v6 I haven't addressed in v7 is whether to delete REF_STORE_READ. But if it is deleted, I think I'm doing it in nd/worktree-kill-parse-ref, which is partly about cleanup refs code anyway, to avoid another re-roll in this series.

refs.c +6 -9
index 77a39f8b17..ec1f563824 100644
@@ -1523,18 +1523,15 @@ static struct ref_store *ref_store_init(const char *gitdir,
 
 struct ref_store *get_main_ref_store(void)
 {
-	struct ref_store *refs;
-
 	if (main_ref_store)
 		return main_ref_store;
 
-	refs = ref_store_init(get_git_dir(),
-			      (REF_STORE_READ |
-			       REF_STORE_WRITE |
-			       REF_STORE_ODB |
-			       REF_STORE_MAIN));
-	main_ref_store = refs;
-	return refs;
+	main_ref_store = ref_store_init(get_git_dir(),
+					(REF_STORE_READ |
+					 REF_STORE_WRITE |
+					 REF_STORE_ODB |
+					 REF_STORE_MAIN));
+	return main_ref_store;
 }
 
 /*
refs/files-backend.c +16 -18
index 4242486118..a5b405436f 100644
@@ -1195,9 +1195,9 @@ static void files_reflog_path(struct files_ref_store *refs,
 	}
 }
 
-static void files_refname_path(struct files_ref_store *refs,
-			       struct strbuf *sb,
-			       const char *refname)
+static void files_ref_path(struct files_ref_store *refs,
+			   struct strbuf *sb,
+			   const char *refname)
 {
 	switch (ref_type(refname)) {
 	case REF_TYPE_PER_WORKTREE:
@@ -1283,7 +1283,7 @@ static void read_loose_refs(const char *dirname, struct ref_dir *dir)
 	struct strbuf path = STRBUF_INIT;
 	size_t path_baselen;
 
-	files_refname_path(refs, &path, dirname);
+	files_ref_path(refs, &path, dirname);
 	path_baselen = path.len;
 
 	d = opendir(path.buf);
@@ -1420,7 +1420,7 @@ static int files_read_raw_ref(struct ref_store *ref_store,
 	*type = 0;
 	strbuf_reset(&sb_path);
 
-	files_refname_path(refs, &sb_path, refname);
+	files_ref_path(refs, &sb_path, refname);
 
 	path = sb_path.buf;
 
@@ -1608,7 +1608,7 @@ static int lock_raw_ref(struct files_ref_store *refs,
 	*lock_p = lock = xcalloc(1, sizeof(*lock));
 
 	lock->ref_name = xstrdup(refname);
-	files_refname_path(refs, &ref_file, refname);
+	files_ref_path(refs, &ref_file, refname);
 
 retry:
 	switch (safe_create_leading_directories(ref_file.buf)) {
@@ -1949,8 +1949,6 @@ static struct ref_iterator *files_ref_iterator_begin(
 	refs = files_downcast(ref_store,
 			      REF_STORE_READ | (ref_paranoia ? 0 : REF_STORE_ODB),
 			      "ref_iterator_begin");
-	if (!refs)
-		return empty_ref_iterator_begin();
 
 	iter = xcalloc(1, sizeof(*iter));
 	ref_iterator = &iter->base;
@@ -2086,7 +2084,7 @@ static struct ref_lock *lock_ref_sha1_basic(struct files_ref_store *refs,
 	if (flags & REF_DELETING)
 		resolve_flags |= RESOLVE_REF_ALLOW_BAD_NAME;
 
-	files_refname_path(refs, &ref_file, refname);
+	files_ref_path(refs, &ref_file, refname);
 	resolved = !!refs_resolve_ref_unsafe(&refs->base,
 					     refname, resolve_flags,
 					     lock->old_oid.hash, type);
@@ -2387,7 +2385,7 @@ static void try_remove_empty_parents(struct files_ref_store *refs,
 		strbuf_setlen(&buf, q - buf.buf);
 
 		strbuf_reset(&sb);
-		files_refname_path(refs, &sb, buf.buf);
+		files_ref_path(refs, &sb, buf.buf);
 		if ((flags & REMOVE_EMPTY_PARENTS_REF) && rmdir(sb.buf))
 			flags &= ~REMOVE_EMPTY_PARENTS_REF;
 
@@ -2709,7 +2707,7 @@ static int files_rename_ref(struct ref_store *ref_store,
 			struct strbuf path = STRBUF_INIT;
 			int result;
 
-			files_refname_path(refs, &path, newrefname);
+			files_ref_path(refs, &path, newrefname);
 			result = remove_empty_directories(&path);
 			strbuf_release(&path);
 
@@ -2935,10 +2933,10 @@ static int log_ref_write_fd(int fd, const unsigned char *old_sha1,
 	return 0;
 }
 
-int files_log_ref_write(struct files_ref_store *refs,
-			const char *refname, const unsigned char *old_sha1,
-			const unsigned char *new_sha1, const char *msg,
-			int flags, struct strbuf *err)
+static int files_log_ref_write(struct files_ref_store *refs,
+			       const char *refname, const unsigned char *old_sha1,
+			       const unsigned char *new_sha1, const char *msg,
+			       int flags, struct strbuf *err)
 {
 	int logfd, result;
 
@@ -3957,7 +3955,7 @@ static int files_transaction_commit(struct ref_store *ref_store,
 			    update->type & REF_ISSYMREF) {
 				/* It is a loose reference. */
 				strbuf_reset(&sb);
-				files_refname_path(refs, &sb, lock->ref_name);
+				files_ref_path(refs, &sb, lock->ref_name);
 				if (unlink_or_msg(sb.buf, err)) {
 					ret = TRANSACTION_GENERIC_ERROR;
 					goto cleanup;
@@ -4266,11 +4264,11 @@ static int files_init_db(struct ref_store *ref_store, struct strbuf *err)
 	/*
 	 * Create .git/refs/{heads,tags}
 	 */
-	files_refname_path(refs, &sb, "refs/heads");
+	files_ref_path(refs, &sb, "refs/heads");
 	safe_create_dir(sb.buf, 1);
 
 	strbuf_reset(&sb);
-	files_refname_path(refs, &sb, "refs/tags");
+	files_ref_path(refs, &sb, "refs/tags");
 	safe_create_dir(sb.buf, 1);
 
 	strbuf_release(&sb);
submodule.c +0 -5
index 3c445f274e..a31f68812c 100644
@@ -1597,11 +1597,6 @@ const char *get_superproject_working_tree(void)
 	return ret;
 }
 
-/*
- * Given a submodule path (as in the index), return the repository
- * path of that submodule in 'buf'. Return -1 on error or when the
- * submodule is not initialized.
- */
 int submodule_to_gitdir(struct strbuf *buf, const char *submodule)
 {
 	const struct submodule *sub;
submodule.h +5 -0
index bddbba7f32..fce2fb64d2 100644
@@ -81,6 +81,11 @@ extern int push_unpushed_submodules(struct sha1_array *commits,
 				    int dry_run);
 extern void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir);
 extern int parallel_submodules(void);
+/*
+ * Given a submodule path (as in the index), return the repository
+ * path of that submodule in 'buf'. Return -1 on error or when the
+ * submodule is not initialized.
+ */
 int submodule_to_gitdir(struct strbuf *buf, const char *submodule);
 
 /*
t/helper/test-ref-store.c +2 -0
index 57849ee59a..2d84c45ffe 100644
@@ -261,6 +261,8 @@ int cmd_main(int argc, const char **argv)
 	const char *func;
 	struct command *cmd;
 
+	setup_git_directory();
+
 	argv = get_store(argv + 1, &refs);
 
 	func = *argv++;
Signature · 1 line
2.11.0.157.gd943d85