Subject: Re: [PATCH 4/8] archive: add tests for directory selection

From: René Scharfe <[email-masked]>
Date: Wed, 08 Apr 2009 21:52:07 +0200

Nguyễn Thái Ngọc Duy schrieb:
> While in archive.c, it says "pathspec". It's not really pathspec.
> Make a few tests to catch this point.
> 
> Signed-off-by: Nguyễn Thái Ngọc Duy <[email-masked]>
> ---
>  archive.c               |   17 +++++++++++++++++
>  t/t0024-crlf-archive.sh |   30 +++++++++++++++++++++++++++++-
>  2 files changed, 46 insertions(+), 1 deletions(-)
> 
> diff --git a/archive.c b/archive.c
> index e87fed7..5b54d95 100644
> --- a/archive.c
> +++ b/archive.c
> @@ -15,6 +15,8 @@ static char const * const archive_usage[] = {
>  
>  #define USES_ZLIB_COMPRESSION 1
>  
> +static int list_archive(struct archiver_args *args);
> +
>  static const struct archiver {
>  	const char *name;
>  	write_archive_fn_t write_archive;
> @@ -22,8 +24,23 @@ static const struct archiver {
>  } archivers[] = {
>  	{ "tar", write_tar_archive },
>  	{ "zip", write_zip_archive, USES_ZLIB_COMPRESSION },
> +	{ "dump-file-list", list_archive },
>  };
>  
> +static int list_archive_entry(struct archiver_args *args,
> +		const unsigned char *sha1, const char *path, size_t pathlen,
> +		unsigned int mode, void *buffer, unsigned long size)
> +{
> +	printf("%s\n", path);
> +	return 0;
> +}

git archive dumps all its output, so I think "file-list" would be a
better name for an archiver creating lists of files.

However, if you only need it for tests (I can't imagine other uses at
the moment), you could do something like this instead:

	$ git archive -v HEAD >/dev/null 2>file-list

It might be wasteful since it creates a full archive (including file
contents) and throws it away, but it's OK for testing purposes.

René