From: Junio C Hamano <gitster@pobox.com>
To: "Shawn O Pearce" <spearce@spearce.org>
Cc: git@vger.kernel.org
Subject: [PATCH] allow bulk import to be packed
Date: Wed, 05 Sep 2007 18:17:19 -0700 [thread overview]
Message-ID: <7vps0wfv8g.fsf@gitster.siamese.dyndns.org> (raw)
This will use fast-import as a backend to dump blobs resulting
from a huge initial import into a packfile.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
builtin-add.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 79 insertions(+), 0 deletions(-)
diff --git a/builtin-add.c b/builtin-add.c
index 105a9f0..f512108 100644
--- a/builtin-add.c
+++ b/builtin-add.c
@@ -12,6 +12,7 @@
#include "diffcore.h"
#include "commit.h"
#include "revision.h"
+#include "run-command.h"
static const char builtin_add_usage[] =
"git-add [-n] [-v] [-f] [--interactive | -i] [-u] [--refresh] [--] <filepattern>...";
@@ -153,6 +154,82 @@ static int git_add_config(const char *var, const char *value)
return git_default_config(var, value);
}
+static void pack_one_blob(FILE *g, size_t size, const char *path)
+{
+ void *buf = NULL;
+ unsigned long nsize;
+ char *nbuf;
+ int re_allocated = 0;
+
+ if (size) {
+ int fd = open(path, O_RDONLY);
+ if (fd < 0)
+ return;
+ buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
+ close(fd);
+ }
+ nbuf = convert_to_git(path, buf, &nsize);
+ if (nbuf) {
+ munmap(buf, size);
+ size = nsize;
+ buf = nbuf;
+ re_allocated = 1;
+ }
+
+ fprintf(g, "blob\ndata %lu\n", size);
+ fwrite(buf, 1, size, g);
+ fputc('\n', g);
+}
+
+#ifndef BULK_ADD_LIMIT
+#define BULK_ADD_LIMIT 200
+#endif
+
+static void pack_bluk_blob(struct dir_struct *dir, int verbose)
+{
+ struct child_process gfi;
+ const char *gfi_argv[] = { "fast-import", NULL };
+ int i, cnt;
+ FILE *g;
+ size_t *addmap;
+
+ if (dir->nr < BULK_ADD_LIMIT)
+ return;
+
+ addmap = xcalloc(dir->nr, sizeof(size_t));
+ for (i = cnt = 0; i < dir->nr; i++) {
+ struct stat st;
+ const char *name = dir->entries[i]->name;
+ if (!lstat(name, &st) && S_ISREG(st.st_mode)) {
+ cnt++;
+ addmap[i] = xsize_t(st.st_size);
+ }
+ }
+ if (cnt < BULK_ADD_LIMIT)
+ return;
+
+ memset(&gfi, 0, sizeof(gfi));
+ gfi.argv = gfi_argv;
+ gfi.no_stdout = 1;
+ gfi.in = -1;
+ gfi.git_cmd = 1;
+
+ if (start_command(&gfi)) {
+ warning("could not run fast-import");
+ return;
+ }
+ g = fdopen(gfi.in, "w");
+
+ for (i = 0; i < dir->nr; i++) {
+ if (!addmap[i])
+ continue;
+ pack_one_blob(g, addmap[i], dir->entries[i]->name);
+ }
+ fflush(g);
+ finish_command(&gfi);
+ reprepare_packed_git();
+}
+
static struct lock_file lock_file;
static const char ignore_error[] =
@@ -258,6 +335,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
die("no files added");
}
+ pack_bluk_blob(&dir, verbose);
+
for (i = 0; i < dir.nr; i++)
add_file_to_cache(dir.entries[i]->name, verbose);
next reply other threads:[~2007-09-06 1:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-06 1:17 Junio C Hamano [this message]
2007-09-06 1:36 ` [PATCH] allow bulk import to be packed Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7vps0wfv8g.fsf@gitster.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=spearce@spearce.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).