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

Re: [PATCH/docs] make slash-rules more readable

From
Dr. Adam Nielsen <admin@in-ici.net>
Date
Apr 10, 2019, 07:39 UTC
Message-ID
<CAKrvxcX+Fi1U4NcH5Mqf0cR8QQc9FWtVQ-uuj0Dhd3qEu5o6XA@mail.gmail.com>
In-Reply-To
<xmqqzhoz2lpr.fsf@gitster-ct.c.googlers.com>
> the pattern is matched against paths in the directory where the
> `.gitignore` file that has the pattern in it is in, and any of
> its subdirectories (recursively).
> the pattern will match in all directories relative to
> the `.gitignore` file, with infinite depth.

I could not catch the difference between the meaning of both. However, I think "paths in the directory" and "directories relative to" are maybe both ambiguous.

Since a pattern without a non-trailing slash must always be a file name or a folder name, and does not have a leading slash, we could maybe just say it like this:

        the pattern is matched against all files and folders (recursively)
        from the location of the `.gitignore` file.
---------
> Unlike a pattern without a slash, a pattern with a
> non-trailing slash is matched against paths immediately in
> the directory the `.gitignore` file the pattern appears in
> is stored in, and does not get used in its subdirectories..

I think one can always assume that we talking about the relevant `.gitignore` file (where the pattern appears in).

Perhaps this covers it all?
        A pattern with a non-trailing slash is always considered
        to begin at the `.gitignore` file location.
followed by your example
> For example, the pattern `doc/frotz/` that appears in
> `.gitignore` at the top-level of the project matches
> `doc/frotz` directory (again, seen from the top-level), but
> not `a/doc/frotz`.
and maybe one more example
        Note that the pattern `doc/frotz` and `/doc/frotz` are
        equivalent.
        However `/bar` and `bar` are different. They both match the
        `bar` file or folder at the top level, but only the latter
will also match `foo/bar`
        (when `foo` is at the top level).

This avoids the hustle with the ambiguous path, where it starts, and trailing or leading slashes. Together with the two examples it seems to be a good compromise between accuracy and understandable.

The alternative would be to say
        A pattern with a non-trailing slash is only matched against any
        path that begins in the directory of the `.gitignore` file.

While this is maybe clearer then saying "pattern [...] always considered to begin at` it is ambiguous about the slashes. So a very accuracy but maybe less understandable version would be something like this:

        A pattern with a non-trailing slash is only matched against any
        path that begins in the directory of the `.gitignore` file.
        For example, if the `.gitignore` file is in folder `doc`
        the path to file  `bar/doc/a/foo` that begins in `doc` is `a/foo`.
        A pattern that matches a path except for a leading slash or
trailing slash
        is still considered a match. It is still valid however,
        that when a pattern ends with a slash, it would only find a
match with a directory.
---------
> Also, a pattern "/doc" matches doc at the current level (i.e. the
> directory in which .gitignore file that the pattern was taken from
> is found) and not in any subdirectories.  Is that clear in the
> proposed update?
Yes.
However, in the docs is already one paragraph solely dedicated for this case:
> A leading slash matches the beginning of the pathname. For example, "/*.c" matches
> "cat-file.c" but not "mozilla-sha1/sha1.c".

However, we have already a better and more in detail explained example in the new proposal `*` paragraph and and the case with the leading slash is now a sub-case of `A pattern with a non-trailing slash` so we might just get rid of the above paragraph? ----------

Thank you for explaining me how the algorithm works procedurally. It gave some inside of the origin of "If the pattern ends with a slash, it is removed for the purpose of the following description.." ---------

All the best, Adam

Previous: Junio C HamanoNext: Dr. Adam Nielsen
Message 7 of 8 in “make slash-rules more readable”
  1. make slash-rules more readableDr. Adam Nielsen, Apr 5, 2019
  2. Junio C HamanoApr 8, 2019
  3. Dr. Adam NielsenApr 8, 2019
  4. Junio C HamanoApr 9, 2019
  5. Dr. Adam NielsenApr 9, 2019
  6. Junio C HamanoApr 9, 2019
  7. Dr. Adam NielsenApr 10, 2019
  8. Dr. Adam NielsenApr 17, 2019

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.