Re: [PATCH v2 7/8] name-hash: allow dir hashing even when !ignore_case

2014-09-06 Thread Thomas Rast
Eric Sunshine sunsh...@sunshineco.com writes:

 On Sat, Feb 22, 2014 at 4:17 AM, Thomas Rast t...@thomasrast.ch wrote:
 -static void lazy_init_name_hash(struct index_state *istate)
 +void init_name_hash(struct index_state *istate, int force_dir_hash)
  {
 int nr;

 if (istate-name_hash_initialized)
 return;
 +
 +   istate-has_dir_hash = force_dir_hash || ignore_case;

 This is getting a bit convoluted. Refactoring lazy_init_name_hash()
 into two functions would eliminate the complexity. For instance:

   void init_name_hash(struct index_state *istate)
   {
   ...pure initialization code...
   }

   static void init_name_hash_if_needed(struct index_state *istate)
   {
 if (ignore_case  !istate-name_hash_initialized)
   init_name_hash(istate);
   }

 The two existing callers of lazy_init_name_hash() in name-hash.c,
 which rely upon the lazy/ignore-case logic, would invoke the static
 init_name_hash_if_needed().

 The new caller in patch 8/8, which knows explicitly if and when it
 wants the hash initialized can invoke the public init_name_hash().

That unfortunately doesn't really help because the conditional part only
affects the dir hash.  Callers request the name hash for other reasons,
but we only do the dir hashing when ignore_case is in effect.

So it's not simply about overriding lazy initialization, but about
choosing to trigger a specific subpart of the initialization.

-- 
Thomas Rast
t...@thomasrast.ch
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 7/8] name-hash: allow dir hashing even when !ignore_case

2014-02-27 Thread Junio C Hamano
Thomas Rast t...@thomasrast.ch writes:

 The directory hash (for fast checks if the index already has a
 directory) was only used in ignore_case mode and so depended on that
 flag.

 Make it generally available on request.

 Signed-off-by: Thomas Rast t...@thomasrast.ch
 ---

I somehow had an impression that we were getting rid of these two
hashes and merging them into one, but I do not see any such change
between 'master..pu'.  Perhaps I am confused with some other topic.

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2 7/8] name-hash: allow dir hashing even when !ignore_case

2014-02-23 Thread Eric Sunshine
On Sat, Feb 22, 2014 at 4:17 AM, Thomas Rast t...@thomasrast.ch wrote:
 The directory hash (for fast checks if the index already has a
 directory) was only used in ignore_case mode and so depended on that
 flag.

 Make it generally available on request.

 Signed-off-by: Thomas Rast t...@thomasrast.ch
 ---
 diff --git a/name-hash.c b/name-hash.c
 index e5b6e1a..c8953be 100644
 --- a/name-hash.c
 +++ b/name-hash.c
 @@ -141,16 +141,19 @@ static void hash_index_entry(struct index_state 
 *istate, struct cache_entry *ce)
 *pos = ce;
 }

 -   if (ignore_case  !(ce-ce_flags  CE_UNHASHED))
 +   if (istate-has_dir_hash  !(ce-ce_flags  CE_UNHASHED))
 add_dir_entry(istate, ce);
  }

 -static void lazy_init_name_hash(struct index_state *istate)
 +void init_name_hash(struct index_state *istate, int force_dir_hash)
  {
 int nr;

 if (istate-name_hash_initialized)
 return;
 +
 +   istate-has_dir_hash = force_dir_hash || ignore_case;

This is getting a bit convoluted. Refactoring lazy_init_name_hash()
into two functions would eliminate the complexity. For instance:

  void init_name_hash(struct index_state *istate)
  {
  ...pure initialization code...
  }

  static void init_name_hash_if_needed(struct index_state *istate)
  {
if (ignore_case  !istate-name_hash_initialized)
  init_name_hash(istate);
  }

The two existing callers of lazy_init_name_hash() in name-hash.c,
which rely upon the lazy/ignore-case logic, would invoke the static
init_name_hash_if_needed().

The new caller in patch 8/8, which knows explicitly if and when it
wants the hash initialized can invoke the public init_name_hash().

 if (istate-cache_nr)
 preallocate_hash(istate-name_hash, istate-cache_nr);
 for (nr = 0; nr  istate-cache_nr; nr++)
 @@ -161,7 +164,7 @@ static void lazy_init_name_hash(struct index_state 
 *istate)
  void add_name_hash(struct index_state *istate, struct cache_entry *ce)
  {
 /* if already hashed, add reference to directory entries */
 -   if (ignore_case  (ce-ce_flags  CE_STATE_MASK) == CE_STATE_MASK)
 +   if (istate-has_dir_hash  (ce-ce_flags  CE_STATE_MASK) == 
 CE_STATE_MASK)
 add_dir_entry(istate, ce);

 ce-ce_flags = ~CE_UNHASHED;
 @@ -181,7 +184,7 @@ void add_name_hash(struct index_state *istate, struct 
 cache_entry *ce)
  void remove_name_hash(struct index_state *istate, struct cache_entry *ce)
  {
 /* if already hashed, release reference to directory entries */
 -   if (ignore_case  (ce-ce_flags  CE_STATE_MASK) == CE_HASHED)
 +   if (istate-has_dir_hash  (ce-ce_flags  CE_STATE_MASK) == 
 CE_HASHED)
 remove_dir_entry(istate, ce);

 ce-ce_flags |= CE_UNHASHED;
 @@ -228,7 +231,7 @@ struct cache_entry *index_dir_exists(struct index_state 
 *istate, const char *nam
 struct cache_entry *ce;
 struct dir_entry *dir;

 -   lazy_init_name_hash(istate);
 +   init_name_hash(istate, 0);
 dir = find_dir_entry(istate, name, namelen);
 if (dir  dir-nr)
 return dir-ce;
 @@ -250,7 +253,7 @@ struct cache_entry *index_file_exists(struct index_state 
 *istate, const char *na
 unsigned int hash = hash_name(name, namelen);
 struct cache_entry *ce;

 -   lazy_init_name_hash(istate);
 +   init_name_hash(istate, 0);
 ce = lookup_hash(hash, istate-name_hash);

 while (ce) {
 @@ -286,9 +289,11 @@ void free_name_hash(struct index_state *istate)
 if (!istate-name_hash_initialized)
 return;
 istate-name_hash_initialized = 0;
 -   if (ignore_case)
 +   if (istate-has_dir_hash) {
 /* free directory entries */
 for_each_hash(istate-dir_hash, free_dir_entry, NULL);
 +   istate-has_dir_hash = 0;
 +   }

 free_hash(istate-name_hash);
 free_hash(istate-dir_hash);
 --
 1.9.0.313.g3d0a325
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 7/8] name-hash: allow dir hashing even when !ignore_case

2014-02-22 Thread Thomas Rast
The directory hash (for fast checks if the index already has a
directory) was only used in ignore_case mode and so depended on that
flag.

Make it generally available on request.

Signed-off-by: Thomas Rast t...@thomasrast.ch
---
 cache.h |  2 ++
 name-hash.c | 19 ---
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/cache.h b/cache.h
index dc040fb..e162021 100644
--- a/cache.h
+++ b/cache.h
@@ -276,6 +276,7 @@ struct index_state {
struct cache_tree *cache_tree;
struct cache_time timestamp;
unsigned name_hash_initialized : 1,
+has_dir_hash : 1,
 initialized : 1;
struct hash_table name_hash;
struct hash_table dir_hash;
@@ -284,6 +285,7 @@ struct index_state {
 extern struct index_state the_index;
 
 /* Name hashing */
+extern void init_name_hash(struct index_state *istate, int force_dir_hash);
 extern void add_name_hash(struct index_state *istate, struct cache_entry *ce);
 extern void remove_name_hash(struct index_state *istate, struct cache_entry 
*ce);
 extern void free_name_hash(struct index_state *istate);
diff --git a/name-hash.c b/name-hash.c
index e5b6e1a..c8953be 100644
--- a/name-hash.c
+++ b/name-hash.c
@@ -141,16 +141,19 @@ static void hash_index_entry(struct index_state *istate, 
struct cache_entry *ce)
*pos = ce;
}
 
-   if (ignore_case  !(ce-ce_flags  CE_UNHASHED))
+   if (istate-has_dir_hash  !(ce-ce_flags  CE_UNHASHED))
add_dir_entry(istate, ce);
 }
 
-static void lazy_init_name_hash(struct index_state *istate)
+void init_name_hash(struct index_state *istate, int force_dir_hash)
 {
int nr;
 
if (istate-name_hash_initialized)
return;
+
+   istate-has_dir_hash = force_dir_hash || ignore_case;
+
if (istate-cache_nr)
preallocate_hash(istate-name_hash, istate-cache_nr);
for (nr = 0; nr  istate-cache_nr; nr++)
@@ -161,7 +164,7 @@ static void lazy_init_name_hash(struct index_state *istate)
 void add_name_hash(struct index_state *istate, struct cache_entry *ce)
 {
/* if already hashed, add reference to directory entries */
-   if (ignore_case  (ce-ce_flags  CE_STATE_MASK) == CE_STATE_MASK)
+   if (istate-has_dir_hash  (ce-ce_flags  CE_STATE_MASK) == 
CE_STATE_MASK)
add_dir_entry(istate, ce);
 
ce-ce_flags = ~CE_UNHASHED;
@@ -181,7 +184,7 @@ void add_name_hash(struct index_state *istate, struct 
cache_entry *ce)
 void remove_name_hash(struct index_state *istate, struct cache_entry *ce)
 {
/* if already hashed, release reference to directory entries */
-   if (ignore_case  (ce-ce_flags  CE_STATE_MASK) == CE_HASHED)
+   if (istate-has_dir_hash  (ce-ce_flags  CE_STATE_MASK) == CE_HASHED)
remove_dir_entry(istate, ce);
 
ce-ce_flags |= CE_UNHASHED;
@@ -228,7 +231,7 @@ struct cache_entry *index_dir_exists(struct index_state 
*istate, const char *nam
struct cache_entry *ce;
struct dir_entry *dir;
 
-   lazy_init_name_hash(istate);
+   init_name_hash(istate, 0);
dir = find_dir_entry(istate, name, namelen);
if (dir  dir-nr)
return dir-ce;
@@ -250,7 +253,7 @@ struct cache_entry *index_file_exists(struct index_state 
*istate, const char *na
unsigned int hash = hash_name(name, namelen);
struct cache_entry *ce;
 
-   lazy_init_name_hash(istate);
+   init_name_hash(istate, 0);
ce = lookup_hash(hash, istate-name_hash);
 
while (ce) {
@@ -286,9 +289,11 @@ void free_name_hash(struct index_state *istate)
if (!istate-name_hash_initialized)
return;
istate-name_hash_initialized = 0;
-   if (ignore_case)
+   if (istate-has_dir_hash) {
/* free directory entries */
for_each_hash(istate-dir_hash, free_dir_entry, NULL);
+   istate-has_dir_hash = 0;
+   }
 
free_hash(istate-name_hash);
free_hash(istate-dir_hash);
-- 
1.9.0.313.g3d0a325

--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html