From: "René Scharfe" <rene.scharfe@lsrfire.ath.cx>
To: Junio C Hamano <gitster@pobox.com>
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>,
Andreas Ericsson <ae@op5.se>,
Git Mailing List <git@vger.kernel.org>,
Michael Gernoth <simigern@cip.informatik.uni-erlangen.de>,
Thomas Glanzmann <thomas@glanzmann.de>
Subject: [PATCH 4/3] archive: specfile syntax change: "$Format:%PLCHLDR$" instead of just "%PLCHLDR"
Date: Thu, 06 Sep 2007 18:20:09 +0200 [thread overview]
Message-ID: <46E028B9.2090908@lsrfire.ath.cx> (raw)
In-Reply-To: <7vzm02klip.fsf@gitster.siamese.dyndns.org>
As suggested by Johannes, --pretty=format: placeholders in specfiles
need to be wrapped in $Format:...$ now. This syntax change restricts
the expansion of placeholders and makes it easier to use with files
that contain non-placeholder percent signs.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
---
Documentation/gitattributes.txt | 5 +++-
builtin-archive.c | 52 +++++++++++++++++++++++++++++++++++---
t/t5000-tar-tree.sh | 4 +-
3 files changed, 53 insertions(+), 8 deletions(-)
diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index 47a621b..37b3be8 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -432,7 +432,10 @@ 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].
+as those for the option `--pretty=format:` of gitlink:git-log[1],
+except that they need to be wrapped like this: `$Format:PLACEHOLDERS$`
+in the file. E.g. the string `$Format:%H$` will be replaced by the
+commit hash.
GIT
diff --git a/builtin-archive.c b/builtin-archive.c
index faccce3..a8a0f01 100644
--- a/builtin-archive.c
+++ b/builtin-archive.c
@@ -81,14 +81,58 @@ static int run_remote_archiver(const char *remote, int argc,
return !!rv;
}
+static void *format_specfile(const struct commit *commit, const char *format,
+ unsigned long *sizep)
+{
+ unsigned long len = *sizep, result_len = 0;
+ const char *a = format;
+ char *result = NULL;
+
+ for (;;) {
+ const char *b, *c;
+ char *fmt, *formatted = NULL;
+ unsigned long a_len, fmt_len, formatted_len, allocated = 0;
+
+ b = memchr(a, '$', len);
+ if (!b || a + len < b + 9 || memcmp(b + 1, "Format:", 7))
+ break;
+ c = memchr(b + 8, '$', len - 8);
+ if (!c)
+ break;
+
+ a_len = b - a;
+ fmt_len = c - b - 8;
+ fmt = xmalloc(fmt_len + 1);
+ memcpy(fmt, b + 8, fmt_len);
+ fmt[fmt_len] = '\0';
+
+ formatted_len = format_commit_message(commit, fmt, &formatted,
+ &allocated);
+ result = xrealloc(result, result_len + a_len + formatted_len);
+ memcpy(result + result_len, a, a_len);
+ memcpy(result + result_len + a_len, formatted, formatted_len);
+ result_len += a_len + formatted_len;
+ len -= c + 1 - a;
+ a = c + 1;
+ }
+
+ if (result && len) {
+ result = xrealloc(result, result_len + len);
+ memcpy(result + result_len, a, len);
+ result_len += len;
+ }
+
+ *sizep = result_len;
+
+ return result;
+}
+
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;
@@ -102,9 +146,7 @@ static void *convert_to_archive(const char *path,
if (!ATTR_TRUE(check[0].value))
return NULL;
- *sizep = format_commit_message(commit, src, &interpolated, &allocated);
-
- return interpolated;
+ return format_specfile(commit, src, sizep);
}
void *sha1_file_to_archive(const char *path, const unsigned char *sha1,
diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh
index 3d5d01b..6e89e07 100755
--- a/t/t5000-tar-tree.sh
+++ b/t/t5000-tar-tree.sh
@@ -36,7 +36,7 @@ test_expect_success \
echo simple textfile >a/a &&
mkdir a/bin &&
cp /bin/sh a/bin &&
- printf "%s" "$SPECFILEFORMAT" >a/specfile &&
+ printf "A\$Format:%s\$O" "$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 &&
@@ -119,7 +119,7 @@ test_expect_success \
test_expect_success \
'validate specfile contents' \
- 'git log --max-count=1 "--pretty=format:$SPECFILEFORMAT" HEAD \
+ 'git log --max-count=1 "--pretty=format:A${SPECFILEFORMAT}O" HEAD \
>f/a/specfile.expected &&
diff f/a/specfile.expected f/a/specfile'
--
1.5.3
next prev parent reply other threads:[~2007-09-06 16:20 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-03 18:07 [PATCH 2/3] archive: specfile support (--pretty=format: in archive files) René Scharfe
2007-09-03 18:40 ` Johannes Schindelin
2007-09-03 20:19 ` David Kastrup
2007-09-04 23:13 ` René Scharfe
2007-09-03 23:53 ` Junio C Hamano
2007-09-04 5:45 ` Andreas Ericsson
2007-09-04 10:41 ` Johannes Schindelin
2007-09-04 23:13 ` René Scharfe
2007-09-05 0:12 ` Johannes Schindelin
2007-09-05 0:23 ` Junio C Hamano
2007-09-06 16:20 ` René Scharfe [this message]
2007-09-06 17:11 ` [PATCH 4/3] archive: specfile syntax change: "$Format:%PLCHLDR$" instead of just "%PLCHLDR" Johannes Schindelin
2007-09-06 20:35 ` René Scharfe
2007-09-06 20:53 ` René Scharfe
2007-09-06 23:17 ` Junio C Hamano
2007-09-07 10:44 ` Johannes Schindelin
2007-09-06 22:32 ` [PATCH 3.5/3] add memmem() René Scharfe
2007-09-06 22:34 ` [PATCH 4/3] archive: specfile syntax change: "$Format:%PLCHLDR$" instead of just "%PLCHLDR" (take 2) René Scharfe
2007-09-06 16:51 ` [PATCH 5/3] archive: rename attribute specfile to export-subst René Scharfe
2007-09-06 17:13 ` Johannes Schindelin
2007-09-06 20:38 ` René Scharfe
2007-09-06 21:03 ` Junio C Hamano
2007-09-07 10:45 ` Johannes Schindelin
2007-09-04 23:13 ` [PATCH 2/3] archive: specfile support (--pretty=format: in archive files) René Scharfe
2007-09-05 0:19 ` 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=46E028B9.2090908@lsrfire.ath.cx \
--to=rene.scharfe@lsrfire.ath.cx \
--cc=Johannes.Schindelin@gmx.de \
--cc=ae@op5.se \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=simigern@cip.informatik.uni-erlangen.de \
--cc=thomas@glanzmann.de \
/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).