git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/4] submodule.c: get superprojects gitlink value

From
Stefan Beller <sbeller@google.com>
Date
Nov 8, 2017, 19:55 UTC
Message-ID
<20171108195509.7839-4-sbeller@google.com>
In-Reply-To
<20171108195509.7839-1-sbeller@google.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
---
 submodule.c | 27 +++++++++++++++++++++++++++
 submodule.h |  6 ++++++
 2 files changed, 33 insertions(+)
diff --git a/submodule.c b/submodule.c
index 4fcb64469e..68b123eb13 100644
--- a/submodule.c
+++ b/submodule.c
@@ -2074,6 +2074,33 @@ const char *get_superproject_working_tree(void)
 	return ret;
 }
 
+/*
+ * Returns 0 when the gitlink is found in the superprojects index,
+ * the value will be found in `oid`. Otherwise return -1.
+ */
+int get_superproject_gitlink(struct object_id *oid)
+{
+	struct child_process cp = CHILD_PROCESS_INIT;
+	struct strbuf sb = STRBUF_INIT;
+	const char *hash;
+
+	if (start_ls_files_dot_dot(&cp, &sb) < 0)
+		return -1;
+
+	if (!skip_prefix(sb.buf, "160000 ", &hash))
+		/*
+		 * superproject doesn't have a gitlink at submodule position or
+		 * output is gibberish
+		 */
+		return -1;
+
+	if (get_oid_hex(hash, oid))
+		/* could not parse the object name */
+		return -1;
+
+	return 0;
+}
+
 /*
  * Put the gitdir for a submodule (given relative to the main
  * repository worktree) into `buf`, or return -1 on error.
diff --git a/submodule.h b/submodule.h
index f0da0277a4..5fc602f0c7 100644
--- a/submodule.h
+++ b/submodule.h
@@ -137,4 +137,10 @@ extern void absorb_git_dir_into_superproject(const char *prefix,
  */
 extern const char *get_superproject_working_tree(void);
 
+/*
+ * Returns 0 when the gitlink is found in the superprojects index,
+ * the value will be found in `oid`. Otherwise return -1.
+ */
+extern int get_superproject_gitlink(struct object_id *oid);
+
 #endif
-- 
2.15.0.128.g40905b34bf.dirty
Previous: Stefan BellerNext: Stefan Beller
Message 3 of 16 in “git-status reports relation to superproject”
  1. 0/4 git-status reports relation to superprojectStefan Beller, Nov 8, 2017
  2. 1/4 remote, revision: factor out exclusive counting between two commitsStefan Beller, Nov 8, 2017
  3. 3/4 submodule.c: get superprojects gitlink valueStefan Beller, Nov 8, 2017
  4. 4/4 git-status: report reference to superprojectStefan Beller, Nov 8, 2017
  5. 2/4 submodule.c: factor start_ls_files_dot_dot out of get_superproject_working_treeStefan Beller, Nov 8, 2017
  6. Jonathan TanNov 8, 2017
  7. [RFD] Long term plan with submodule refs?Stefan Beller, Nov 9, 2017
  8. Jonathan TanNov 9, 2017
  9. Junio C HamanoNov 9, 2017
  10. Junio C HamanoNov 9, 2017
  11. Stefan BellerNov 9, 2017
  12. Jacob KellerNov 9, 2017
  13. Stefan BellerNov 9, 2017
  14. Jacob KellerNov 10, 2017
  15. Stefan BellerNov 10, 2017
  16. Jacob KellerNov 11, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.