threads / patch / 33991

patch, 4 partsTrivial patches

Subject: [PATCH 0/4] Trivial patches

## tl;dr

8 messages between May 30, 2013 and Jun 3, 2013. Diffs are folded; open one to read it.

replies: 7people: 2as markdown or json

Felipe Contreras· May 30, 2013, 13:56 UTC · lore
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· May 30, 2013, 13:56 UTC · re: Felipe Contreras · lore

[PATCH 1/4] read-cache: fix wrong 'the_index' usage

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(-)
Show changes to read-cache.c +1 −1
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
Junio C Hamano· Jun 3, 2013, 17:09 UTC · re: Felipe Contreras · lore

Re: [PATCH 1/4] read-cache: fix wrong 'the_index' usage

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.
Show 16 quoted lines
>  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;
Felipe Contreras· May 30, 2013, 13:56 UTC · re: Felipe Contreras · lore

[PATCH 2/4] read-cache: trivial style cleanups

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 read-cache.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Show changes to read-cache.c +2 −2
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· May 30, 2013, 13:56 UTC · re: Felipe Contreras · lore

[PATCH 3/4] unpack-trees: trivial cleanup

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(-)
Show changes to unpack-trees.c +1 −2
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
Junio C Hamano· Jun 3, 2013, 17:13 UTC · re: Felipe Contreras · lore

Re: [PATCH 3/4] unpack-trees: trivial cleanup

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.
Show 17 quoted lines
>  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· Jun 3, 2013, 20:51 UTC · re: Junio C Hamano · lore

Re: [PATCH 3/4] unpack-trees: trivial cleanup

On Mon, Jun 3, 2013 at 12:13 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 10 quoted lines
> 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
Felipe Contreras· May 30, 2013, 13:56 UTC · re: Felipe Contreras · lore

[PATCH 4/4] sha1_file: trivial style cleanup

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 sha1_file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Show changes to sha1_file.c +1 −1
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

← back to recent threads