Re: [PATCH 28/35] commit.c: migrate the commit buffer to the parsed object store

2018-06-13 Thread Stefan Beller
On Wed, Jun 6, 2018 at 12:32 PM Duy Nguyen  wrote:
> >  define_commit_slab(buffer_slab, struct commit_buffer);
>
> struct buffer_slab is defined locally here...
>
...
> > +struct buffer_slab *allocate_commit_buffer_slab(void);
>
> So you would need a forward declaration of struct buffer_slab in
> commit.h before it's referenced here?

Will do so in a resend; as well as in object.h


Re: [PATCH 28/35] commit.c: migrate the commit buffer to the parsed object store

2018-06-06 Thread Duy Nguyen
On Wed, May 30, 2018 at 2:48 AM, Stefan Beller  wrote:
> Signed-off-by: Stefan Beller 
> ---
>  commit.c | 29 +++--
>  commit.h |  2 ++
>  object.c |  5 +
>  object.h |  2 ++
>  4 files changed, 32 insertions(+), 6 deletions(-)
>
> diff --git a/commit.c b/commit.c
> index fd31c453fdc..45dbf6f1453 100644
> --- a/commit.c
> +++ b/commit.c
> @@ -248,18 +248,32 @@ struct commit_buffer {
> unsigned long size;
>  };
>  define_commit_slab(buffer_slab, struct commit_buffer);

struct buffer_slab is defined locally here...

> diff --git a/commit.h b/commit.h
> index 536fa03955f..df199498bfb 100644
> --- a/commit.h
> +++ b/commit.h
> @@ -81,6 +81,8 @@ static inline int parse_commit_the_repository(struct commit 
> *item)
>  }
>  void parse_commit_or_die(struct commit *item);
>
> +struct buffer_slab *allocate_commit_buffer_slab(void);

So you would need a forward declaration of struct buffer_slab in
commit.h before it's referenced here?

> diff --git a/object.h b/object.h
> index 6adc8323ca4..45e22282101 100644
> --- a/object.h
> +++ b/object.h
> @@ -22,6 +22,8 @@ struct parsed_object_pool {
> char *alternate_shallow_file;
>
> int commit_graft_prepared;
> +
> +   struct buffer_slab *buffer_slab;

and maybe here as well

>  };
>
>  struct parsed_object_pool *parsed_object_pool_new(void);
> --
> 2.17.0.582.gccdcbd54c44.dirty
>



-- 
Duy


[PATCH 28/35] commit.c: migrate the commit buffer to the parsed object store

2018-05-29 Thread Stefan Beller
Signed-off-by: Stefan Beller 
---
 commit.c | 29 +++--
 commit.h |  2 ++
 object.c |  5 +
 object.h |  2 ++
 4 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/commit.c b/commit.c
index fd31c453fdc..45dbf6f1453 100644
--- a/commit.c
+++ b/commit.c
@@ -248,18 +248,32 @@ struct commit_buffer {
unsigned long size;
 };
 define_commit_slab(buffer_slab, struct commit_buffer);
-static struct buffer_slab buffer_slab = COMMIT_SLAB_INIT(1, buffer_slab);
+
+struct buffer_slab *allocate_commit_buffer_slab(void)
+{
+   struct buffer_slab *bs = xmalloc(sizeof(*bs));
+   init_buffer_slab(bs);
+   return bs;
+}
+
+void free_commit_buffer_slab(struct buffer_slab *bs)
+{
+   clear_buffer_slab(bs);
+   free(bs);
+}
 
 void set_commit_buffer_the_repository(struct commit *commit, void *buffer, 
unsigned long size)
 {
-   struct commit_buffer *v = buffer_slab_at(&buffer_slab, commit);
+   struct commit_buffer *v = buffer_slab_at(
+   the_repository->parsed_objects->buffer_slab, commit);
v->buffer = buffer;
v->size = size;
 }
 
 const void *get_cached_commit_buffer_the_repository(const struct commit 
*commit, unsigned long *sizep)
 {
-   struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
+   struct commit_buffer *v = buffer_slab_peek(
+   the_repository->parsed_objects->buffer_slab, commit);
if (!v) {
if (sizep)
*sizep = 0;
@@ -291,14 +305,16 @@ const void *get_commit_buffer(const struct commit 
*commit, unsigned long *sizep)
 
 void unuse_commit_buffer(const struct commit *commit, const void *buffer)
 {
-   struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
+   struct commit_buffer *v = buffer_slab_peek(
+   the_repository->parsed_objects->buffer_slab, commit);
if (!(v && v->buffer == buffer))
free((void *)buffer);
 }
 
 void free_commit_buffer(struct commit *commit)
 {
-   struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
+   struct commit_buffer *v = buffer_slab_peek(
+   the_repository->parsed_objects->buffer_slab, commit);
if (v) {
FREE_AND_NULL(v->buffer);
v->size = 0;
@@ -318,7 +334,8 @@ void release_commit_memory(struct commit *c)
 
 const void *detach_commit_buffer(struct commit *commit, unsigned long *sizep)
 {
-   struct commit_buffer *v = buffer_slab_peek(&buffer_slab, commit);
+   struct commit_buffer *v = buffer_slab_peek(
+   the_repository->parsed_objects->buffer_slab, commit);
void *ret;
 
if (!v) {
diff --git a/commit.h b/commit.h
index 536fa03955f..df199498bfb 100644
--- a/commit.h
+++ b/commit.h
@@ -81,6 +81,8 @@ static inline int parse_commit_the_repository(struct commit 
*item)
 }
 void parse_commit_or_die(struct commit *item);
 
+struct buffer_slab *allocate_commit_buffer_slab(void);
+void free_commit_buffer_slab(struct buffer_slab *bs);
 /*
  * Associate an object buffer with the commit. The ownership of the
  * memory is handed over to the commit, and must be free()-able.
diff --git a/object.c b/object.c
index 03180f84b2a..ce29601c6c2 100644
--- a/object.c
+++ b/object.c
@@ -467,6 +467,8 @@ struct parsed_object_pool *parsed_object_pool_new(void)
o->is_shallow = -1;
o->shallow_stat = xcalloc(1, sizeof(*o->shallow_stat));
 
+   o->buffer_slab = allocate_commit_buffer_slab();
+
return o;
 }
 
@@ -538,6 +540,9 @@ void parsed_object_pool_clear(struct parsed_object_pool *o)
FREE_AND_NULL(o->obj_hash);
o->obj_hash_size = 0;
 
+   free_commit_buffer_slab(o->buffer_slab);
+   o->buffer_slab = NULL;
+
clear_alloc_state(o->blob_state);
clear_alloc_state(o->tree_state);
clear_alloc_state(o->commit_state);
diff --git a/object.h b/object.h
index 6adc8323ca4..45e22282101 100644
--- a/object.h
+++ b/object.h
@@ -22,6 +22,8 @@ struct parsed_object_pool {
char *alternate_shallow_file;
 
int commit_graft_prepared;
+
+   struct buffer_slab *buffer_slab;
 };
 
 struct parsed_object_pool *parsed_object_pool_new(void);
-- 
2.17.0.582.gccdcbd54c44.dirty