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

Re: [PATCH] Quick description of possible gitattributes system

From
Junio C Hamano <junkio@cox.net>
Date
Mar 2, 2007, 00:09 UTC
Message-ID
<7vejo8o69o.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<200703011206.47213.andyparkins@gmail.com>
Andy Parkins <andyparkins@gmail.com> writes:
Show 8 quoted lines
> +Attributes are attached to paths in one of two ways:
> +
> + - Via the .gitattributes file.  This will work in the same way as the
> +   .gitignore file.  That is, there can be multiple .gitattributes files
> +   throughout the working directory.
> +
> +   Typically the .gitattributes file will be a version controlled file,
> +   just like .gitignore.

Another point to stress here is that these are property of the paths of the project and independent of the platform each user happens to have a repository of the project on. If something is text, then it is text whether the platform is on UNIX or on DOS.

> +   It will obviously be of different format from the .gitattributes
> +   file, but the attribute names and path specification will be
> +   identical (and specified as if from the root of the repository tree).

I am in favor of also using $GIT_DIR/config format even for the in-tree .gitattributes files. For one thing, it makes the syntax and quoting rules saner and more consistent (blanks in pathname patterns and such), and we already have a parser for it.

	[attribute "image/png"]
        	path = "*.png"
	[attribute "image/jpg"]
        	path = "*.jpg"
        	path = "*.jpeg"
	[attribute "text"]
		; anything that is image/* is non-text -- I am
                ; not sure if we want to allow this which means
                ; we need to resolve dependencies, though.
                attr = "!image/*"
		; inside list of path-patterns, the first match wins.
		path = "!this-is-not-text.txt"
        	path = "*"
	; .gitignore is a mere special case of "ignored" attribute.
	[attribute "ignored"]
        	path = "*~"
                path = "!hand-maintained.o"
                path = "*.[aso]"

Earlier, I said attributes are property of project, but that does not mean we should forbid users to define more paths in config. On DOS, you might want to have:

	[attribute "ignored"]
        	path = "*.obj"

to suppliment the last entry of the above "ignored" that is meant to catch object files, until the upstream project adds it to the .gitattribute files.

In contrast to that attributes define property of paths of the project, handlers define how we should behave on paths with certain attributes in a particular repository. So it is important to stress that that handler sections should never appear in in-tree .gitattributes files. Because they are per-repository, the same project checked out on DOS will be used with this handler definition (which would be the built-in default not to require the users to have one in ~/.gitconfig):

	[handler "text"]
        	input = crlf
                output = crlf
while on UNIX the input/output would be no-op.
Show 10 quoted lines
> +----------------------------------------
> +[handler "fix-line-endings"]
> +  attribute = text/plain
> +  infilter = eol_lf
> +  outfilter = eol_local
> +----------------------------------------
> +
> +This definition creates a handler named "fix-line-endings" (don't suppose
> +they actually need names) that would run the "eol_lf" filter on check
> +in, and the "eol_local" filter on checkout.

I would suggest making handler section _match_ the attribute names. By "match", what I mean is to allow something like this:

	[handler "image/*"]
        	pretty = "cmd display -"
even though the attributes are "image/png", "image/jpg", etc.
> +[handler "show-images"]
> +  attribute = image/gif
> +  prettyfilter = pipe display -

I would recommend against calling them *filter. After all, the semantics of each handler action (such as input, output and pretty) already determine if it needs to act as a filter or data sink. We do not need to say prettyfilter either; it is not even a filter to begin with -- it is a data sink.

Previous: Robin RosenbergNext: Junio C Hamano
Message 8 of 20 in “Quick description of possible gitattributes system”
  1. Quick description of possible gitattributes systemAndy Parkins, Mar 1, 2007
  2. Brian GernhardtMar 1, 2007
  3. Andy ParkinsMar 2, 2007
  4. Brian GernhardtMar 2, 2007
  5. Andy ParkinsMar 2, 2007
  6. Brian GernhardtMar 2, 2007
  7. Robin RosenbergMar 1, 2007
  8. Junio C HamanoMar 2, 2007
  9. Junio C HamanoMar 2, 2007
  10. Andy ParkinsMar 2, 2007
  11. Andy ParkinsMar 2, 2007
  12. Jakub NarebskiMar 2, 2007
  13. Linus TorvaldsMar 2, 2007
  14. Andy ParkinsMar 2, 2007
  15. Linus TorvaldsMar 2, 2007
  16. Johannes SchindelinMar 2, 2007
  17. Andy ParkinsMar 2, 2007
  18. Andy ParkinsMar 2, 2007
  19. Junio C HamanoMar 3, 2007
  20. Jakub NarebskiMar 3, 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.