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

Re: [PATCH 4/4] archive: queue directories for all types of pathspecs

From
Jeff King <peff@peff.net>
Date
Sep 13, 2017, 12:53 UTC
Message-ID
<20170913125312.awtlbndv5j6kkcmz@sigill.intra.peff.net>
In-Reply-To
<837ff6fe-a645-97fe-4b21-ec36f662ce19@web.de>
On Wed, Sep 13, 2017 at 12:43:57AM +0200, René Scharfe wrote:
Show 16 quoted lines
> -- >8 --
> Subject: [PATCH] archive: don't add empty directories to archives
> 
> While git doesn't track empty directories, git archive can be tricked
> into putting some into archives.  One way is to construct an empty tree
> object, as t5004 does.  While that is supported by the object database,
> it can't be represented in the index and thus it's unlikely to occur in
> the wild.
> 
> Another way is using the literal name of a directory in an exclude
> pathspec -- its contents are are excluded, but the directory stub is
> included.  That's inconsistent: exclude pathspecs containing wildcards
> don't leave empty directories in the archive.
> 
> Yet another way is have a few levels of nested subdirectories (e.g.
> d1/d2/d3/file1) and ignoring the entries at the leaved (e.g. file1).
s/leaved/leaves/ ?
Show 18 quoted lines
> The directories with the ignored content are ignored as well (e.g. d3),
> but their empty parents are included (e.g. d2).
> 
> As empty directories are not supported by git, they should also not be
> written into archives.  If an empty directory is really needed then it
> can be tracked and archived by placing an empty .gitignore file in it.
> 
> There already is a mechanism in place for suppressing empty directories.
> When read_tree_recursive() encounters a directory excluded by a pathspec
> then it enters it anyway because it might contain included entries.  It
> calls the callback function before it is able to decide if the directory
> is actually needed.  For that reason git archive adds directories to a
> queue and writes entries for them only when it encounters the first
> child item -- but currently only if pathspecs with wildcards are used.
> 
> Queue *all* directories, no matter if there even are pathspecs present.
> This prevents git archive from writing entries for empty directories in
> all cases.

Nicely explained, and this seems like the right level to be handling it. Simple, and it will catch the cases we know about _and_ and any new ones which pop up.

Show 6 quoted lines
> ---
>  archive.c                       | 19 ++-----------------
>  t/t5001-archive-attr.sh         |  2 +-
>  t/t5002-archive-attr-pattern.sh |  2 +-
>  t/t5004-archive-corner-cases.sh |  4 ++--
>  4 files changed, 6 insertions(+), 21 deletions(-)

I'm not too familiar with this part of the archive code, but it seemed pretty easy to follow. The patch looks good to me.

-Peff
Previous: René ScharfeNext: René Scharfe
Message 13 of 17 in “Bug?: git archive exclude pathspec and gitattributes export-ignore”
  1. David AdamAug 13, 2017
  2. René ScharfeAug 14, 2017
  3. David AdamAug 15, 2017
  4. René ScharfeAug 19, 2017
  5. 1/4 t5001: add tests for export-ignore attributes and exclude pathspecsRené Scharfe, Aug 19, 2017
  6. 2/4 archive: factor out helper functions for handling attributesRené Scharfe, Aug 19, 2017
  7. 4/4 archive: queue directories for all types of pathspecsRené Scharfe, Aug 19, 2017
  8. René ScharfeAug 19, 2017
  9. René ScharfeAug 19, 2017
  10. Junio C HamanoAug 19, 2017
  11. Jeff KingAug 20, 2017
  12. René ScharfeSep 12, 2017
  13. Jeff KingSep 13, 2017
  14. René ScharfeSep 13, 2017
  15. Stefan BellerAug 21, 2017
  16. Junio C HamanoAug 19, 2017
  17. 3/4 archive: don't queue excluded directoriesRené Scharfe, Aug 19, 2017

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.