1

I have an issue where we supply source to a client that has to have customer specific legal comment header information installed in source files with several different versions of the headers depending on which source files they are ( ie: developer specified categories )

So what I want is an ability to specify a string like $Id$ or $SpecialName$ to define what header is to be inserted which will be expanded by the code distribution build ( makes zip or jar files ) into

$SpecialName: lots of customer specific stuff like a big header of copyright, legal, and  
 other info
 blah blah blah $

And then if they modify or patch something in the file and send it back I want to check the changes into git and have it ignore everything between the build expanded "$SpecialName:" and the next "$" the way $Id$ can be made to work when checking things in.

I saw a reference to a "$Format:" in this question but haven't found references to what it is and whether it is what I'm looking for or not.

Ideally I could specify the strings on the reference repository server "read only" and have it propagate to all users when they pull changes, but that is a separate issue from achieving the functionality which comes first.


It looks like one approach is to use "filters" - from the git book:

However, that result is of limited use. If you’ve used keyword substitution in CVS or Subversion, you can include a datestamp — the SHA isn’t all that helpful, because it’s fairly random and you can’t tell if one SHA is older or newer than another.

It turns out that you can write your own filters for doing substitutions in files on commit/checkout. These are the “clean” and “smudge” filters. In the .gitattributes file, you can set a filter for particular paths and then set up scripts that will process files just before they’re committed (“clean”, see Figure 7.2) and just before they’re checked out (“smudge”, see Figure 7.3). These filters can be set to do all sorts of fun things.

The relevant thing here is it would be appropriate to do this on the repository server and not on the client - is processing of the "file" data pre-commit and pre-checkout possible on the repository server?

Community
  • 1
  • 1
peterk
  • 5,136
  • 6
  • 33
  • 47
  • In git all machines have a repository, so any machine can in principle act as a repository server. – Robin Green Nov 03 '13 at 14:39
  • True - but the desire is to have a fresh clone or pull from a server (peer) that is considered "authoritative" have everything "pre-configured" so no additional action on the part of the retrieving peer is needed to have things work as desired. And yes this is a conflict between making this "one button seamless" and security because you don't want it to be easy to push auto-executing active code like hooks on peers or back to others insecurely. So the only way seems to be to establish a set of scripts maintained and distributed separately. – peterk Nov 04 '13 at 17:12
  • And doing this makes the "keeping in sync" process a bit more complex, and makes conformance with the protocol one is using incompatible with integrated git plugins in IDEs wqhich often arn't quite programmable enough. – peterk Nov 04 '13 at 17:13

1 Answers1

0

The traditional way to do this is for the version control system to do this expansion. But this is actually not necessary for you as you only need it to appear on client machines.

You just need to use some kind of templating tool in your source code distribution build process. It should not be necessary in most cases to make it ignore the headers if a patch is sent, because the patch should apply anyway, just with some fuzz, which won't prevent it from applying automatically.

Robin Green
  • 32,079
  • 16
  • 104
  • 187
  • It is more like if I get the whole file back and simply want to commit it without pre-processing. Wondering if there is any way to tag a block inside a source file as being ignored by git $Id$ appears to be and thus can be used, and was wondering if there is a mechanism where $ArbiraryWord$ or $PredefinedWord$ is also possible. Of course on can get fancy and put in a pre-processing hook on the server that could choose the substution set based on which branch is checked out which would enable the customer to have live Git access to the repository etc but ... – peterk Nov 02 '13 at 18:49
  • If you get a file you can generate a patch from it, by doing a plain `diff` (not a `git diff`) against the distributed source. – Robin Green Nov 02 '13 at 20:15
  • True - but you can't just unzip 500 files over the folder and then git commit it to the customer's branch which does it all by automation :) What I'm really asking is help in understanding the capabilities of the git toolset for processing source files so I can use it for any number of potential things. – peterk Nov 02 '13 at 22:51