Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto-inserting metadata strings in source code with git?

Many legacy source code control systems (RCSS, SCCS, CVS...) provided metadata variables of a sort that would be automagically maintained by the system in source code, so you could do things like:

const char *header = "$Header$";

and it would be replaced with:

const char *header = "$Header: : /home/scott/src/project/file.c,v 1.4 1997/04/04 05:13:55 scott Exp scott$;

on commit. If memory serves, they had things like author, last checkin timestamp, as well as composite strings like the above. Really handy. Now that git has taken over the world, I can't find anything comparable. The closest I've come is to maintain a Python script or whatever that generates a source file with version information. That seems pretty kludgy. Is there some better option available, ideally within git, but even with some well-maintained third party addon or something?

like image 585
Scott Deerwester Avatar asked Mar 07 '26 23:03

Scott Deerwester


1 Answers

Those vcs's have no way to record content relationships among files, no way of tying your current work tree to any particular revision of anything without looking at each one individually, so without larding all your content with markers you've got no reasonable way to locate it in history.

Git tells you what revision your worktree content came from with its HEAD ref, Want to know what version a file is? git describe gets you a handy and reasonably recognizable moniker showing the base revision, you can flavor it to taste.

It's only when content is entirely divorced from the repo that you might need to embed identifiers, and for that, there's the export-subst attribute used by git archive. It allows you to apply keyword substitutions using any of git log's directives.

like image 179
jthill Avatar answered Mar 09 '26 12:03

jthill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!