git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
	Michael J Gruber <git@drmicha.warpmail.net>
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 3/5] Convert prefix_pathspec() to produce struct pathspec_item
Date: Sat,  9 Apr 2011 23:54:18 +0700	[thread overview]
Message-ID: <1302368060-23827-4-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1302368060-23827-1-git-send-email-pclouds@gmail.com>

New field plain_len is used to mark the first part of 'match' where no
magic can be applied.
---
 cache.h |    1 +
 setup.c |   26 ++++++++++++++++++--------
 2 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/cache.h b/cache.h
index da1a46c..08b4633 100644
--- a/cache.h
+++ b/cache.h
@@ -528,6 +528,7 @@ struct pathspec {
 	struct pathspec_item {
 		const char *match;
 		int len;
+		int plain_len;	/* match[0..plain_len-1] does not have any kind of magic*/
 		unsigned magic;
 	} *items;
 };
diff --git a/setup.c b/setup.c
index 1e7dfb1..8a4a9d0 100644
--- a/setup.c
+++ b/setup.c
@@ -148,11 +148,12 @@ struct pathspec_magic {
  * the prefix part must always match literally, and a single stupid
  * string cannot express such a case.
  */
-const char *prefix_pathspec(const char *prefix, int prefixlen, const char *elt)
+int prefix_pathspec(struct pathspec_item *item,
+		    const char *prefix, int prefixlen,
+		    const char *elt)
 {
 	unsigned magic = 0;
 	const char *copyfrom = elt;
-	const char *retval;
 	int i, free_source = 0;
 
 	if (elt[0] != ':') {
@@ -184,7 +185,8 @@ const char *prefix_pathspec(const char *prefix, int prefixlen, const char *elt)
 			copyfrom++;
 	} else if (!elt[1]) {
 		/* Just ':' -- no element! */
-		return NULL;
+		memset(item, 0, sizeof(*item));
+		return -1;
 	} else {
 		/* shorthand */
 		for (copyfrom = elt + 1;
@@ -225,13 +227,19 @@ const char *prefix_pathspec(const char *prefix, int prefixlen, const char *elt)
 		}
 	}
 
+	memset(item, 0, sizeof(*item));
+	item->magic = magic;
+
 	if (magic & PATHSPEC_FROMTOP)
-		retval = xstrdup(copyfrom);
-	else
-		retval = prefix_path(prefix, prefixlen, copyfrom);
+		item->match = xstrdup(copyfrom);
+	else {
+		item->match = prefix_path(prefix, prefixlen, copyfrom);
+		item->plain_len = prefixlen;
+	}
+	item->len = strlen(item->match);
 	if (free_source)
 		free((char *)copyfrom);
-	return retval;
+	return 0;
 }
 
 const char **get_pathspec_old(const char *prefix, const char **pathspec)
@@ -255,7 +263,9 @@ const char **get_pathspec_old(const char *prefix, const char **pathspec)
 	dst = pathspec;
 	prefixlen = prefix ? strlen(prefix) : 0;
 	while (*src) {
-		*(dst++) = prefix_pathspec(prefix, prefixlen, *src);
+		struct pathspec_item item;
+		prefix_pathspec(&item, prefix, prefixlen, *src);
+		*(dst++) = item.match;
 		src++;
 	}
 	*dst = NULL;
-- 
1.7.4.74.g639db

  parent reply	other threads:[~2011-04-09 16:55 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-09 16:54 [PATCH 0/5] New get_pathspec() Nguyễn Thái Ngọc Duy
2011-04-09 16:54 ` [PATCH 1/5] Rename functions in preparation for get_pathspec() restructure Nguyễn Thái Ngọc Duy
2011-04-09 16:54 ` [PATCH 2/5] Replace has_wildcard with PATHSPEC_NOGLOB Nguyễn Thái Ngọc Duy
2011-04-10  0:49   ` Junio C Hamano
2011-04-10  7:23     ` Nguyen Thai Ngoc Duy
2011-04-09 16:54 ` Nguyễn Thái Ngọc Duy [this message]
2011-04-09 16:54 ` [PATCH 4/5] Implement new get_pathspec() Nguyễn Thái Ngọc Duy
2011-04-09 16:54 ` [PATCH 5/5] grep: convert to use the " Nguyễn Thái Ngọc Duy
2011-04-10  0:56   ` Junio C Hamano
2011-04-10  7:26     ` Nguyen Thai Ngoc Duy
2011-04-09 21:41 ` [PATCH 0/5] New get_pathspec() 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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=1302368060-23827-4-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@drmicha.warpmail.net \
    --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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).