summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7b95089)
raw | patch | inline | side by side (parent: 7b95089)
author | René Scharfe <rene.scharfe@lsrfire.ath.cx> | |
Mon, 3 Sep 2007 18:07:01 +0000 (20:07 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Mon, 3 Sep 2007 23:46:16 +0000 (16:46 -0700) |
Add support for a new attribute, specfile. Files marked as being
specfiles are expanded by git-archive when they are written to an
archive. It has no effect on worktree files. The same placeholders
as those for the option --pretty=format: of git-log et al. can be
used.
The attribute is useful for creating auto-updating specfiles. It is
limited by the underlying function format_commit_message(), though.
E.g. currently there is no placeholder for git-describe like output,
and expanded specfiles can't contain NUL bytes. That can be fixed
in format_commit_message() later and will then benefit users of
git-log, too.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
specfiles are expanded by git-archive when they are written to an
archive. It has no effect on worktree files. The same placeholders
as those for the option --pretty=format: of git-log et al. can be
used.
The attribute is useful for creating auto-updating specfiles. It is
limited by the underlying function format_commit_message(), though.
E.g. currently there is no placeholder for git-describe like output,
and expanded specfiles can't contain NUL bytes. That can be fixed
in format_commit_message() later and will then benefit users of
git-log, too.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
index 46f9d591aa7a3af2235d29308d101b2bfa0bff56..47a621b7333bd171225ca78482c6da52c577777b 100644 (file)
----------------------------------------------------------------
+Creating an archive
+~~~~~~~~~~~~~~~~~~~
+
+`specfile`
+^^^^^^^^^^
+
+If the attribute `specfile` is set for a file then git will expand
+several placeholders when adding this file to an archive. The
+expansion depends on the availability of a commit ID, i.e. if
+gitlink:git-archive[1] has been given a tree instead of a commit or a
+tag then no replacement will be done. The placeholders are the same
+as those for the option `--pretty=format:` of gitlink:git-log[1].
+
+
GIT
---
Part of the gitlink:git[7] suite
diff --git a/archive-tar.c b/archive-tar.c
index 66fe3e375b545613faba4e051dc41c1acb5d8cee..c0d95dab0d965ff0ae961d72d7eae4c021c5c05a 100644 (file)
--- a/archive-tar.c
+++ b/archive-tar.c
static time_t archive_time;
static int tar_umask = 002;
static int verbose;
+static const struct commit *commit;
/* writes out the whole block, but only if it is full */
static void write_if_needed(void)
buffer = NULL;
size = 0;
} else {
- buffer = convert_sha1_file(path.buf, sha1, mode, &type, &size);
+ buffer = sha1_file_to_archive(path.buf, sha1, mode, &type,
+ &size, commit);
if (!buffer)
die("cannot read %s", sha1_to_hex(sha1));
}
archive_time = args->time;
verbose = args->verbose;
+ commit = args->commit;
if (args->commit_sha1)
write_global_extended_header(args->commit_sha1);
diff --git a/archive-zip.c b/archive-zip.c
index 444e1623db66fe4f5d8983e1e9e2cf4083b005b4..f63dff383483c482b414432b697306c53b320d00 100644 (file)
--- a/archive-zip.c
+++ b/archive-zip.c
static int verbose;
static int zip_date;
static int zip_time;
+static const struct commit *commit;
static unsigned char *zip_dir;
static unsigned int zip_dir_size;
if (S_ISREG(mode) && zlib_compression_level != 0)
method = 8;
result = 0;
- buffer = convert_sha1_file(path, sha1, mode, &type, &size);
+ buffer = sha1_file_to_archive(path, sha1, mode, &type, &size,
+ commit);
if (!buffer)
die("cannot read %s", sha1_to_hex(sha1));
crc = crc32(crc, buffer, size);
zip_dir = xmalloc(ZIP_DIRECTORY_MIN_SIZE);
zip_dir_size = ZIP_DIRECTORY_MIN_SIZE;
verbose = args->verbose;
+ commit = args->commit;
if (args->base && plen > 0 && args->base[plen - 1] == '/') {
char *base = xstrdup(args->base);
diff --git a/archive.h b/archive.h
index 6838dc788f7620b0807a7044b611efc623bdcf0c..5791e657e9a0c22081f4f42b9d8ca5b3c536baf2 100644 (file)
--- a/archive.h
+++ b/archive.h
const char *base;
struct tree *tree;
const unsigned char *commit_sha1;
+ const struct commit *commit;
time_t time;
const char **pathspec;
unsigned int verbose : 1;
extern int write_zip_archive(struct archiver_args *);
extern void *parse_extra_zip_args(int argc, const char **argv);
+extern void *sha1_file_to_archive(const char *path, const unsigned char *sha1, unsigned int mode, enum object_type *type, unsigned long *size, const struct commit *commit);
+
#endif /* ARCHIVE_H */
diff --git a/builtin-archive.c b/builtin-archive.c
index 187491bc172571b783a0be4f4dfa3d94d58bb0fe..faccce302a5ca3104aa89020c89694e682ef0ba6 100644 (file)
--- a/builtin-archive.c
+++ b/builtin-archive.c
#include "exec_cmd.h"
#include "pkt-line.h"
#include "sideband.h"
+#include "attr.h"
static const char archive_usage[] = \
"git-archive --format=<fmt> [--prefix=<prefix>/] [--verbose] [<extra>] <tree-ish> [path...]";
return !!rv;
}
+static void *convert_to_archive(const char *path,
+ const void *src, unsigned long *sizep,
+ const struct commit *commit)
+{
+ static struct git_attr *attr_specfile;
+ struct git_attr_check check[1];
+ char *interpolated = NULL;
+ unsigned long allocated = 0;
+
+ if (!commit)
+ return NULL;
+
+ if (!attr_specfile)
+ attr_specfile = git_attr("specfile", 8);
+
+ check[0].attr = attr_specfile;
+ if (git_checkattr(path, ARRAY_SIZE(check), check))
+ return NULL;
+ if (!ATTR_TRUE(check[0].value))
+ return NULL;
+
+ *sizep = format_commit_message(commit, src, &interpolated, &allocated);
+
+ return interpolated;
+}
+
+void *sha1_file_to_archive(const char *path, const unsigned char *sha1,
+ unsigned int mode, enum object_type *type,
+ unsigned long *size,
+ const struct commit *commit)
+{
+ void *buffer, *converted;
+
+ buffer = read_sha1_file(sha1, type, size);
+ if (buffer && S_ISREG(mode)) {
+ converted = convert_to_working_tree(path, buffer, size);
+ if (converted) {
+ free(buffer);
+ buffer = converted;
+ }
+
+ converted = convert_to_archive(path, buffer, size, commit);
+ if (converted) {
+ free(buffer);
+ buffer = converted;
+ }
+ }
+
+ return buffer;
+}
+
static int init_archiver(const char *name, struct archiver *ar)
{
int rv = -1, i;
const unsigned char *commit_sha1;
time_t archive_time;
struct tree *tree;
- struct commit *commit;
+ const struct commit *commit;
unsigned char sha1[20];
if (get_sha1(name, sha1))
}
ar_args->tree = tree;
ar_args->commit_sha1 = commit_sha1;
+ ar_args->commit = commit;
ar_args->time = archive_time;
}
diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh
index 1a4c53a031608a16785e6ac9a0531696156bacba..3d5d01be784fdee620fe732d3da4a8b1eea3f846 100755 (executable)
--- a/t/t5000-tar-tree.sh
+++ b/t/t5000-tar-tree.sh
TAR=${TAR:-tar}
UNZIP=${UNZIP:-unzip}
+SPECFILEFORMAT=%H%n
+
test_expect_success \
'populate workdir' \
'mkdir a b c &&
echo simple textfile >a/a &&
mkdir a/bin &&
cp /bin/sh a/bin &&
+ printf "%s" "$SPECFILEFORMAT" >a/specfile &&
ln -s a a/l1 &&
(p=long_path_to_a_file && cd a &&
for depth in 1 2 3 4 5; do mkdir $p && cd $p; done &&
'validate file contents with prefix' \
'diff -r a c/prefix/a'
+test_expect_success \
+ 'create an archive with a specfile' \
+ 'echo specfile specfile >a/.gitattributes &&
+ git archive HEAD >f.tar &&
+ rm a/.gitattributes'
+
+test_expect_success \
+ 'extract specfile' \
+ '(mkdir f && cd f && $TAR xf -) <f.tar'
+
+test_expect_success \
+ 'validate specfile contents' \
+ 'git log --max-count=1 "--pretty=format:$SPECFILEFORMAT" HEAD \
+ >f/a/specfile.expected &&
+ diff f/a/specfile.expected f/a/specfile'
+
test_expect_success \
'git archive --format=zip' \
'git archive --format=zip HEAD >d.zip'