Skip to content

Commit 79559f2

Browse files
girvinggitster
authored andcommitted
git fast-export: add --no-data option
When using git fast-export and git fast-import to rewrite the history of a repository with large binary files, almost all of the time is spent dealing with blobs. This is extremely inefficient if all we want to do is rewrite the commits and tree structure. --no-data skips the output of blobs and writes SHA-1s instead of marks, which provides a massive speedup. Signed-off-by: Geoffrey Irving <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 86b5efb commit 79559f2

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Documentation/git-fast-export.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ marks the same across runs.
8282
allow that. So fake a tagger to be able to fast-import the
8383
output.
8484

85+
--no-data::
86+
Skip output of blob objects and instead refer to blobs via
87+
their original SHA-1 hash. This is useful when rewriting the
88+
directory structure or history of a repository without
89+
touching the contents of individual files. Note that the
90+
resulting stream can only be used by a repository which
91+
already contains the necessary objects.
92+
8593
[git-rev-list-args...]::
8694
A list of arguments, acceptable to 'git-rev-parse' and
8795
'git-rev-list', that specifies the specific objects and references

builtin-fast-export.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ static int progress;
2626
static enum { ABORT, VERBATIM, WARN, STRIP } signed_tag_mode = ABORT;
2727
static enum { ERROR, DROP, REWRITE } tag_of_filtered_mode = ABORT;
2828
static int fake_missing_tagger;
29+
static int no_data;
2930

3031
static int parse_opt_signed_tag_mode(const struct option *opt,
3132
const char *arg, int unset)
@@ -116,6 +117,9 @@ static void handle_object(const unsigned char *sha1)
116117
char *buf;
117118
struct object *object;
118119

120+
if (no_data)
121+
return;
122+
119123
if (is_null_sha1(sha1))
120124
return;
121125

@@ -173,7 +177,7 @@ static void show_filemodify(struct diff_queue_struct *q,
173177
* Links refer to objects in another repositories;
174178
* output the SHA-1 verbatim.
175179
*/
176-
if (S_ISGITLINK(spec->mode))
180+
if (no_data || S_ISGITLINK(spec->mode))
177181
printf("M %06o %s %s\n", spec->mode,
178182
sha1_to_hex(spec->sha1), spec->path);
179183
else {
@@ -580,6 +584,9 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
580584
"Import marks from this file"),
581585
OPT_BOOLEAN(0, "fake-missing-tagger", &fake_missing_tagger,
582586
"Fake a tagger when tags lack one"),
587+
{ OPTION_NEGBIT, 0, "data", &no_data, NULL,
588+
"Skip output of blob data",
589+
PARSE_OPT_NOARG | PARSE_OPT_NEGHELP, NULL, 1 },
583590
OPT_END()
584591
};
585592

0 commit comments

Comments
 (0)