All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Wu <peter@lekensteyn.nl>
To: Duy Nguyen <pclouds@gmail.com>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: git archive and glob pathspecs
Date: Sat, 13 Sep 2014 12:36:03 +0200	[thread overview]
Message-ID: <6687757.cFzdCVORFi@al> (raw)
In-Reply-To: <CACsJy8BZBe1XV-uM8VHeGcDntn6vqJrNsWi6wTdQ1+fWAAsGFg@mail.gmail.com>

On Wednesday 03 September 2014 13:21:06 Duy Nguyen wrote:
> On Wed, Sep 3, 2014 at 5:17 AM, Peter Wu <peter@lekensteyn.nl> wrote:
> > Hi,
> >
> > The `git archive` seems to accept a pathspec judging from the error message (git
> > version 2.1.0):
> >
> >     git archive HEAD -- :x
> >     fatal: pathspec 'x' did not match any files
> >
> > When I try to use deeper glob specs however, it throws an error (this also
> > happens if I use `:(glob)**/Makefile`, tested in the git source tree):
> >
> >     $ git archive HEAD -- ':(glob)*/Makefile'
> >     fatal: pathspec '*/Makefile' did not match any files
> >
> > Strange enough, command `git log -- ':(glob)*/Makefile'` works. Any idea what is
> > wrong?
> 
> There may be something wrong. This patch seems to make it work for me,
> but it includes lots of empty directories. I'll have a closer look
> later (btw it's surprising that negative pathspec works too..)

I can confirm that this patch shows Makefile's, but also includes a lot of empty
directories.

As for why this happens, my guess is that write_archive_entries() recurses the
full tree and adds every encountered directory (via read_tree_1, via
write_archive_entry()).

To fix this, write_archive (write_tar_archive, etc.) should be taught to handle
glob patterns, or parse_pathspec should expand globs (and then
parse_pathspec_arg might have to validate the remaining patterns).

Kind regards,
Peter

> diff --git a/archive.c b/archive.c
> index 3fc0fb2..a5be58d 100644
> --- a/archive.c
> +++ b/archive.c
> @@ -221,6 +221,7 @@ static int path_exists(struct tree *tree, const char *path)
>   int ret;
> 
>   parse_pathspec(&pathspec, 0, 0, "", paths);
> + pathspec.recursive = 1;
>   ret = read_tree_recursive(tree, "", 0, 0, &pathspec, reject_entry, NULL);
>   free_pathspec(&pathspec);
>   return ret != 0;
> @@ -237,6 +238,7 @@ static void parse_pathspec_arg(const char **pathspec,
>   parse_pathspec(&ar_args->pathspec, 0,
>         PATHSPEC_PREFER_FULL,
>         "", pathspec);
> + ar_args->pathspec.recursive = 1;
>   if (pathspec) {
>   while (*pathspec) {
>   if (**pathspec && !path_exists(ar_args->tree, *pathspec))

  reply	other threads:[~2014-09-13 10:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-02 22:17 git archive and glob pathspecs Peter Wu
2014-09-03  6:21 ` Duy Nguyen
2014-09-13 10:36   ` Peter Wu [this message]
2014-09-04 13:37 ` [PATCH] archive: support filtering paths with glob Nguyễn Thái Ngọc Duy
2014-09-13 10:52   ` Peter Wu
2014-09-21  3:55     ` [PATCH v2] " Nguyễn Thái Ngọc Duy
2014-09-22 19:15       ` Junio C Hamano
2014-09-22 23:04         ` Duy Nguyen
2014-09-23 16:57           ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6687757.cFzdCVORFi@al \
    --to=peter@lekensteyn.nl \
    --cc=git@vger.kernel.org \
    --cc=pclouds@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.