Scott Deerwester
Scott Deerwester

Reputation: 3977

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?

Upvotes: 2

Views: 310

Answers (1)

jthill
jthill

Reputation: 60305

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.

Upvotes: 1

Related Questions