[PATCH 6/7] submodule: remove add_submodule_odb

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The remaining callers to get_submodule_ref_store do not require access
to the objects, and do not call add_submodule_odb.  This function can
therefore be removed and the refstore marked as not having access to the
objects.

The submodule ref-store tests have been updated to reflect the fact that
the objects are no longer available in the ref-store.

Signed-off-by: Andrew Oakley <andrew@xxxxxxxxxxxxx>
---
 refs.c                         |  5 +----
 refs.h                         | 37 +++-------------------------------
 submodule.c                    | 19 -----------------
 submodule.h                    |  2 --
 t/helper/test-ref-store.c      |  1 -
 t/t1406-submodule-ref-store.sh | 17 ++--------------
 6 files changed, 6 insertions(+), 75 deletions(-)

diff --git a/refs.c b/refs.c
index ceff6d2af5..0a1960b4fe 100644
--- a/refs.c
+++ b/refs.c
@@ -1832,10 +1832,7 @@ struct ref_store *get_submodule_ref_store(const char *submodule)
 	if (submodule_to_gitdir(&submodule_sb, submodule))
 		goto done;
 
-	/* assume that add_submodule_odb() has been called */
-	refs = ref_store_init(the_repository,
-			      submodule_sb.buf,
-			      REF_STORE_READ | REF_STORE_ODB);
+	refs = ref_store_init(NULL, submodule_sb.buf, REF_STORE_READ);
 	register_ref_store_map(&submodule_ref_stores, "submodule",
 			       refs, submodule);
 
diff --git a/refs.h b/refs.h
index 6695518156..a1b381437b 100644
--- a/refs.h
+++ b/refs.h
@@ -831,40 +831,6 @@ int ref_storage_backend_exists(const char *name);
 
 struct ref_store *get_main_ref_store(struct repository *r);
 
-/**
- * Submodules
- * ----------
- *
- * If you want to iterate the refs of a submodule you first need to add the
- * submodules object database. You can do this by a code-snippet like
- * this:
- *
- * 	const char *path = "path/to/submodule"
- * 	if (add_submodule_odb(path))
- * 		die("Error submodule '%s' not populated.", path);
- *
- * `add_submodule_odb()` will return zero on success. If you
- * do not do this you will get an error for each ref that it does not point
- * to a valid object.
- *
- * Note: As a side-effect of this you cannot safely assume that all
- * objects you lookup are available in superproject. All submodule objects
- * will be available the same way as the superprojects objects.
- *
- * Example:
- * --------
- *
- * ----
- * static int handle_remote_ref(const char *refname,
- * 		const unsigned char *sha1, int flags, void *cb_data)
- * {
- * 	struct strbuf *output = cb_data;
- * 	strbuf_addf(output, "%s\n", refname);
- * 	return 0;
- * }
- *
- */
-
 /*
  * Return the ref_store instance for the specified submodule. For the
  * main repository, use submodule==NULL; such a call cannot fail. For
@@ -874,6 +840,9 @@ struct ref_store *get_main_ref_store(struct repository *r);
  *
  * For backwards compatibility, submodule=="" is treated the same as
  * submodule==NULL.
+ *
+ * The ref_store for a submodule will be read only and have no access to the
+ * object database.  Only raw access to the refs is possible.
  */
 struct ref_store *get_submodule_ref_store(const char *submodule);
 struct ref_store *get_worktree_ref_store(const struct worktree *wt);
diff --git a/submodule.c b/submodule.c
index 1671800340..cf7db6815e 100644
--- a/submodule.c
+++ b/submodule.c
@@ -165,25 +165,6 @@ void stage_updated_gitmodules(struct index_state *istate)
 		die(_("staging updated .gitmodules failed"));
 }
 
-/* TODO: remove this function, use repo_submodule_init instead. */
-int add_submodule_odb(const char *path)
-{
-	struct strbuf objects_directory = STRBUF_INIT;
-	int ret = 0;
-
-	ret = strbuf_git_path_submodule(&objects_directory, path, "objects/");
-	if (ret)
-		goto done;
-	if (!is_directory(objects_directory.buf)) {
-		ret = -1;
-		goto done;
-	}
-	add_to_alternates_memory(objects_directory.buf);
-done:
-	strbuf_release(&objects_directory);
-	return ret;
-}
-
 void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
 					     const char *path)
 {
diff --git a/submodule.h b/submodule.h
index 6a66d3e05f..0260c75e06 100644
--- a/submodule.h
+++ b/submodule.h
@@ -97,8 +97,6 @@ int submodule_uses_gitfile(const char *path);
 #define SUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED (1<<2)
 int bad_to_remove_submodule(const char *path, unsigned flags);
 
-int add_submodule_odb(const char *path);
-
 /*
  * Initialize a repository struct for a submodule based on the provided 'path'.
  *
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 759e69dc54..1ec9f1b764 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -32,7 +32,6 @@ static const char **get_store(const char **argv, struct ref_store **refs)
 		ret = strbuf_git_path_submodule(&sb, gitdir, "objects/");
 		if (ret)
 			die("strbuf_git_path_submodule failed: %d", ret);
-		add_to_alternates_memory(sb.buf);
 		strbuf_release(&sb);
 
 		*refs = get_submodule_ref_store(gitdir);
diff --git a/t/t1406-submodule-ref-store.sh b/t/t1406-submodule-ref-store.sh
index 36b7ef5046..f4fbf26149 100755
--- a/t/t1406-submodule-ref-store.sh
+++ b/t/t1406-submodule-ref-store.sh
@@ -20,10 +20,8 @@ test_expect_success 'pack_refs() not allowed' '
 '
 
 test_expect_success 'peel_ref(new-tag)' '
-	git -C sub rev-parse HEAD >expected &&
 	git -C sub tag -a -m new-tag new-tag HEAD &&
-	$RUN peel-ref refs/tags/new-tag >actual &&
-	test_cmp expected actual
+	test_must_fail $RUN peel-ref refs/tags/new-tag
 '
 
 test_expect_success 'create_symref() not allowed' '
@@ -39,18 +37,7 @@ test_expect_success 'rename_refs() not allowed' '
 '
 
 test_expect_success 'for_each_ref(refs/heads/)' '
-	$RUN for-each-ref refs/heads/ | cut -d" " -f 2- >actual &&
-	cat >expected <<-\EOF &&
-	master 0x0
-	new-master 0x0
-	EOF
-	test_cmp expected actual
-'
-
-test_expect_success 'for_each_ref() is sorted' '
-	$RUN for-each-ref refs/heads/ | cut -d" " -f 2- >actual &&
-	sort actual > expected &&
-	test_cmp expected actual
+	test_must_fail $RUN for-each-ref refs/heads/
 '
 
 test_expect_success 'resolve_ref(master)' '
-- 
2.26.2




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux