All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] get_octopus_merge_bases(): cleanup redundant variable
@ 2014-01-03 14:45 Vasily Makarov
  2014-01-03 18:26 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Vasily Makarov @ 2014-01-03 14:45 UTC (permalink / raw)
  To: git; +Cc: vmiklos, Vasily Makarov

pptr is needless. Some related code got cleaned as well

Signed-off-by: Vasily Makarov <einmalfel@gmail.com>
---
 commit.c | 33 +++++++++++++++------------------
 1 file changed, 15 insertions(+), 18 deletions(-)

diff --git a/commit.c b/commit.c
index de16a3c..4a7a192 100644
--- a/commit.c
+++ b/commit.c
@@ -834,26 +834,23 @@ static struct commit_list *merge_bases_many(struct commit *one, int n, struct co
 struct commit_list *get_octopus_merge_bases(struct commit_list *in)
 {
 	struct commit_list *i, *j, *k, *ret = NULL;
-	struct commit_list **pptr = &ret;
 
-	for (i = in; i; i = i->next) {
-		if (!ret)
-			pptr = &commit_list_insert(i->item, pptr)->next;
-		else {
-			struct commit_list *new = NULL, *end = NULL;
-
-			for (j = ret; j; j = j->next) {
-				struct commit_list *bases;
-				bases = get_merge_bases(i->item, j->item, 1);
-				if (!new)
-					new = bases;
-				else
-					end->next = bases;
-				for (k = bases; k; k = k->next)
-					end = k;
-			}
-			ret = new;
+	commit_list_insert(in->item, &ret);
+
+	for (i = in->next; i; i = i->next) {
+		struct commit_list *new = NULL, *end = NULL;
+
+		for (j = ret; j; j = j->next) {
+			struct commit_list *bases;
+			bases = get_merge_bases(i->item, j->item, 1);
+			if (!new)
+				new = bases;
+			else
+				end->next = bases;
+			for (k = bases; k; k = k->next)
+				end = k;
 		}
+		ret = new;
 	}
 	return ret;
 }
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] get_octopus_merge_bases(): cleanup redundant variable
  2014-01-03 14:45 [PATCH] get_octopus_merge_bases(): cleanup redundant variable Vasily Makarov
@ 2014-01-03 18:26 ` Junio C Hamano
  2014-01-03 19:01   ` Vasily Makarov
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2014-01-03 18:26 UTC (permalink / raw)
  To: Vasily Makarov; +Cc: git, vmiklos

Vasily Makarov <einmalfel@gmail.com> writes:

> pptr is needless. Some related code got cleaned as well
>
> Signed-off-by: Vasily Makarov <einmalfel@gmail.com>
> ---
>  commit.c | 33 +++++++++++++++------------------
>  1 file changed, 15 insertions(+), 18 deletions(-)
>
> diff --git a/commit.c b/commit.c
> index de16a3c..4a7a192 100644
> --- a/commit.c
> +++ b/commit.c
> @@ -834,26 +834,23 @@ static struct commit_list *merge_bases_many(struct commit *one, int n, struct co
>  struct commit_list *get_octopus_merge_bases(struct commit_list *in)
>  {
>  	struct commit_list *i, *j, *k, *ret = NULL;
> -	struct commit_list **pptr = &ret;
>  
> -	for (i = in; i; i = i->next) {
> -		if (!ret)
> -			pptr = &commit_list_insert(i->item, pptr)->next;
> -		else {
> -			struct commit_list *new = NULL, *end = NULL;
> -
> -			for (j = ret; j; j = j->next) {
> -				struct commit_list *bases;
> -				bases = get_merge_bases(i->item, j->item, 1);
> -				if (!new)
> -					new = bases;
> -				else
> -					end->next = bases;
> -				for (k = bases; k; k = k->next)
> -					end = k;
> -			}
> -			ret = new;
> +	commit_list_insert(in->item, &ret);

I suspect that the original code would have behaved well (and I also
suspect that it was designed to) even if in==NULL upon entry, but
this version will crash here.  Nothing a simple

	if (!in)
        	return NULL;

upfront cannot fix, though.

And if we add these three lines back, the patch will become 18
insertions with 18 deletions but the result is very much more
readable than the original ;-).

> +
> +	for (i = in->next; i; i = i->next) {
> +		struct commit_list *new = NULL, *end = NULL;
> +
> +		for (j = ret; j; j = j->next) {
> +			struct commit_list *bases;
> +			bases = get_merge_bases(i->item, j->item, 1);
> +			if (!new)
> +				new = bases;
> +			else
> +				end->next = bases;
> +			for (k = bases; k; k = k->next)
> +				end = k;
>  		}
> +		ret = new;
>  	}
>  	return ret;
>  }

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] get_octopus_merge_bases(): cleanup redundant variable
  2014-01-03 18:26 ` Junio C Hamano
@ 2014-01-03 19:01   ` Vasily Makarov
  0 siblings, 0 replies; 3+ messages in thread
From: Vasily Makarov @ 2014-01-03 19:01 UTC (permalink / raw)
  To: git; +Cc: gitster, vmiklos, Vasily Makarov

pptr is needless. Some related code got cleaned as well

Signed-off-by: Vasily Makarov <einmalfel@gmail.com>
---
 commit.c | 36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/commit.c b/commit.c
index de16a3c..8e48c49 100644
--- a/commit.c
+++ b/commit.c
@@ -834,26 +834,26 @@ static struct commit_list *merge_bases_many(struct commit *one, int n, struct co
 struct commit_list *get_octopus_merge_bases(struct commit_list *in)
 {
 	struct commit_list *i, *j, *k, *ret = NULL;
-	struct commit_list **pptr = &ret;
 
-	for (i = in; i; i = i->next) {
-		if (!ret)
-			pptr = &commit_list_insert(i->item, pptr)->next;
-		else {
-			struct commit_list *new = NULL, *end = NULL;
-
-			for (j = ret; j; j = j->next) {
-				struct commit_list *bases;
-				bases = get_merge_bases(i->item, j->item, 1);
-				if (!new)
-					new = bases;
-				else
-					end->next = bases;
-				for (k = bases; k; k = k->next)
-					end = k;
-			}
-			ret = new;
+	if (!in)
+		return NULL;
+
+	commit_list_insert(in->item, &ret);
+
+	for (i = in->next; i; i = i->next) {
+		struct commit_list *new = NULL, *end = NULL;
+
+		for (j = ret; j; j = j->next) {
+			struct commit_list *bases;
+			bases = get_merge_bases(i->item, j->item, 1);
+			if (!new)
+				new = bases;
+			else
+				end->next = bases;
+			for (k = bases; k; k = k->next)
+				end = k;
 		}
+		ret = new;
 	}
 	return ret;
 }
-- 
1.8.3.2

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-01-03 19:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-03 14:45 [PATCH] get_octopus_merge_bases(): cleanup redundant variable Vasily Makarov
2014-01-03 18:26 ` Junio C Hamano
2014-01-03 19:01   ` Vasily Makarov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.