From: Duy Nguyen <pclouds@gmail.com>
To: Graeme Geldenhuys <mailinglists@geldenhuys.co.uk>
Cc: git@vger.kernel.org
Subject: Re: Git archiving only branch work
Date: Thu, 13 Nov 2014 20:36:16 +0700 [thread overview]
Message-ID: <20141113133615.GA28346@lanh> (raw)
In-Reply-To: <5464a4e8.4a0.2bfa0e00.3067f800@geldenhuys.co.uk>
On Thu, Nov 13, 2014 at 12:32:40PM +0000, Graeme Geldenhuys wrote:
> [alias]
> deploy = !sh -c 'git archive --prefix=$1/ -o deploy_$1.zip HEAD
> $(git diff --name-only -D $2)' -
>
> This works very well. The only problem we have so far is that if we
> have files with spaces in the name (eg: SQL update scripts), then the
> command breaks.
>
> Does anybody have an idea on how this can be resolved? Any help would
> be much appreciated.
I wonder if it's overkill to do something like this patch ("git
archive" may need some more updates for it to work though). With it
you can do:
git diff --name-only ... | git archive ... HEAD -- ":(file)-"
The good thing is it works for other commands as well. But is it
really a good thing..
-- 8<--
Subject: [PATCH] pathspec: support :(file)
This pathspec magic must be used alone. It reads the actual pathspec
from a given file whose path is specified after :(file). E.g.
git ls-files :(file)foo
list files specified by pathspec in file "foo". Reading from stdin is
possible to:
git ls-fiels :(file)-
TODO: specify line terminator..
---
pathspec.c | 38 ++++++++++++++++++++++++++++++++++++++
pathspec.h | 4 +++-
2 files changed, 41 insertions(+), 1 deletion(-)
diff --git a/pathspec.c b/pathspec.c
index 9304ee3..ba34f9b 100644
--- a/pathspec.c
+++ b/pathspec.c
@@ -1,6 +1,7 @@
#include "cache.h"
#include "dir.h"
#include "pathspec.h"
+#include "argv-array.h"
/*
* Finds which of the given pathspecs match items in the index.
@@ -72,6 +73,7 @@ static struct pathspec_magic {
{ PATHSPEC_GLOB, '\0', "glob" },
{ PATHSPEC_ICASE, '\0', "icase" },
{ PATHSPEC_EXCLUDE, '!', "exclude" },
+ { PATHSPEC_FROMFILE, 0, "file" },
};
static void prefix_short_magic(struct strbuf *sb, int prefixlen,
@@ -235,6 +237,9 @@ static unsigned prefix_pathspec(struct pathspec_item *item,
} else if (magic & PATHSPEC_FROMTOP) {
match = xstrdup(copyfrom);
prefixlen = 0;
+ } else if ((magic & PATHSPEC_FROMFILE) && !strcmp(copyfrom, "-")) {
+ match = xstrdup(copyfrom);
+ prefixlen = 0;
} else {
match = prefix_path_gently(prefix, prefixlen, &prefixlen, copyfrom);
if (!match)
@@ -354,6 +359,31 @@ static void NORETURN unsupported_magic(const char *pattern,
pattern, sb.buf);
}
+static void pathspec_fromfile(struct pathspec *pathspec,
+ unsigned magic_mask, unsigned flags,
+ const char *prefix, const char *path)
+{
+ struct strbuf buf, nbuf;
+ int line_termination = '\n'; /* FIXME: support :(file:<line terminator>) */
+ struct argv_array av = ARGV_ARRAY_INIT;
+ FILE *fp = !strcmp(path, "-") ? stdin : fopen(path, "r");
+
+ if (!fp)
+ die_errno(_("fail to open %s"), path);
+
+ strbuf_init(&buf, 0);
+ strbuf_init(&nbuf, 0);
+ while (strbuf_getline(&buf, fp, line_termination) != EOF)
+ argv_array_push(&av, buf.buf);
+ strbuf_release(&buf);
+ strbuf_release(&nbuf);
+ if (fp != stdin)
+ fclose(fp);
+ parse_pathspec(pathspec, magic_mask | PATHSPEC_FROMFILE,
+ flags, prefix, av.argv);
+ /* cannot free av because pathspec keeps references to it */
+}
+
/*
* Given command line arguments and a prefix, convert the input to
* pathspec. die() if any magic in magic_mask is used.
@@ -427,6 +457,14 @@ void parse_pathspec(struct pathspec *pathspec,
item[i].magic & magic_mask,
short_magic);
+ if (item[i].magic & PATHSPEC_FROMFILE) {
+ if (n != 1)
+ die(_(":(file) can only be used alone"));
+ pathspec_fromfile(pathspec,
+ magic_mask | PATHSPEC_FROMFILE,
+ flags, prefix, item[i].match);
+ return;
+ }
if ((flags & PATHSPEC_SYMLINK_LEADING_PATH) &&
has_symlink_leading_path(item[i].match, item[i].len)) {
die(_("pathspec '%s' is beyond a symbolic link"), entry);
diff --git a/pathspec.h b/pathspec.h
index 0c11262..84de102 100644
--- a/pathspec.h
+++ b/pathspec.h
@@ -8,13 +8,15 @@
#define PATHSPEC_GLOB (1<<3)
#define PATHSPEC_ICASE (1<<4)
#define PATHSPEC_EXCLUDE (1<<5)
+#define PATHSPEC_FROMFILE (1<<6)
#define PATHSPEC_ALL_MAGIC \
(PATHSPEC_FROMTOP | \
PATHSPEC_MAXDEPTH | \
PATHSPEC_LITERAL | \
PATHSPEC_GLOB | \
PATHSPEC_ICASE | \
- PATHSPEC_EXCLUDE)
+ PATHSPEC_EXCLUDE | \
+ PATHSPEC_FROMFILE)
#define PATHSPEC_ONESTAR 1 /* the pathspec pattern satisfies GFNM_ONESTAR */
--
2.1.0.rc0.78.gc0d8480
-- 8< --
next prev parent reply other threads:[~2014-11-13 13:36 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-13 12:32 Git archiving only branch work Graeme Geldenhuys
2014-11-13 13:19 ` Peter Krefting
2014-11-13 13:36 ` Duy Nguyen [this message]
2014-11-13 16:49 ` Junio C Hamano
2014-11-13 20:06 ` Jeff King
2014-11-13 21:10 ` Junio C Hamano
2014-11-13 21:33 ` Jeff King
2014-11-13 21:36 ` Junio C Hamano
2014-11-13 21:39 ` Jeff King
2014-11-13 21:48 ` Junio C Hamano
2014-11-14 15:32 ` Jeff King
2014-11-14 20:35 ` Junio C Hamano
2014-11-13 16:10 ` Thomas Koch
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=20141113133615.GA28346@lanh \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=mailinglists@geldenhuys.co.uk \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).