git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 3/8] Add a library function to add an alternate to the alternates file
@ 2008-04-17 23:32 Daniel Barkalow
  0 siblings, 0 replies; only message in thread
From: Daniel Barkalow @ 2008-04-17 23:32 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Johannes Schindelin

This is in the core so that, if the alternates file has already been
read, the addition can be parsed and put into effect for the current
process.

Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
---
 cache.h     |    1 +
 sha1_file.c |   12 ++++++++++++
 2 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/cache.h b/cache.h
index 4a113b0..96dcb49 100644
--- a/cache.h
+++ b/cache.h
@@ -589,6 +589,7 @@ extern struct alternate_object_database {
 	char base[FLEX_ARRAY]; /* more */
 } *alt_odb_list;
 extern void prepare_alt_odb(void);
+extern void add_to_alternates_file(const char *reference);
 
 struct pack_window {
 	struct pack_window *next;
diff --git a/sha1_file.c b/sha1_file.c
index 445a871..1aa3cef 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -379,6 +379,18 @@ static void read_info_alternates(const char * relative_base, int depth)
 	munmap(map, mapsz);
 }
 
+void add_to_alternates_file(const char *reference)
+{
+	struct lock_file *lock = xcalloc(1, sizeof(struct lock_file));
+	int fd = hold_lock_file_for_append(lock, git_path("objects/info/alternates"), 1);
+	char *alt = mkpath("%s/objects\n", reference);
+	write_or_die(fd, alt, strlen(alt));
+	if (commit_lock_file(lock))
+		die("could not close alternates file");
+	if (alt_odb_tail)
+		link_alt_odb_entries(alt, alt + strlen(alt), '\n', NULL, 0);
+}
+
 void prepare_alt_odb(void)
 {
 	const char *alt;
-- 
1.5.4.3.610.gea6cd

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2008-04-17 23:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-17 23:32 [PATCH 3/8] Add a library function to add an alternate to the alternates file Daniel Barkalow

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).