Another approach to id strings in Git?

I plan on moving my company from CVS to Git, and some engineers want us to still use CVS keyword strings, such as $Id: $. I read all about implementing this with the ident setting .gitattributes, and I understand why this is undesirable, although perhaps for smaller source trees as well. (Our source is huge, so I think that would be impossible.)

Our engineers do not really care about the presence of the SHA1 hash file in the file. They just want to know:

  • date of last modification
  • committer name
  • maybe commit message

It is very convenient for them to see this information in the file headers when viewing the code, and I can not argue with that.

I want to know:

Is there a way to info-stamp all step-by-step files at the moment before git commit? In other words, to run the perl command, which replaces with the $Id: $block of the desired information - on working copies of files that were committed?

This will not require any action .gitattributes. git just needed to know how to combine two such blocks of information, ideally by choosing a later one. The printed information will be just another file change in the newly created version.

I looked at this in a preliminary commit, but it seems it is designed differently - not for editing files, but only for checking them. Am I right about that?

? , , git , , .gitattributes.

//.

+5
3

RCS (, , CVS) $Id:$, . , - 1.8.2-rc10 plain 1.8.2. - , file, git log file , , RCS. , CVS (, , , git ).

+3

git documentation , .

script , , - ( )

#! /usr/bin/env ruby
data = STDIN.read
last_info = `git log --pretty=format:"%ad %cn %s" -1`
puts data.gsub('$Last$', '$Last: ' + last_info.to_s + '$')

$ git config filter.last_expander.smudge expand_last_info
$ git config filter.last_expander.clean 'perl -pe "s/\\\$Last[^\\\$]*\\\$/\\\$Last\\\$/"'

setup.gitattributes

echo '*.txt filter=last_expander' >> .gitattributes

: ( ), , , , , , . , . , ? .

+3

:

  • :

    #!/bin/sh
    git diff --cached --name-only -z --diff-filter=ACM |
            xargs -r0 .filters/keywords --
    git diff --cached --name-only -z --diff-filter=ACM |
            xargs -r0 git add -u -v --
    
  • commit-msg:

    #!/bin/sh
    awk '!/^[[:space:]]*(#|$)/{exit f++}END{exit !f}' "$1" && exit
    # NOTREACHED unless commit was aborted
    git diff --cached --name-only -z --diff-filter=ACM |
            xargs -r0 .filters/keywords -d --
    git diff --cached --name-only -z --diff-filter=ACM |
            xargs -r0 git add -u -v --
    
  • ".filters/fraubsd-keywords", " ":

    https://raw.githubusercontent.com/freebsdfrau/FrauBSD/master/.filters/fraubsd-keywords

  • " ", :

    • Fraubsd to header
    • _FrauBSD to _Header

After that, every time you do git commit, the text $Header$and / or $Header: ... $will be translated into$Header: file YYYY-MM-DD HH:MM:SS GMTOFFSET committer $

NOTE. You may need to change the small "keywords" section of the script to work with more or less file types. At the time of this writing, it only works with files that are “ASCII text” or “shell scripts”.

0
source