From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Subject: [PATCH v2 13/21] Convert read_cache_preload() to take struct pathspec Date: Fri, 11 Jan 2013 18:21:07 +0700 Message-ID: <1357903275-16804-14-git-send-email-pclouds@gmail.com> References: <1357903275-16804-1-git-send-email-pclouds@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Junio C Hamano , =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Fri Jan 11 12:22:45 2013 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TtchA-0007Uu-UP for gcvg-git-2@plane.gmane.org; Fri, 11 Jan 2013 12:22:45 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751594Ab3AKLWZ convert rfc822-to-quoted-printable (ORCPT ); Fri, 11 Jan 2013 06:22:25 -0500 Received: from mail-pa0-f47.google.com ([209.85.220.47]:45321 "EHLO mail-pa0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750800Ab3AKLWY (ORCPT ); Fri, 11 Jan 2013 06:22:24 -0500 Received: by mail-pa0-f47.google.com with SMTP id fa10so966381pad.6 for ; Fri, 11 Jan 2013 03:22:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=n9oJO5bwsrAMA5kU7U2B4BPQpumTmbHDpBg4vync4xE=; b=tlJxVCGaXEW4buC4SeX7/XFRQ3o1Lj6BKDMxHx1rnzstJhqTfQdmNwzOmSQji4yMCA p1dXdnE+p/CwoB44/Zzt5n+r62OV6pTzAvsTpBWCYbJZIz5wfbCV8MTEfsKFg0nu4kn9 KKLsivJzLO9fThd9OZ+L3QIfIbLn5AePK4bXBqRgoYnqyskfYH15KEe7DyDD+3jLu0XX BZjEvHZEmPf4eeNl3kdMRyYgOTAjux/1oydo29u3Hm4bC7y/3YTAw8IOBcl5VWjyi+jP 6vXE4NTJbSM1sLMGQBXpQwqJTcM9G+g5FaMvkQYHCUvo7GTOh5rHp90NC+NszcVcHtXV il2g== X-Received: by 10.68.136.132 with SMTP id qa4mr58813257pbb.166.1357903343981; Fri, 11 Jan 2013 03:22:23 -0800 (PST) Received: from lanh ([115.74.46.148]) by mx.google.com with ESMTPS id kp4sm2635234pbc.52.2013.01.11.03.22.20 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 11 Jan 2013 03:22:23 -0800 (PST) Received: by lanh (sSMTP sendmail emulation); Fri, 11 Jan 2013 18:22:38 +0700 X-Mailer: git-send-email 1.8.0.rc2.23.g1fb49df In-Reply-To: <1357903275-16804-1-git-send-email-pclouds@gmail.com> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: Signed-off-by: Nguy=E1=BB=85n Th=C3=A1i Ng=E1=BB=8Dc Duy --- builtin/checkout.c | 2 +- builtin/commit.c | 4 ++-- builtin/diff-files.c | 2 +- builtin/diff-index.c | 2 +- builtin/diff.c | 4 ++-- cache.h | 4 +++- preload-index.c | 20 +++++++++++--------- 7 files changed, 21 insertions(+), 17 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index da25298..00910dc 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -261,7 +261,7 @@ static int checkout_paths(const struct checkout_opt= s *opts, lock_file =3D xcalloc(1, sizeof(struct lock_file)); =20 newfd =3D hold_locked_index(lock_file, 1); - if (read_cache_preload(opts->pathspec.raw) < 0) + if (read_cache_preload(&opts->pathspec) < 0) return error(_("corrupt index file")); =20 if (opts->source_tree) diff --git a/builtin/commit.c b/builtin/commit.c index 196dfab..069d853 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -287,7 +287,7 @@ static char *prepare_index(int argc, const char **a= rgv, const char *prefix, PATHSPEC_EMPTY_MATCH_ALL, prefix, argv); =20 - if (read_cache_preload(pathspec.raw) < 0) + if (read_cache_preload(&pathspec) < 0) die(_("index file corrupt")); =20 if (interactive) { @@ -1209,7 +1209,7 @@ int cmd_status(int argc, const char **argv, const= char *prefix) PATHSPEC_EMPTY_MATCH_ALL, prefix, argv); =20 - read_cache_preload(s.pathspec.raw); + read_cache_preload(&s.pathspec); refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, s.pathspec.= raw, NULL, NULL); =20 fd =3D hold_locked_index(&index_lock, 0); diff --git a/builtin/diff-files.c b/builtin/diff-files.c index 46085f8..9200069 100644 --- a/builtin/diff-files.c +++ b/builtin/diff-files.c @@ -61,7 +61,7 @@ int cmd_diff_files(int argc, const char **argv, const= char *prefix) (rev.diffopt.output_format & DIFF_FORMAT_PATCH)) rev.combine_merges =3D rev.dense_combined_merges =3D 1; =20 - if (read_cache_preload(rev.diffopt.pathspec.raw) < 0) { + if (read_cache_preload(&rev.diffopt.pathspec) < 0) { perror("read_cache_preload"); return -1; } diff --git a/builtin/diff-index.c b/builtin/diff-index.c index 1c737f7..ce15b23 100644 --- a/builtin/diff-index.c +++ b/builtin/diff-index.c @@ -43,7 +43,7 @@ int cmd_diff_index(int argc, const char **argv, const= char *prefix) usage(diff_cache_usage); if (!cached) { setup_work_tree(); - if (read_cache_preload(rev.diffopt.pathspec.raw) < 0) { + if (read_cache_preload(&rev.diffopt.pathspec) < 0) { perror("read_cache_preload"); return -1; } diff --git a/builtin/diff.c b/builtin/diff.c index 8c2af6c..62bdc4d 100644 --- a/builtin/diff.c +++ b/builtin/diff.c @@ -140,7 +140,7 @@ static int builtin_diff_index(struct rev_info *revs= , usage(builtin_diff_usage); if (!cached) { setup_work_tree(); - if (read_cache_preload(revs->diffopt.pathspec.raw) < 0) { + if (read_cache_preload(&revs->diffopt.pathspec) < 0) { perror("read_cache_preload"); return -1; } @@ -240,7 +240,7 @@ static int builtin_diff_files(struct rev_info *revs= , int argc, const char **argv revs->combine_merges =3D revs->dense_combined_merges =3D 1; =20 setup_work_tree(); - if (read_cache_preload(revs->diffopt.pathspec.raw) < 0) { + if (read_cache_preload(&revs->diffopt.pathspec) < 0) { perror("read_cache_preload"); return -1; } diff --git a/cache.h b/cache.h index af96376..c594ded 100644 --- a/cache.h +++ b/cache.h @@ -182,6 +182,8 @@ struct cache_entry { #error "CE_EXTENDED_FLAGS out of range" #endif =20 +struct pathspec; + /* * Copy the sha1 and stat state of a cache entry from one to * another. But we never change the name, or the hash state! @@ -433,7 +435,7 @@ extern int init_db(const char *template_dir, unsign= ed int flags); =20 /* Initialize and use the cache information */ extern int read_index(struct index_state *); -extern int read_index_preload(struct index_state *, const char **paths= pec); +extern int read_index_preload(struct index_state *, const struct paths= pec *pathspec); extern int read_index_from(struct index_state *, const char *path); extern int is_index_unborn(struct index_state *); extern int read_index_unmerged(struct index_state *); diff --git a/preload-index.c b/preload-index.c index 49cb08d..91f27f7 100644 --- a/preload-index.c +++ b/preload-index.c @@ -4,7 +4,8 @@ #include "cache.h" =20 #ifdef NO_PTHREADS -static void preload_index(struct index_state *index, const char **path= spec) +static void preload_index(struct index_state *index, + const struct pathspec *pathspec) { ; /* nothing */ } @@ -24,7 +25,7 @@ static void preload_index(struct index_state *index, = const char **pathspec) struct thread_data { pthread_t pthread; struct index_state *index; - const char **pathspec; + struct pathspec pathspec; int offset, nr; }; =20 @@ -35,9 +36,7 @@ static void *preload_thread(void *_data) struct index_state *index =3D p->index; struct cache_entry **cep =3D index->cache + p->offset; struct cache_def cache; - struct pathspec pathspec; =20 - init_pathspec(&pathspec, p->pathspec); memset(&cache, 0, sizeof(cache)); nr =3D p->nr; if (nr + p->offset > index->cache_nr) @@ -53,7 +52,7 @@ static void *preload_thread(void *_data) continue; if (ce_uptodate(ce)) continue; - if (!ce_path_match(ce, &pathspec)) + if (!ce_path_match(ce, &p->pathspec)) continue; if (threaded_has_symlink_leading_path(&cache, ce->name, ce_namelen(c= e))) continue; @@ -63,11 +62,11 @@ static void *preload_thread(void *_data) continue; ce_mark_uptodate(ce); } while (--nr > 0); - free_pathspec(&pathspec); return NULL; } =20 -static void preload_index(struct index_state *index, const char **path= spec) +static void preload_index(struct index_state *index, + const struct pathspec *pathspec) { int threads, i, work, offset; struct thread_data data[MAX_PARALLEL]; @@ -82,10 +81,12 @@ static void preload_index(struct index_state *index= , const char **pathspec) threads =3D MAX_PARALLEL; offset =3D 0; work =3D DIV_ROUND_UP(index->cache_nr, threads); + memset(&data, 0, sizeof(data)); for (i =3D 0; i < threads; i++) { struct thread_data *p =3D data+i; p->index =3D index; - p->pathspec =3D pathspec; + if (pathspec) + p->pathspec =3D *pathspec; p->offset =3D offset; p->nr =3D work; offset +=3D work; @@ -100,7 +101,8 @@ static void preload_index(struct index_state *index= , const char **pathspec) } #endif =20 -int read_index_preload(struct index_state *index, const char **pathspe= c) +int read_index_preload(struct index_state *index, + const struct pathspec *pathspec) { int retval =3D read_index(index); =20 --=20 1.8.0.rc2.23.g1fb49df