On Fri, Jan 11, 2013 at 11:56:43AM -0800, Russell wrote:

> I am trying to implement a filter that updates a "Last modified: <date>" 
> field in a source file comment header on commit. From the reading I've done 
> so far this seems to be a different approach to the usual "mimic RCS 
> behaviour" approach that uses a source file with the $Date$ (or similar) 
> keyword that gets replaced with the current date on checkout.
> Most succintly my approach is thus: 
>    sed "s|Last modified: [0-9]*|Last modified: ${currentYear}|"
> ie. On a clean, look for "Last modified: <some year>" text and replace it 
> with "Last modified: <this year>" as the file is committed (a change to a 
> file isn't "real" until it is preserved in the repo).
> I think this approach makes more sense than the RCS approach because now 
> the central repository always represents the actual commited changes, 
> rather than some abstraction using variables and the local files should 
> also be perfectly aligned with packaging for distribution via tarball or 
> such because the dates are self-consistent.
> The problem is that the local files and the files in the repo end up out of 
> sync. The local files have the old date, but the repo has the modified 
> date. I have to rm the file and git checkout <myFile> to get the change in 
> my local directory; strangely git checkout --force doesn't pick up the 
> change either.
> Is someone able to explain what I need to do to make this work?

You seem to misunderstand the concept a bit.
The blobs kept in the repo should have some neutral placeholder, such as
to read something like "Last modified $Timestamp$" in them.

Then, in the smudge filter, which is run after checking out the blob
into a file in the work tree, you replace that $Timestamp$ with
something appropriate for your work tree.

Then, in the clean filter, which is run before the new blob is written
to the repository, your task is to *revert* that local change, that is,
to change whatever your smudge filter did back to $Timestamp$.

That way your repository always keeps "normalized" blobs.


Reply via email to