get_octopus_merge_bases(): cleanup redundant variable
PATCH 1/1 get_octopus_merge_bases(): cleanup redundant variable
pptr is needless. Some related code got cleaned as well
--- commit.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-)
commit.c +15 -18
@@ -834,26 +834,23 @@ static struct commit_list *merge_bases_many(struct commit *one, int n, struct costruct 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; }
Signature · 1 line
1.8.3.2
Quoted 25 lines · Vasily Makarov
pptr is needless. Some related code got cleaned as well
Signed-off-by Vasily Makarov <[email protected]>--- commit.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-)commit.c +0
-9@@ -834,26 +834,23 @@ static struct commit_list *merge_bases_many(struct commit *one, int n, struct costruct 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;
commit.c static struct commit_list *merge_bases_many(struct commit *one, int n, struct co · line 838
Quoted 10 lines
commit.c +1
-9- 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 ;-).
Quoted 18 lines
commit.c +14
-0+ +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; }
PATCH 1/1 get_octopus_merge_bases(): cleanup redundant variable
pptr is needless. Some related code got cleaned as well
--- commit.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-)
commit.c +18 -18
@@ -834,26 +834,26 @@ static struct commit_list *merge_bases_many(struct commit *one, int n, struct costruct 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; }
Signature · 1 line
1.8.3.2