git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Patches for libgit2
@ 2009-10-03 18:09 Hervé Cauwelier
  2009-10-03 18:09 ` [PATCH 1/6] Open the pack file and keep a map on it Hervé Cauwelier
  0 siblings, 1 reply; 12+ messages in thread
From: Hervé Cauwelier @ 2009-10-03 18:09 UTC (permalink / raw)
  To: git


Hi,

Please find patches for libgit2. They allowed me to read the history of a
repository with only 75 patches but hacked by an history shortening.

Commits were both in a 5 GB pack file and loose objects. So I had to add
support for pack files. Hopefully, reading idx files was already there so I
followed the same model.

Patches can also be cloned at "git://git.hforge.org/libgit2.git".

There is a Python wrapper on the next side, forking from the existing
libgit2-python [1]. They bring the same functionnalities but the patches are
not slick yet.

[1] http://code.istique.net/gitweb/?p=libgit2-python.git;a=summary

One thing that would miss is unit tests, but I lack experience on testing C
code, and it would require having a small but exhaustive pack file with
different types of object, including ofs and ref deltas. Help on this part is
welcome.

Next step would be decoding raw objects to commits, trees, blobs and tags.
There is already the start of a commit structure. I'll be starting from that.

Regards,

Hervé

^ permalink raw reply	[flat|nested] 12+ messages in thread
* [PATCH 1/6] Open the pack file and keep a map on it.
@ 2009-10-14 10:37 Hervé Cauwelier
  2009-10-14 12:48 ` Sverre Rabbelier
  0 siblings, 1 reply; 12+ messages in thread
From: Hervé Cauwelier @ 2009-10-14 10:37 UTC (permalink / raw)
  To: git

On the same model than the idx file.

Signed-off-by: Hervé Cauwelier <herve@itaapy.com>
---
 src/odb.c |   65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/odb.h |    1 +
 2 files changed, 65 insertions(+), 1 deletions(-)

diff --git a/src/odb.c b/src/odb.c
index 6d646a4..2319998 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -64,6 +64,10 @@ struct git_pack {
 
 	/** Name of the pack file(s), without extension ("pack-abc"). */
 	char pack_name[GIT_PACK_NAME_MAX];
+
+	/** The .pack file, mapped into memory. */
+	git_file pack_fd;
+	git_map pack_map;
 };
 typedef struct git_pack git_pack;
 
@@ -809,6 +813,59 @@ unlock_fail:
 	return GIT_ERROR;
 }
 
+static int pack_openpack_map(git_pack *p)
+{
+	char pb[GIT_PATH_MAX];
+	off_t len;
+
+	if (git__fmt(pb, sizeof(pb), "%s/pack/%s.pack",
+			p->db->objects_dir,
+			p->pack_name) < 0)
+		return GIT_ERROR;
+
+	if ((p->pack_fd = gitfo_open(pb, O_RDONLY)) < 0)
+		return GIT_ERROR;
+
+	if ((len = gitfo_size(p->pack_fd)) < 0
+			|| !git__is_sizet(len)
+			|| gitfo_map_ro(&p->pack_map, p->pack_fd, 0, (size_t)len)) {
+		gitfo_close(p->pack_fd);
+		return GIT_ERROR;
+	}
+
+	return GIT_SUCCESS;
+}
+
+static int pack_openpack(git_pack *p)
+{
+	gitlck_lock(&p->lock);
+	if (p->invalid)
+		goto unlock_fail;
+	if (p->pack_fd < 0) {
+		uint32_t *data;
+
+		if (pack_openpack_map(p))
+			goto invalid_fail;
+		data = p->pack_map.data;
+
+		if (decode32(&data[0]) != PACK_HDR)
+			goto unmap_fail;
+	}
+	gitlck_unlock(&p->lock);
+	return GIT_SUCCESS;
+
+unmap_fail:
+	gitfo_free_map(&p->pack_map);
+
+invalid_fail:
+	p->invalid = 1;
+	p->pack_fd = -1;
+
+unlock_fail:
+	gitlck_unlock(&p->lock);
+	return GIT_ERROR;
+}
+
 static void pack_decidx(git_pack *p)
 {
 	gitlck_lock(&p->lock);
@@ -830,6 +887,11 @@ static void pack_dec(git_pack *p)
 			gitfo_close(p->idx_fd);
 			free(p->im_fanout);
 		}
+		if (p->pack_fd >= 0) {
+			gitfo_free_map(&p->pack_map);
+			gitfo_close(p->pack_fd);
+			p->pack_fd = -1;
+		}
 
 		gitlck_free(&p->lock);
 		free(p);
@@ -861,6 +923,7 @@ static git_pack *alloc_pack(const char *pack_name)
 	gitlck_init(&p->lock);
 	strcpy(p->pack_name, pack_name);
 	p->refcnt = 1;
+	p->pack_fd = -1;
 	return p;
 }
 
@@ -895,7 +958,7 @@ static int scan_one_pack(void *state, char *name)
 
 	r->next = *ret;
 	*ret = r;
-	return 0;
+	return GIT_SUCCESS;
 }
 
 static git_packlist* scan_packs(git_odb *db)
diff --git a/src/odb.h b/src/odb.h
index 2f205b2..121583f 100644
--- a/src/odb.h
+++ b/src/odb.h
@@ -15,5 +15,6 @@
  * cannot be true for an idx v1 file.
  */
 #define PACK_TOC 0xff744f63 /* -1tOc */
+#define PACK_HDR 0x5041434b /* PACK */
 
 #endif
-- 
1.6.5

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2009-10-14 15:43 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-03 18:09 Patches for libgit2 Hervé Cauwelier
2009-10-03 18:09 ` [PATCH 1/6] Open the pack file and keep a map on it Hervé Cauwelier
2009-10-03 18:09   ` [PATCH 2/6] Read the base offset or name of delta objects Hervé Cauwelier
2009-10-03 18:09     ` [PATCH 3/6] Allow zlib to read a pack buffer longer than the actual data Hervé Cauwelier
2009-10-03 18:09       ` [PATCH 4/6] Inflate an object from a pack file Hervé Cauwelier
2009-10-03 18:10         ` [PATCH 5/6] This assertion is valid for both loose and packed objects Hervé Cauwelier
2009-10-03 18:10           ` [PATCH 6/6] Read an object from a pack file Hervé Cauwelier
2009-10-05 15:27   ` [PATCH 1/6] Open the pack file and keep a map on it Shawn O. Pearce
  -- strict thread matches above, loose matches on Subject: below --
2009-10-14 10:37 Hervé Cauwelier
2009-10-14 12:48 ` Sverre Rabbelier
2009-10-14 15:29   ` Hervé Cauwelier
2009-10-14 15:30     ` Sverre Rabbelier

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 NNTP newsgroup(s).