summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 734cd57)
raw | patch | inline | side by side (parent: 734cd57)
author | Carlos Manuel Duclos Vergara <carlos.duclos@nokia.com> | |
Mon, 16 Feb 2009 17:20:25 +0000 (18:20 +0100) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 4 Mar 2009 08:56:52 +0000 (00:56 -0800) |
When archiving a repository there is no way to specify a file as output.
This patch adds a new option "--output" that redirects the output to a
file instead of stdout.
Signed-off-by: Carlos Manuel Duclos Vergara <carlos.duclos@nokia.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This patch adds a new option "--output" that redirects the output to a
file instead of stdout.
Signed-off-by: Carlos Manuel Duclos Vergara <carlos.duclos@nokia.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-archive.txt | patch | blob | history | |
archive.c | patch | blob | history | |
t/t5000-tar-tree.sh | patch | blob | history |
index 5b3eb12c8a1e8ac50f09745efd091882b248f1bc..0eeefe00603814fcabc7d537d5c04e5801591c56 100644 (file)
--------
[verse]
'git archive' --format=<fmt> [--list] [--prefix=<prefix>/] [<extra>]
+ [--output=<file>]
[--remote=<repo> [--exec=<git-upload-archive>]] <tree-ish>
[path...]
--prefix=<prefix>/::
Prepend <prefix>/ to each filename in the archive.
+--output=<file>::
+ Write the archive to <file> instead of stdout.
+
<extra>::
This can be any options that the archiver backend understand.
See next section.
diff --git a/archive.c b/archive.c
index e6de0397cc82ae97018cbf4fc82d5697ec4d915d..c6aea8358f5b632ee11cb102c1ec1b6c2b317835 100644 (file)
--- a/archive.c
+++ b/archive.c
ar_args->time = archive_time;
}
+static void create_output_file(const char *output_file)
+{
+ int output_fd = open(output_file, O_CREAT | O_WRONLY | O_TRUNC, 0666);
+ if (output_fd < 0)
+ die("could not create archive file: %s ", output_file);
+ if (output_fd != 1) {
+ if (dup2(output_fd, 1) < 0)
+ die("could not redirect output");
+ else
+ close(output_fd);
+ }
+}
+
#define OPT__COMPR(s, v, h, p) \
{ OPTION_SET_INT, (s), NULL, (v), NULL, (h), \
PARSE_OPT_NOARG | PARSE_OPT_NONEG, NULL, (p) }
const char *base = NULL;
const char *remote = NULL;
const char *exec = NULL;
+ const char *output = NULL;
int compression_level = -1;
int verbose = 0;
int i;
OPT_STRING(0, "format", &format, "fmt", "archive format"),
OPT_STRING(0, "prefix", &base, "prefix",
"prepend prefix to each pathname in the archive"),
+ OPT_STRING(0, "output", &output, "file",
+ "write the archive to this file"),
OPT__VERBOSE(&verbose),
OPT__COMPR('0', &compression_level, "store only", 0),
OPT__COMPR('1', &compression_level, "compress faster", 1),
if (!base)
base = "";
+ if (output)
+ create_output_file(output);
+
if (list) {
for (i = 0; i < ARRAY_SIZE(archivers); i++)
printf("%s\n", archivers[i].name);
diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh
index c942c8be85339157e22f755d8fc94e64efaee4dd..b7e362834bd743b61c27a4fd2118a83b14828489 100755 (executable)
--- a/t/t5000-tar-tree.sh
+++ b/t/t5000-tar-tree.sh
'git archive vs. the same in a bare repo' \
'test_cmp b.tar b3.tar'
+test_expect_success 'git archive with --output' \
+ 'git archive --output=b4.tar HEAD &&
+ test_cmp b.tar b4.tar'
+
test_expect_success \
'validate file modification time' \
'mkdir extract &&
'git archive --format=zip vs. the same in a bare repo' \
'test_cmp d.zip d1.zip'
+test_expect_success 'git archive --format=zip with --output' \
+ 'git archive --format=zip --output=d2.zip HEAD &&
+ test_cmp d.zip d2.zip'
+
$UNZIP -v >/dev/null 2>&1
if [ $? -eq 127 ]; then
echo "Skipping ZIP tests, because unzip was not found"