git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH 5/6] unpack-trees.c: use path_excluded() in check_ok_to_remove()
Date: Tue,  5 Jun 2012 22:45:18 -0700	[thread overview]
Message-ID: <1338961519-30970-6-git-send-email-gitster@pobox.com> (raw)
In-Reply-To: <1338961519-30970-1-git-send-email-gitster@pobox.com>

This function is responsible for determining if a path that is not
tracked is ignored and allow "checkout" to overwrite it as needed.
It used excluded() without checking if higher level directory in the
path is ignored; correct it to use path_excluded() for this check.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---

 * There are uses of lower-level interface excluded_from_list() in
   the codepath for narrow-checkout hack; they are supposed to be
   already checking each level as they descend, and are not touched
   with this patch.
---
 unpack-trees.c | 11 ++++++++++-
 unpack-trees.h |  1 +
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/unpack-trees.c b/unpack-trees.c
index 7c9ecf6..133f2c9 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1016,6 +1016,10 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
 			o->el = &el;
 	}
 
+	if (o->dir) {
+		o->path_exclude_check = xmalloc(sizeof(struct path_exclude_check));
+		path_exclude_check_init(o->path_exclude_check, o->dir);
+	}
 	memset(&o->result, 0, sizeof(o->result));
 	o->result.initialized = 1;
 	o->result.timestamp.sec = o->src_index->timestamp.sec;
@@ -1140,6 +1144,10 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
 
 done:
 	free_excludes(&el);
+	if (o->path_exclude_check) {
+		path_exclude_check_clear(o->path_exclude_check);
+		free(o->path_exclude_check);
+	}
 	return ret;
 
 return_failed:
@@ -1355,7 +1363,8 @@ static int check_ok_to_remove(const char *name, int len, int dtype,
 	if (ignore_case && icase_exists(o, name, len, st))
 		return 0;
 
-	if (o->dir && excluded(o->dir, name, &dtype))
+	if (o->dir &&
+	    path_excluded(o->path_exclude_check, name, -1, &dtype))
 		/*
 		 * ce->name is explicitly excluded, so it is Ok to
 		 * overwrite it.
diff --git a/unpack-trees.h b/unpack-trees.h
index 5e432f5..ec74a9f 100644
--- a/unpack-trees.h
+++ b/unpack-trees.h
@@ -52,6 +52,7 @@ struct unpack_trees_options {
 	const char *prefix;
 	int cache_bottom;
 	struct dir_struct *dir;
+	struct path_exclude_check *path_exclude_check;
 	struct pathspec *pathspec;
 	merge_fn_t fn;
 	const char *msgs[NB_UNPACK_TREES_ERROR_TYPES];
-- 
1.7.11.rc1.37.g09843ac

  parent reply	other threads:[~2012-06-06  5:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-06  5:45 [PATCH 0/6] "ls-files -i" not honoring directory wide ignore Junio C Hamano
2012-06-06  5:45 ` [PATCH 1/6] ls-files -i: pay attention to exclusion of leading paths Junio C Hamano
2012-06-06  5:45 ` [PATCH 2/6] ls-files -i: micro-optimize path_excluded() Junio C Hamano
2012-06-06  5:45 ` [PATCH 3/6] path_excluded(): update API to less cache-entry centric Junio C Hamano
2012-06-06  5:45 ` [PATCH 4/6] builtin/add.c: use path_excluded() Junio C Hamano
2012-06-06  5:45 ` Junio C Hamano [this message]
2012-06-06  5:45 ` [PATCH 6/6] dir.c: make excluded() file scope static 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=1338961519-30970-6-git-send-email-gitster@pobox.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    /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).