Integrating with hooks
I've created some bash functions which handle tagging some files with revision information, but even after reading the git manual I'm not really sure how to integrate them so that they remove revision expansion before each check-in (to avoid cluttering the repository with keyword substitutions), and add them back (with the current commit info) after each commit.
These are the functions:
# Show some kind of useful revision string, like the RCS $Id$ string. I
# think commit hash, filename, hostname containing the repository, and
# timestamp should be plenty of information to track down a given file.
git-id () {
for file in "$@"; do
_date=$(date +'%F %T %Z')
git log -1 \
--pretty=format:"[%h] \"$file\" $(hostname -f) ($_date)" \
"$file"
done
}
# Replace the $Id$ keyword string in the file itself.
git-export () {
for file in "$@"; do
echo Modifying $file...
_id=$(git-id "$file")
sed -ri 's/\$(Id|Revision).*\$/$Id: '"$_id"' $/' "$file"
done
}
# Clean the $Id$ keyword string to prevent cluttering the repository
# with keyword-revision diffs when we check the file back in.
git-unexport () {
for file in "$@"; do
echo Resetting $file...
sed -ri 's/\$Id.*\$/$Id$/' "$file"
done
}How do I hook this in the way I want so that it's handled automatically?
Signature · 2 lines
"Oh, look: rocks!" -- Doctor Who, "Destiny of the Daleks"
[Cc: Todd A. Jacobs <[email protected]>, [email protected]]
Quoted 8 lines · Todd A. Jacobs
I've created some bash functions which handle tagging some files with revision information, but even after reading the git manual I'm not really sure how to integrate them so that they remove revision expansion before each check-in (to avoid cluttering the repository with keyword substitutions), and add them back (with the current commit info) after each commit.
These are the functions:
[...]
Quoted 1 line
How do I hook this in the way I want so that it's handled automatically?
Take a look at gitattributes(5), namely 'filter' attribute.
Although instead of implementing it "by hand", perhaps it would be enough to use 'ident' and/or 'export-subs' attribute.
P.S. Because of the way git updates files, and git thinks about files it is I think universally regarded to be bad idea to put in a file any Id that depend on commit data.
Signature · 3 lines
Jakub Narebski Warsaw, Poland ShadeHawk on #git
Quoted 1 line · Jakub Narebski
Take a look at gitattributes(5), namely 'filter' attribute.
Thanks, I took a look at the man page you suggested. The "ident" feature almost does what I want, but doesn't seem to take any sort of format string. So, I thought I'd explore "filter," but can't really find any examples of how to implement the smudge and clean commands, which seem to be what I'm really trying to do here.
Is there an example somewhere that you can point me to? The man page doesn't really show any examples of how to implement the filter attribute, so I'm a little unsure how to proceed.
Signature · 2 lines
"Oh, look: rocks!" -- Doctor Who, "Destiny of the Daleks"
Quoted 9 lines · Todd A. Jacobs
Quoted 1 line · Jakub Narebski
Take a look at gitattributes(5), namely 'filter' attribute.
Thanks, I took a look at the man page you suggested. The "ident" feature almost does what I want, but doesn't seem to take any sort of format string. So, I thought I'd explore "filter," but can't really find any examples of how to implement the smudge and clean commands, which seem to be what I'm really trying to do here.
A clean and smudge filter processes one file at a time. It reads the old content from stdin and writes the result to stdout.
There is a tiny example in the test suite, t/t0021-conversion.sh, look for rot13.sh.
-- Hannes
Hi,
Quoted 7 lines · Todd A. Jacobs
Quoted 1 line · Jakub Narebski
Take a look at gitattributes(5), namely 'filter' attribute.
Thanks, I took a look at the man page you suggested. The "ident" feature almost does what I want, but doesn't seem to take any sort of format string.
Note that the ident feature will give you _only_ the blob sha1.
I guess that you're more interested in the export-subst feature.
Hth,
Dscho
Quoted 7 lines · Todd A. Jacobs
Quoted 1 line · Jakub Narebski
Take a look at gitattributes(5), namely 'filter' attribute.
Thanks, I took a look at the man page you suggested. The "ident" feature almost does what I want, but doesn't seem to take any sort of format string.
The ident feature provides only sensible Id for a file (if you want to avoid potentially rewriting _all_ and not only changed files on checkout / switching branch / reset --hard). All Ids which have commit info, like commit id, commit date, author are not sensible in mentioned sense.
Quoted 7 lines
So, I thought I'd explore "filter," but can't really find any examples of how to implement the smudge and clean commands, which seem to be what I'm really trying to do here.
Is there an example somewhere that you can point me to? The man page doesn't really show any examples of how to implement the filter attribute, so I'm a little unsure how to proceed.
Cannot help you there, but see examples of diff and merge attributes, it should I think be similar.
Signature · 3 lines
Jakub Narebski Warsaw, Poland ShadeHawk on #git