From: Derek Moore <hidden> Date: 2016-06-15 23:02:41
I first noticed this using the system git provided in Fedora 21, so I
cloned the official git repo, built from source, and it would appear
there are even more options that don't work with export-subst in the
latest code.
I tested this under commit 63a45136a329bab550425c3142db6071434d935e
(HEAD, origin/master, origin/HEAD, master).
Take, for example, the following script:
FILE=Foo.pm
DIR=$(mktemp -d /tmp/git.XXXXXX)
cd $DIR
git init
echo '*.pm export-subst ident' >> .gitattributes
echo '# Last Author : $Author: $Format:%an$ $' > $FILE
echo '# Last Date : $Date: $Format:%ai (%ad)% $' >> $FILE
echo '# Last Version : $Revision: $Format:%d$ $' >> $FILE
echo '# Last Version v2: $Revision: $Format:%D$ $' >> $FILE
echo '# Last Commit : $Commit: $Format:%H$ $' >> $FILE
echo '# This File : $Id$' >> $FILE
echo 'our $VERSION = (qw($Format:%N$))[1];' >> $FILE
git add .
git commit -a -m "Initial commit."
git notes add -f -m '$Release: 0048 $'
git tag -f releases/R0048
git archive HEAD $FILE | tar xf - --to-stdout
rm $FILE
git checkout -- $FILE
cat $FILE
git log --format='%N' -1
You can tell I'm attempting to recreate CVS keywords (bwahahaa!) for a
project that is insisting they need them.
I'd be happy to write a bunch of unit tests for export-subst and all
PRETTY FORMATS format:<string> options, if that would be desirable. I
see the t/ directory, and the t/test-lib.sh stuff looks simple enough
(TAP in bash, hmm).
Thanks,
Derek
From: Derek Moore <hidden> Date: 2016-06-15 23:02:41
On Thu, Oct 9, 2014 at 10:56 AM, Derek Moore [off-list ref] wrote:
I first noticed this using the system git provided in Fedora 21, so I
cloned the official git repo, built from source, and it would appear
there are even more options that don't work with export-subst in the
latest code.
I'm a dumb ass. After installing my newly compiled git to /usr/local,
I neglected to spawn a new shell so the new binary could get picked up
by my $PATH. Despite /usr/local/bin preceding /usr/bin, /usr/bin/git
was cached by my shell, and 'which git' was lying to me, therefore my
testing of new format:<string> options was invalid.
I must retract the statement "and it would appear there are even more
options that don't work with export-subst in the latest code."
As far as I've tested it would seem only %N doesn't resolve inside of
$Format:$, until I maybe do unit tests for this to identify any
others.
From: Jeff King <hidden> Date: 2016-06-15 23:02:41
On Thu, Oct 09, 2014 at 12:42:39PM -0500, Derek Moore wrote:
As far as I've tested it would seem only %N doesn't resolve inside of
$Format:$, until I maybe do unit tests for this to identify any
others.
Yes, %N is somewhat special in that the calling code needs to initialize
the notes tree itself. We can't just do it lazily when we see the first
%N because _which_ notes we show depends on other options (e.g., for
log, if you've used --notes-ref, --show-notes=..., etc).
So in theory you need something like 5b16360 (pretty: Initialize notes
if %N is used, 2010-04-13), but adapted for git-archive. The trick,
though, is that we do not even see the format string until we are
looking at a particular file with a $Format$ marker. So you'd have to
lazily initialize notes there (and if you want to support picking
specific notes refs, you'd have to teach git-archive new options to do
so[1]).
Here's a quick-and-dirty patch that makes the snippet you posted earlier
do what I think you expected. I haven't tested it beyond that, and am
not planning to push it forward myself, but please feel free to use it
as a basis for building a solution.
---
[1] I think you could get pretty far using `git -c core.notesRef=foo` to
give ad-hoc config, as the notes code should use that as the
ultimate default. But I didn't try it.
On Thu, Oct 09, 2014 at 12:42:39PM -0500, Derek Moore wrote:
quoted
As far as I've tested it would seem only %N doesn't resolve inside of
$Format:$, until I maybe do unit tests for this to identify any
others.
Yes, %N is somewhat special in that the calling code needs to initialize
the notes tree itself. We can't just do it lazily when we see the first
%N because _which_ notes we show depends on other options (e.g., for
log, if you've used --notes-ref, --show-notes=..., etc).
So in theory you need something like 5b16360 (pretty: Initialize notes
if %N is used, 2010-04-13), but adapted for git-archive. The trick,
though, is that we do not even see the format string until we are
looking at a particular file with a $Format$ marker. So you'd have to
lazily initialize notes there (and if you want to support picking
specific notes refs, you'd have to teach git-archive new options to do
so[1]).
Here's a quick-and-dirty patch that makes the snippet you posted earlier
do what I think you expected. I haven't tested it beyond that, and am
not planning to push it forward myself, but please feel free to use it
as a basis for building a solution.
---
[1] I think you could get pretty far using `git -c core.notesRef=foo` to
give ad-hoc config, as the notes code should use that as the
ultimate default. But I didn't try it.