# [PATCH 0/4] Trivial patches

8 messages from 2013-05-30 to 2013-06-03. Participants: Felipe Contreras, Junio C Hamano.
Thread: https://gitlist.dev/t/33991

## Felipe Contreras, 2013-05-30 13:56

Subject: [PATCH 0/4] Trivial patches
Message-ID: <1369922181-31016-1-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1369922181-31016-1-git-send-email-felipe.contreras%40gmail.com

```
Hi,

Here's a bunch of  trivial patches, mostly syle, but the first one might be
important.

Felipe Contreras (4):
  read-cache: fix wrong 'the_index' usage
  read-cache: trivial style cleanups
  unpack-trees: trivial cleanup
  sha1_file: trivial style cleanup

 read-cache.c   | 6 +++---
 sha1_file.c    | 2 +-
 unpack-trees.c | 3 +--
 3 files changed, 5 insertions(+), 6 deletions(-)

-- 
1.8.3.rc3.312.g47657de

```

## Felipe Contreras, 2013-05-30 13:56

Subject: [PATCH 1/4] read-cache: fix wrong 'the_index' usage
Message-ID: <1369922181-31016-2-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1369922181-31016-2-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1369922181-31016-1-git-send-email-felipe.contreras@gmail.com>

```
We are dealing with the 'istate' index, not 'the_index'.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 read-cache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/read-cache.c b/read-cache.c
index 04ed561..5253ec5 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -626,7 +626,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
 			if (*ptr == '/') {
 				struct cache_entry *foundce;
 				++ptr;
-				foundce = index_name_exists(&the_index, ce->name, ptr - ce->name, ignore_case);
+				foundce = index_name_exists(istate, ce->name, ptr - ce->name, ignore_case);
 				if (foundce) {
 					memcpy((void *)startPtr, foundce->name + (startPtr - ce->name), ptr - startPtr);
 					startPtr = ptr;
-- 
1.8.3.rc3.312.g47657de

```

## Felipe Contreras, 2013-05-30 13:56

Subject: [PATCH 2/4] read-cache: trivial style cleanups
Message-ID: <1369922181-31016-3-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1369922181-31016-3-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1369922181-31016-1-git-send-email-felipe.contreras@gmail.com>

```
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 read-cache.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/read-cache.c b/read-cache.c
index 5253ec5..7040e79 100644
--- a/read-cache.c
+++ b/read-cache.c
@@ -979,7 +979,7 @@ int add_index_entry(struct index_state *istate, struct cache_entry *ce, int opti
 	if (istate->cache_nr == istate->cache_alloc) {
 		istate->cache_alloc = alloc_nr(istate->cache_alloc);
 		istate->cache = xrealloc(istate->cache,
-					istate->cache_alloc * sizeof(struct cache_entry *));
+					istate->cache_alloc * sizeof(*istate->cache));
 	}
 
 	/* Add it in.. */
@@ -1449,7 +1449,7 @@ int read_index_from(struct index_state *istate, const char *path)
 	istate->version = ntohl(hdr->hdr_version);
 	istate->cache_nr = ntohl(hdr->hdr_entries);
 	istate->cache_alloc = alloc_nr(istate->cache_nr);
-	istate->cache = xcalloc(istate->cache_alloc, sizeof(struct cache_entry *));
+	istate->cache = xcalloc(istate->cache_alloc, sizeof(*istate->cache));
 	istate->initialized = 1;
 
 	if (istate->version == 4)
-- 
1.8.3.rc3.312.g47657de

```

## Felipe Contreras, 2013-05-30 13:56

Subject: [PATCH 3/4] unpack-trees: trivial cleanup
Message-ID: <1369922181-31016-4-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1369922181-31016-4-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1369922181-31016-1-git-send-email-felipe.contreras@gmail.com>

```
dfc has not been initialized at this point.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 unpack-trees.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/unpack-trees.c b/unpack-trees.c
index ede4299..36f4ff7 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1040,8 +1040,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
 	if (!o->skip_sparse_checkout)
 		mark_new_skip_worktree(o->el, o->src_index, 0, CE_NEW_SKIP_WORKTREE);
 
-	if (!dfc)
-		dfc = xcalloc(1, cache_entry_size(0));
+	dfc = xcalloc(1, cache_entry_size(0));
 	o->df_conflict_entry = dfc;
 
 	if (len) {
-- 
1.8.3.rc3.312.g47657de

```

## Felipe Contreras, 2013-05-30 13:56

Subject: [PATCH 4/4] sha1_file: trivial style cleanup
Message-ID: <1369922181-31016-5-git-send-email-felipe.contreras@gmail.com>
URL: https://gitlist.dev/e/1369922181-31016-5-git-send-email-felipe.contreras%40gmail.com
In-Reply-To: <1369922181-31016-1-git-send-email-felipe.contreras@gmail.com>

```
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 sha1_file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sha1_file.c b/sha1_file.c
index 67e815b..b114cc9 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2138,7 +2138,7 @@ void *unpack_entry(struct packed_git *p, off_t obj_offset,
 		if (!data)
 			die("failed to apply delta");
 
-		free (delta_data);
+		free(delta_data);
 	}
 
 	*final_type = type;
-- 
1.8.3.rc3.312.g47657de

```

## Junio C Hamano, 2013-06-03 17:09

Subject: Re: [PATCH 1/4] read-cache: fix wrong 'the_index' usage
Message-ID: <7v4ndfi0ir.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v4ndfi0ir.fsf%40alter.siamese.dyndns.org
In-Reply-To: <1369922181-31016-2-git-send-email-felipe.contreras@gmail.com>

```
Felipe Contreras <felipe.contreras@gmail.com> writes:

> We are dealing with the 'istate' index, not 'the_index'.
>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---

Good catch; will apply.

>  read-cache.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/read-cache.c b/read-cache.c
> index 04ed561..5253ec5 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -626,7 +626,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
>  			if (*ptr == '/') {
>  				struct cache_entry *foundce;
>  				++ptr;
> -				foundce = index_name_exists(&the_index, ce->name, ptr - ce->name, ignore_case);
> +				foundce = index_name_exists(istate, ce->name, ptr - ce->name, ignore_case);
>  				if (foundce) {
>  					memcpy((void *)startPtr, foundce->name + (startPtr - ce->name), ptr - startPtr);
>  					startPtr = ptr;

```

## Junio C Hamano, 2013-06-03 17:13

Subject: Re: [PATCH 3/4] unpack-trees: trivial cleanup
Message-ID: <7vzjv7glrw.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vzjv7glrw.fsf%40alter.siamese.dyndns.org
In-Reply-To: <1369922181-31016-4-git-send-email-felipe.contreras@gmail.com>

```
Felipe Contreras <felipe.contreras@gmail.com> writes:

> dfc has not been initialized at this point.
>
> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
> ---

Upon the first entry to this function, because dfc is 

	static struct cache_entry *dfc;

it is NULL.  In that case, we allocate one instance.  When the
function is called again, we can reuse the entry, because it merely
acts as a unique sentinel value.

And we do not free() it.

>  unpack-trees.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/unpack-trees.c b/unpack-trees.c
> index ede4299..36f4ff7 100644
> --- a/unpack-trees.c
> +++ b/unpack-trees.c
> @@ -1040,8 +1040,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
>  	if (!o->skip_sparse_checkout)
>  		mark_new_skip_worktree(o->el, o->src_index, 0, CE_NEW_SKIP_WORKTREE);
>  
> -	if (!dfc)
> -		dfc = xcalloc(1, cache_entry_size(0));
> +	dfc = xcalloc(1, cache_entry_size(0));
>  	o->df_conflict_entry = dfc;
>  
>  	if (len) {

```

## Felipe Contreras, 2013-06-03 20:51

Subject: Re: [PATCH 3/4] unpack-trees: trivial cleanup
Message-ID: <CAMP44s0rHtrf0aa6sgQxM=vsMcYXOt5Jian-wuP9AA_rXesBmw@mail.gmail.com>
URL: https://gitlist.dev/e/CAMP44s0rHtrf0aa6sgQxM%3DvsMcYXOt5Jian-wuP9AA_rXesBmw%40mail.gmail.com
In-Reply-To: <7vzjv7glrw.fsf@alter.siamese.dyndns.org>

```
On Mon, Jun 3, 2013 at 12:13 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Felipe Contreras <felipe.contreras@gmail.com> writes:
>
>> dfc has not been initialized at this point.
>>
>> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
>> ---
>
> Upon the first entry to this function, because dfc is
>
>         static struct cache_entry *dfc;

Ah, I didn't notice it's static. Smells error-prone, but I guess it's
OK for now.

-- 
Felipe Contreras

```
