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

[PATCH 2/6] Allow more than one keepfile in the transport

From
Tomas Carnecky <tom@dbservice.com>
Date
Oct 3, 2010, 12:21 UTC
Message-ID
<1286108511-55876-2-git-send-email-tom@dbservice.com>
In-Reply-To
<4CA86A12.6080905@dbservice.com>

Git itself creates only one packfile per fetch. But other transports may chose to create more than one (those that use fast-import for example). Use an array to keep track of the pack lockfiles.

Signed-off-by: Tomas Carnecky <tom@dbservice.com>
---
 transport-helper.c |    5 +----
 transport.c        |   27 ++++++++++++++++++++++-----
 transport.h        |   11 ++++++++++-
 3 files changed, 33 insertions(+), 10 deletions(-)
diff --git a/transport-helper.c b/transport-helper.c
index 0fe886e..dcaaa89 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -362,10 +362,7 @@ static int fetch_with_fetch(struct transport *transport,
 
 		if (!prefixcmp(buf.buf, "lock ")) {
 			const char *name = buf.buf + 5;
-			if (transport->pack_lockfile)
-				warning("%s also locked %s", data->name, name);
-			else
-				transport->pack_lockfile = xstrdup(name);
+			transport_keep(transport, name);
 		} else if (!prefixcmp(buf.buf, "map ")) {
 			map_impure_ref(nr_heads, to_fetch, buf.buf + 4);
 		}
diff --git a/transport.c b/transport.c
index 4dba6f8..df2baa7 100644
--- a/transport.c
+++ b/transport.c
@@ -518,6 +518,7 @@ static int fetch_refs_via_pack(struct transport *transport,
 	struct fetch_pack_args args;
 	int i;
 	struct ref *refs_tmp = NULL;
+	char *keepfile = NULL;
 
 	memset(&args, 0, sizeof(args));
 	args.uploadpack = data->options.uploadpack;
@@ -541,7 +542,7 @@ static int fetch_refs_via_pack(struct transport *transport,
 
 	refs = fetch_pack(&args, data->fd, data->conn,
 			  refs_tmp ? refs_tmp : transport->remote_refs,
-			  dest, nr_heads, heads, &transport->pack_lockfile);
+			  dest, nr_heads, heads, &keepfile);
 	close(data->fd[0]);
 	close(data->fd[1]);
 	if (finish_connect(data->conn))
@@ -556,6 +557,10 @@ static int fetch_refs_via_pack(struct transport *transport,
 	free(origh);
 	free(heads);
 	free(dest);
+
+	if (keepfile)
+		transport_keep(transport, keepfile);
+
 	return (refs ? 0 : -1);
 }
 
@@ -1116,11 +1121,15 @@ int transport_fetch_refs(struct transport *transport, struct ref *refs)
 
 void transport_unlock_pack(struct transport *transport)
 {
-	if (transport->pack_lockfile) {
-		unlink_or_warn(transport->pack_lockfile);
-		free(transport->pack_lockfile);
-		transport->pack_lockfile = NULL;
+	int i;
+
+	for (i = 0; i < transport->keep_nr; ++i) {
+		char *keepfile = (char *) transport->keep[i];
+		unlink_or_warn(keepfile);
+		free(keepfile);
 	}
+
+	transport->keep_nr = 0;
 }
 
 int transport_connect(struct transport *transport, const char *name,
@@ -1137,6 +1146,7 @@ int transport_disconnect(struct transport *transport)
 	int ret = 0;
 	if (transport->disconnect)
 		ret = transport->disconnect(transport);
+	free(transport->keep);
 	free(transport);
 	return ret;
 }
@@ -1188,3 +1198,10 @@ char *transport_anonymize_url(const char *url)
 literal_copy:
 	return xstrdup(url);
 }
+
+void transport_keep(struct transport *transport, const char *keepfile)
+{
+	int nr = transport->keep_nr + 1;
+	ALLOC_GROW(transport->keep, nr, transport->keep_alloc);
+	transport->keep[transport->keep_nr++] = keepfile;
+}
diff --git a/transport.h b/transport.h
index c59d973..6320d28 100644
--- a/transport.h
+++ b/transport.h
@@ -78,7 +78,14 @@ struct transport {
 	 * use. disconnect() releases these resources.
 	 **/
 	int (*disconnect)(struct transport *connection);
-	char *pack_lockfile;
+
+	/** The transport can create zero or more pack files which need to be
+	 * kept until we can update the refs. This array holds the names of the
+	 * keep files which we have to delete once the refs are updated.
+	 **/
+	const char **keep;
+	int keep_nr, keep_alloc;
+
 	signed verbose : 3;
 	/**
 	 * Transports should not set this directly, and should use this
@@ -165,4 +172,6 @@ int transport_refs_pushed(struct ref *ref);
 void transport_print_push_status(const char *dest, struct ref *refs,
 		  int verbose, int porcelain, int *nonfastforward);
 
+void transport_keep(struct transport *transport, const char *keepfile);
+
 #endif
-- 
1.7.3.37.gb6088b
Previous: Sverre RabbelierNext: Jonathan Nieder
Message 5 of 21 in “[RFC] New type of remote helpers”
  1. Tomas CarneckyOct 3, 2010
  2. 1/6 Remote helper: accept ':<value> <name>' as a response to 'list'Tomas Carnecky, Oct 3, 2010
  3. Jonathan NiederOct 5, 2010
  4. Sverre RabbelierOct 7, 2010
  5. 2/6 Allow more than one keepfile in the transportTomas Carnecky, Oct 3, 2010
  6. Jonathan NiederOct 5, 2010
  7. 3/6 Allow the transport fetch command to add additional refsTomas Carnecky, Oct 3, 2010
  8. Jonathan NiederOct 5, 2010
  9. 4/6 Rename get_mode() to decode_tree_mode() and export itTomas Carnecky, Oct 3, 2010
  10. Jonathan NiederOct 5, 2010
  11. 5/6 Introduce the git fast-import-helperTomas Carnecky, Oct 3, 2010
  12. Jonathan NiederOct 3, 2010
  13. Tomas CarneckyOct 3, 2010
  14. Sverre RabbelierOct 3, 2010
  15. Tomas CarneckyOct 3, 2010
  16. Sverre RabbelierOct 3, 2010
  17. 6/6 Add git-remote-svnTomas Carnecky, Oct 3, 2010
  18. Jonathan NiederOct 5, 2010
  19. Sverre RabbelierOct 3, 2010
  20. Jonathan NiederOct 3, 2010
  21. Ramkumar RamachandraOct 3, 2010

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.