git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: RCS keyword expansion

From
JHJan Hudec <bulb@ucw.cz>
Date
Oct 12, 2007, 12:57 UTC
Message-ID
<20071012125751.GB7865@efreet.light.src>
In-Reply-To
<Pine.LNX.4.64.0710121144001.3682@ds9.cixit.se>
On Fri, Oct 12, 2007 at 11:50:51 +0100, Peter Karlsson wrote:
Show 5 quoted lines
> > But don't you see?  When switching branches, this totally breaks down.
> 
> Why would it? If the file is the same on both branches, nothing would
> happen (it is still the same version), and if the file is different, it
> gets changed anyway, and a new keyword expansion would take place.

It does not -- the blob ID is the same. And you can indeed get $Id$ expanded to that (see gitattributes(5)). However, that's the ONLY thing that is the same. The date of last modification or ID of commit that last touched that file might not.

Why? Because git tracks content, not history. The trees and blobs (files) are identified by SHA1 hashes of their content. Only commit objects add the notion of history. Thus if two commits contain file with the same text, it's the same file. Even if the file is the same in those commit purely by accident.

Show 13 quoted lines
> > No, really, IMHO it is enough to show either the commit name or the
> > blob name of the file. After all, you are not interested in the date
> > that this file was last committed, but in the _contents_.
> 
> Yes, but I want it on the lowest addressable unit size, i.e on the file
> level (I could possibly want to have the last commit for a set of files
> when I have something that get generated from several sources, but that
> is rare for a regular website, unless since javascripts and stylesheets
> etc. are delivered separately).
> 
> Already today when you do "git log" on a file, you get the log filtered
> for only changes to that file. So the mechanisms seem already to be
> there, I just need to figure out how to apply them to what I want.

Yes. But you need the (current) commit for that. Now if a file foo is the same on branches A and B, switching between them will not touch that file, but git log foo may well give you completely different results. That's why there's no date or commit that last touched a file.

Show 14 quoted lines
> > So why not go for the contents?  With CVS/SVN you only have the
> > chance to do that by date or version number. With git, we have a more
> > powerful way: we do it by a hash of the contents.
> 
> Yes, but the hash if of "everything". I'm not interested in
> "everything" in this context, and I don't want to have a separate git
> repository for each file...
> 
> > If it's not what you want, I suggest rethinking what you want ;-)
> > Otherwise it is scripting time for you.  It's easy enough with git.
> 
> That's what I'm trying to figure out. I assume it would be possible to
> do with some kind of hook that is run on checkout. But I can't figure
> out how to do that.

If you read the (already mentioned) gitattributes(5) manpage, you'll find description of smudge and clean filters. They will be applied to each file written out to the tree and read back respectively. But be sure to understand why you can't -- for principial, not techical reasons -- have the date or commit ID expanded correctly in all cases.

-- 
						 Jan 'Bulb' Hudec <bulb@ucw.cz>
Previous: Johannes SchindelinNext: Salikh Zakirov
Message 16 of 27 in “RCS keyword expansion”
  1. Peter KarlssonOct 11, 2007
  2. Johannes SixtOct 11, 2007
  3. Randal L. SchwartzOct 11, 2007
  4. Oliver KullmannOct 11, 2007
  5. Alex RiesenOct 11, 2007
  6. Johannes SchindelinOct 11, 2007
  7. Sam VilainOct 11, 2007
  8. Peter KarlssonOct 12, 2007
  9. Johannes SchindelinOct 12, 2007
  10. Peter KarlssonOct 12, 2007
  11. Johannes SixtOct 12, 2007
  12. Lars HjemliOct 12, 2007
  13. Johannes SchindelinOct 12, 2007
  14. Peter KarlssonOct 15, 2007
  15. Johannes SchindelinOct 15, 2007
  16. Jan HudecOct 12, 2007
  17. Salikh ZakirovOct 12, 2007
  18. Johannes SchindelinOct 12, 2007
  19. Zakirov SalikhOct 12, 2007
  20. Peter KarlssonOct 11, 2007
  21. Alex RiesenOct 11, 2007
  22. Peter KarlssonOct 12, 2007
  23. Barry FishmanOct 12, 2007
  24. Linus TorvaldsOct 12, 2007
  25. Florian WeimerOct 12, 2007
  26. Sam VilainOct 11, 2007
  27. Lars HjemliOct 11, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.