Re: RCS keyword expansion

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Salikh Zakirov
Date: Friday, October 12, 2007 - 12:08 pm

Peter Karlsson wrote:

For what it's worth, I've made a small exercise on git scripting 
(which I'm total newbie in), and tried to use filter mechanism
(smudge/clean) for solving the problem Peter stated.

Fundamental problems of this approach were discussed in full
on the mailing list, however, as I understand Peter's situation,
they do not apply, as the web site workspace is 'checkout-only',
and no actual work (commits) are made there. 
Thus, it will not cause any merge problems etc.

Anyway, smudge/clean does not give the immediate solution to the problem
because of smaller technical shortcomings:
* smudge filter is not passed a name of file being checked out, 
  so it is not possible to exactly find the commit identifier.
  However, this is alleviated by the fact that 'smudge' is only being run
  for the changed files, so the last commit *is* the needed one.

* smudge filter is not passed a commit identifier. This is a bit more serious,
  as this information is nowhere to get from otherwise. I tried to use 'HEAD'
  value, but apparently it is not yet updated at the moment 'smudge' is being
  run, so the files end up with the date of the "previous" commit rather than
  the commit being checked out. "Previous" means the commit that was checked
  out before. The problem gets worse if different branch is checkout out,
  as the files get the timestamp of a previous branch.

AFAIR, lack of information in smudge filter was intentional, to discourage
this particular use of smudge/clean mechanism. However, I think this can be
reconsidered given the Peter's use case: "checkout-only" workspace for immediate
publishing to webserver. Alternatively, anyone interested in this use case
could implement additional smudge arguments as a site-local patch.

And then, there are small annoyances, which seems to be inevitable:
* if you change 'clean' filter and check out earlier revision, it will be
  reported as having modifications (due to changed 'clean' definition).

Below is what I ended up with:

.gitattributes:
* filter=date

.git/config:
[filter "date"]
        smudge = .git/smudge
        clean = .git/clean

.git/clean:
#!/usr/bin/perl -p
s#\$Date[^\$]*\$#\$Date\$#;

.git/smudge:
#!/usr/bin/perl

use POSIX qw(strftime);
$branch = `git-symbolic-ref HEAD`; chomp($branch);
$rev = `git-rev-list -n 1 $branch`; chomp($rev);
open REV, "git show --pretty=raw $rev|";
$time = time; # default to current time
while (<REV>) {
    if (/^committer.* (\d+) [\-+]\d*$/) {
        $time = $1;
    }
}
close REV;

$date = strftime "%Y-%m-%d %H:%M:%S", localtime($time);
while (<>) {
    s#\$Date[^\$]*\$#\$Date: $date\$#;
    print;
}

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
RCS keyword expansion, Peter Karlsson, (Thu Oct 11, 7:47 am)
Re: RCS keyword expansion, Johannes Sixt, (Thu Oct 11, 8:02 am)
Re: RCS keyword expansion, Randal L. Schwartz, (Thu Oct 11, 8:09 am)
Re: RCS keyword expansion, Oliver Kullmann, (Thu Oct 11, 8:59 am)
Re: RCS keyword expansion, Peter Karlsson, (Thu Oct 11, 10:55 am)
Re: RCS keyword expansion, Alex Riesen, (Thu Oct 11, 11:09 am)
Re: RCS keyword expansion, Lars Hjemli, (Thu Oct 11, 12:16 pm)
Re: RCS keyword expansion, Alex Riesen, (Thu Oct 11, 12:21 pm)
Re: RCS keyword expansion, Johannes Schindelin, (Thu Oct 11, 1:47 pm)
Re: RCS keyword expansion, Sam Vilain, (Thu Oct 11, 2:20 pm)
Re: RCS keyword expansion, Sam Vilain, (Thu Oct 11, 2:35 pm)
Re: RCS keyword expansion, Peter Karlsson, (Thu Oct 11, 10:26 pm)
Re: RCS keyword expansion, Peter Karlsson, (Thu Oct 11, 10:27 pm)
Re: RCS keyword expansion, Johannes Schindelin, (Fri Oct 12, 3:02 am)
Re: RCS keyword expansion, Peter Karlsson, (Fri Oct 12, 3:50 am)
Re: RCS keyword expansion, Johannes Sixt, (Fri Oct 12, 4:05 am)
Re: RCS keyword expansion, Lars Hjemli, (Fri Oct 12, 4:21 am)
Re: RCS keyword expansion, Johannes Schindelin, (Fri Oct 12, 4:34 am)
Re: RCS keyword expansion, Jan Hudec, (Fri Oct 12, 5:57 am)
Re: RCS keyword expansion, Salikh Zakirov, (Fri Oct 12, 12:08 pm)
Re: RCS keyword expansion, Johannes Schindelin, (Fri Oct 12, 3:42 pm)
Re: RCS keyword expansion, Zakirov Salikh, (Fri Oct 12, 4:52 pm)
Re: RCS keyword expansion, Peter Karlsson, (Mon Oct 15, 7:03 am)
Re: RCS keyword expansion, Johannes Schindelin, (Mon Oct 15, 7:28 am)