From: Nguyen Thai Ngoc Duy <pclouds@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 4/5] archive: do not read .gitattributes in working directory
Date: Thu, 16 Apr 2009 20:50:05 +1000 [thread overview]
Message-ID: <fcaeb9bf0904160350m14dce828oe88bda6562d98f48@mail.gmail.com> (raw)
In-Reply-To: <1239848917-14399-5-git-send-email-gitster@pobox.com>
[-- Attachment #1: Type: text/plain, Size: 2454 bytes --]
Sorry I got distracted by Vista+x11 stuff and had not work on this.
2009/4/16 Junio C Hamano <gitster@pobox.com>:
> @@ -168,6 +171,22 @@ int write_archive_entries(struct archiver_args *args,
> context.args = args;
> context.write_entry = write_entry;
>
> + /*
> + * Setup index and instruct attr to read index only
> + */
> + if (!args->worktree_attributes) {
> + memset(&opts, 0, sizeof(opts));
> + opts.index_only = 1;
> + opts.head_idx = -1;
> + opts.src_index = &the_index;
> + opts.dst_index = &the_index;
> + opts.fn = oneway_merge;
> + init_tree_desc(&t, args->tree->buffer, args->tree->size);
> + if (unpack_trees(1, &t, &opts))
> + return -1;
> + git_attr_set_direction(GIT_ATTR_INDEX, &the_index);
> + }
> +
> err = read_tree_recursive(args->tree, args->base, args->baselen, 0,
> args->pathspec, write_archive_entry, &context);
> if (err == READ_TREE_RECURSIVE)
Squash the attached patch on top of this patch (I have yet to install
mutt), we may avoid a few possible lstat()s during unpack_trees(),
also less memory allocation.
I was thinking about loading .gitattributes inside write_archive_entry
too, to avoid calling read_tree_recursive twice, but it requires
.gitattributes to be traversed first. Won't work if there are files
.abc, .def...
If read_tree_recusive() expose its tree to read_tree_fn_t, we can then
look ahead and load .gitattributes, but that requires changing
read_tree_fn_t interface. I'll see if it's feasible to make a
customized read_tree_recusive() just for archive.c
Oh and a feature request (not really because I don't use it myself):
support submodules in "git archive", anyone?
> @@ -36,6 +36,14 @@ int cmd_tar_tree(int argc, const char **argv, const char *prefix)
> argv++;
> argc--;
> }
> + if (2 <= argc && !strcmp(argv[1], "--fix-attributes")) {
> + argv++;
> + argc--;
> + }
Does this part needed? Gotta fix tar_tree_usage and git-tar-tree.txt
too. I'd vote remove it.
--
Duy
[-- Attachment #2: attr-1.patch --]
[-- Type: text/x-patch, Size: 1927 bytes --]
diff --git a/archive.c b/archive.c
index 0ce628b..f79d005 100644
--- a/archive.c
+++ b/archive.c
@@ -147,12 +147,34 @@ static int write_archive_entry(const unsigned char *sha1, const char *base,
return err;
}
+static int read_gitattr_to_index(const unsigned char *sha1, const char *base, int baselen, const char *pathname, unsigned mode, int stage, void *context)
+{
+ struct cache_entry *ce;
+ unsigned int size;
+ int len;
+ static int gitattr_len = 0;
+
+ if (S_ISDIR(mode))
+ return READ_TREE_RECURSIVE;
+
+ len = strlen(pathname);
+ if (!gitattr_len)
+ gitattr_len = strlen(GITATTRIBUTES_FILE);
+ if (len < gitattr_len || strcmp(pathname+len-gitattr_len, GITATTRIBUTES_FILE))
+ return 0;
+ size = cache_entry_size(len);
+ ce = xcalloc(1, size);
+ ce->ce_mode = create_ce_mode(mode);
+ ce->ce_flags = create_ce_flags(len, stage);
+ memcpy(ce->name, pathname, len+1);
+ hashcpy(ce->sha1, sha1);
+ return add_cache_entry(ce, ADD_CACHE_OK_TO_ADD | ADD_CACHE_SKIP_DFCHECK);
+}
+
int write_archive_entries(struct archiver_args *args,
write_archive_entry_fn_t write_entry)
{
struct archiver_context context;
- struct unpack_trees_options opts;
- struct tree_desc t;
int err;
if (args->baselen > 0 && args->base[args->baselen - 1] == '/') {
@@ -170,20 +192,8 @@ int write_archive_entries(struct archiver_args *args,
context.args = args;
context.write_entry = write_entry;
-
- /*
- * Setup index and instruct attr to read index only
- */
if (!args->worktree_attributes) {
- memset(&opts, 0, sizeof(opts));
- opts.index_only = 1;
- opts.head_idx = -1;
- opts.src_index = &the_index;
- opts.dst_index = &the_index;
- opts.fn = oneway_merge;
- init_tree_desc(&t, args->tree->buffer, args->tree->size);
- if (unpack_trees(1, &t, &opts))
- return -1;
+ read_tree_recursive(args->tree, NULL, 0, 0, NULL, read_gitattr_to_index, NULL);
git_attr_set_direction(GIT_ATTR_INDEX, &the_index);
}
next prev parent reply other threads:[~2009-04-16 10:51 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-16 2:28 [PATCH 0/5] archive attribute series Junio C Hamano
2009-04-16 2:28 ` [PATCH 1/5] archive tests: do not use .gitattributes in working directory Junio C Hamano
2009-04-16 2:28 ` [PATCH 2/5] attr: add GIT_ATTR_INDEX "direction" Junio C Hamano
2009-04-16 2:28 ` [PATCH 3/5] unpack-trees: do not muck with attributes when we are not checking out Junio C Hamano
2009-04-16 2:28 ` [PATCH 4/5] archive: do not read .gitattributes in working directory Junio C Hamano
2009-04-16 2:28 ` [PATCH 5/5] archive test: test new --fix-attributes feature Junio C Hamano
2009-04-17 19:53 ` René Scharfe
2009-04-16 5:17 ` [PATCH 4/5] archive: do not read .gitattributes in working directory Junio C Hamano
2009-04-16 7:06 ` Jeff King
2009-04-16 7:29 ` Jakub Narebski
2009-04-16 10:50 ` Nguyen Thai Ngoc Duy [this message]
2009-04-16 12:38 ` Nguyen Thai Ngoc Duy
2009-04-17 20:33 ` [PATCH 2/5] attr: add GIT_ATTR_INDEX "direction" René Scharfe
2009-04-17 19:51 ` [PATCH 1/5] archive tests: do not use .gitattributes in working directory René Scharfe
2009-04-17 22:17 ` [PATCH v2 " René Scharfe
2009-04-17 22:17 ` [PATCH v2 2/5] attr: add GIT_ATTR_INDEX "direction" René Scharfe
2009-04-17 22:18 ` [PATCH v2 3/5] unpack-trees: do not muck with attributes when we are not checking out René Scharfe
2009-04-17 22:18 ` [PATCH v2 4/5] archive: do not read .gitattributes in working directory René Scharfe
2009-04-17 22:18 ` [PATCH v2 5/5] archive test: attributes René Scharfe
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=fcaeb9bf0904160350m14dce828oe88bda6562d98f48@mail.gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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 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).