threads / discuss / 21896

Generic filters for git archive?

Subject: Generic filters for git archive?

## tl;dr

4 messages between Dec 8, 2009 and Dec 15, 2009.

replies: 3people: 2as markdown or json

Russ Dill· Dec 8, 2009, 01:06 UTC · lore

I'm trying to add copyright headers to my source files as they are exported via git archive. eg:

* $Copyright$
to
 * Copyright (c) 2003-2009 by Foo Bar
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

And properly handling things like '# $Copyright$', '// $Copyright$', etc. I have a sed script that does this, but no way to apply it to the output of git archive. I tried setting up a smudge filter that would only smudge output on archive exports, but it doesn't appear that the smudge filters get run on git archive.

I am currently running 1.6.3.3
René Scharfe· Dec 9, 2009, 22:48 UTC · re: Russ Dill · lore

Re: Generic filters for git archive?

Am 08.12.2009 02:06, schrieb Russ Dill:
Show 30 quoted lines
> I'm trying to add copyright headers to my source files as they are
> exported via git archive. eg:
> 
> * $Copyright$
> 
> to
> 
>  * Copyright (c) 2003-2009 by Foo Bar
>  *
>  * This program is free software; you can redistribute it and/or modify it
>  * under the terms of the GNU General Public License as published by the
>  * Free Software Foundation; either version 2 of the License, or (at your
>  * option) any later version.
>  *
>  * This program is distributed in the hope that it will be useful, but
>  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
>  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
>  * for more details.
>  *
>  * You should have received a copy of the GNU General Public License
>  * along with this program; if not, write to the Free Software Foundation,
>  * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
> 
> And properly handling things like '# $Copyright$', '// $Copyright$',
> etc. I have a sed script that does this, but no way to apply it to the
> output of git archive. I tried setting up a smudge filter that would
> only smudge output on archive exports, but it doesn't appear that the
> smudge filters get run on git archive.
> 
> I am currently running 1.6.3.3

Is the filter attribute contained in a .gitattribute file that's part of the tree you are trying to export? If it's only in the worktree copy, then you need to use the option --worktree-attributes to make git archive use it.

René
Russ Dill· Dec 15, 2009, 07:08 UTC · re: René Scharfe · lore

Re: Generic filters for git archive?

On Wed, Dec 9, 2009 at 3:48 PM, René Scharfe <rene.scharfe@lsrfire.ath.cx> wrote:

Show 36 quoted lines
> Am 08.12.2009 02:06, schrieb Russ Dill:
>> I'm trying to add copyright headers to my source files as they are
>> exported via git archive. eg:
>>
>> * $Copyright$
>>
>> to
>>
>>  * Copyright (c) 2003-2009 by Foo Bar
>>  *
>>  * This program is free software; you can redistribute it and/or modify it
>>  * under the terms of the GNU General Public License as published by the
>>  * Free Software Foundation; either version 2 of the License, or (at your
>>  * option) any later version.
>>  *
>>  * This program is distributed in the hope that it will be useful, but
>>  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
>>  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
>>  * for more details.
>>  *
>>  * You should have received a copy of the GNU General Public License
>>  * along with this program; if not, write to the Free Software Foundation,
>>  * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
>>
>> And properly handling things like '# $Copyright$', '// $Copyright$',
>> etc. I have a sed script that does this, but no way to apply it to the
>> output of git archive. I tried setting up a smudge filter that would
>> only smudge output on archive exports, but it doesn't appear that the
>> smudge filters get run on git archive.
>>
>> I am currently running 1.6.3.3
>
> Is the filter attribute contained in a .gitattribute file that's part of
> the tree you are trying to export?  If it's only in the worktree copy,
> then you need to use the option --worktree-attributes to make git
> archive use it.

hmm..It does seem to be running. But I'd really like to use the gitattributes from the tagged version I'm exporting and I don't want the smudge filter to run on files I'm working on in my source tree, just on the export.

René Scharfe· Dec 15, 2009, 13:06 UTC · re: Russ Dill · lore

Re: Generic filters for git archive?

Am 15.12.2009 08:08, schrieb Russ Dill:
> hmm..It does seem to be running. But I'd really like to use the
> gitattributes from the tagged version I'm exporting and I don't want
> the smudge filter to run on files I'm working on in my source tree,
> just on the export.
This seems to work here:
   $ git version
   git version 1.6.3.3
   $ mkdir /tmp/x
   $ cd /tmp/x
   $ git init
   Initialized empty Git repository in /tmp/x/.git/
   $ echo sc >a
   $ git add a
   $ echo '#!/bin/sh' >f
   $ echo 'sed "s/sc/Santa Claus/"' >>f
   $ chmod 755 f
   $ git config filter.sc.smudge ./f
   $ echo 'a filter=sc' >.gitattributes
   $ git add .gitattributes
   $ git commit -m.
   [master (root-commit) 57f6bef] .
    2 files changed, 2 insertions(+), 0 deletions(-)
    create mode 100644 .gitattributes
    create mode 100644 a
   $ rm .gitattributes
   $ git archive --prefix=x HEAD | tar xf - xa
   $ cat xa
   Santa Claus
   $ git archive --prefix=y --worktree-attributes HEAD | tar xf - ya
   $ cat ya
   sc

The first archive call uses the committed .gitattributes file and runs the file through the smudge filter. The second one uses the worktree version, which doesn't exist, so no filtering occurs.

What commands do you use?

Thanks, René

← back to recent threads