Re: [PATCH/RFC v2 08/16] Make in-memory format aware of stat_crc

2012-08-07 Thread Thomas Gummerer
On 08/05, Junio C Hamano wrote:
> Thomas Gummerer  writes:
> 
> > +   stat_crc = crc32(stat_crc, (Bytef*)&stat, 4);
> > +   stat = htonl(ce->ce_ino);
> > +   stat_crc = crc32(stat_crc, (Bytef*)&stat, 4);
> > +   stat = htonl(ce->ce_size);
> > +   stat_crc = crc32(stat_crc, (Bytef*)&stat, 4);
> > +   stat = htonl(ce->ce_dev);
> > +   stat_crc = crc32(stat_crc, (Bytef*)&stat, 4);
> > +   stat = htonl(ce->ce_uid);
> > +   stat_crc = crc32(stat_crc, (Bytef*)&stat, 4);
> > +   stat = htonl(ce->ce_gid);
> > +   stat_crc = crc32(stat_crc, (Bytef*)&stat, 4);
> > +   return stat_crc;
> 
> What are these (Bytef *) casts are about?  We do not use it in any
> of our existing calls to crc32().

>From a quick look over the existing calls, their argument is
always either a void* or a char* pointer.  Using pointers other
than those two or Bytef* gives compiler warnings.  I can cast
to either void* or char* if that's preferred.
--
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/RFC v2 08/16] Make in-memory format aware of stat_crc

2012-08-05 Thread Junio C Hamano
Thomas Gummerer  writes:

> + stat_crc = crc32(stat_crc, (Bytef*)&stat, 4);
> + stat = htonl(ce->ce_ino);
> + stat_crc = crc32(stat_crc, (Bytef*)&stat, 4);
> + stat = htonl(ce->ce_size);
> + stat_crc = crc32(stat_crc, (Bytef*)&stat, 4);
> + stat = htonl(ce->ce_dev);
> + stat_crc = crc32(stat_crc, (Bytef*)&stat, 4);
> + stat = htonl(ce->ce_uid);
> + stat_crc = crc32(stat_crc, (Bytef*)&stat, 4);
> + stat = htonl(ce->ce_gid);
> + stat_crc = crc32(stat_crc, (Bytef*)&stat, 4);
> + return stat_crc;

What are these (Bytef *) casts are about?  We do not use it in any
of our existing calls to crc32().
--
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/RFC v2 08/16] Make in-memory format aware of stat_crc

2012-08-05 Thread Thomas Gummerer
Make the in-memory format aware of the stat_crc used by index-v5.
It is simply ignored by index version prior to v5.

Signed-off-by: Thomas Gummerer 
---
 cache.h  |1 +
 read-cache.c |   27 +++
 2 files changed, 28 insertions(+)

diff --git a/cache.h b/cache.h
index 9bfc9f3..076d6af 100644
--- a/cache.h
+++ b/cache.h
@@ -122,6 +122,7 @@ struct cache_entry {
unsigned int ce_flags;
unsigned int ce_namelen;
unsigned char sha1[20];
+   uint32_t ce_stat_crc;
struct cache_entry *next;
struct cache_entry *dir_next;
char name[FLEX_ARRAY]; /* more */
diff --git a/read-cache.c b/read-cache.c
index dceaa5c..4243606 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -67,6 +67,31 @@ void rename_index_entry_at(struct index_state *istate, int 
nr, const char *new_n
add_index_entry(istate, new, 
ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE);
 }
 
+static uint32_t calculate_stat_crc(struct cache_entry *ce)
+{
+   unsigned int ctimens = 0;
+   uint32_t stat, stat_crc;
+
+   stat = htonl(ce->ce_ctime.sec);
+   stat_crc = crc32(0, (Bytef*)&stat, 4);
+#ifdef USE_NSEC
+   ctimens = ce->ce_ctime.nsec;
+#endif
+   stat = htonl(ctimens);
+   stat_crc = crc32(stat_crc, (Bytef*)&stat, 4);
+   stat = htonl(ce->ce_ino);
+   stat_crc = crc32(stat_crc, (Bytef*)&stat, 4);
+   stat = htonl(ce->ce_size);
+   stat_crc = crc32(stat_crc, (Bytef*)&stat, 4);
+   stat = htonl(ce->ce_dev);
+   stat_crc = crc32(stat_crc, (Bytef*)&stat, 4);
+   stat = htonl(ce->ce_uid);
+   stat_crc = crc32(stat_crc, (Bytef*)&stat, 4);
+   stat = htonl(ce->ce_gid);
+   stat_crc = crc32(stat_crc, (Bytef*)&stat, 4);
+   return stat_crc;
+}
+
 /*
  * This only updates the "non-critical" parts of the directory
  * cache, ie the parts that aren't tracked by GIT, and only used
@@ -89,6 +114,8 @@ void fill_stat_cache_info(struct cache_entry *ce, struct 
stat *st)
 
if (S_ISREG(st->st_mode))
ce_mark_uptodate(ce);
+
+   ce->ce_stat_crc = calculate_stat_crc(ce);
 }
 
 static int ce_compare_data(struct cache_entry *ce, struct stat *st)
-- 
1.7.10.GIT

--
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