fmt-merge-msg improvements
cover fmt-merge-msg improvements
The first one might be considered a bug, although triggering it is probably impossible. Not much of a price to pay for correctness though.
The next two patches modernize and update the test a bit.
The next 3 patches try and reduce the code size by libifying(?) fmt-merge-msg.
The final patch is just a "while I'm here" thing and might be unnecessary if we decide to just remove the summary option.
Stephen Boyd (7):
fmt-merge-msg: be quiet if nothing to merge
t6200: modernize with test_tick
t6200: test fmt-merge-msg more
fmt-merge-msg: use pretty.c routines
string-list: add unsorted_string_list_lookup()
fmt-merge-msg: remove custom string_list implementation
fmt-merge-msg: hide summary option
Documentation/technical/api-string-list.txt | 6 +- builtin/fmt-merge-msg.c | 159 ++++++++-------------- string-list.c | 13 ++- string-list.h | 3 +- t/t6200-fmt-merge-msg.sh | 196 ++++++++++++++++++++++----- 5 files changed, 235 insertions(+), 142 deletions(-)
PATCH 1/7 fmt-merge-msg: be quiet if nothing to merge
When FETCH_HEAD contains only 'not-for-merge' entries fmt-merge-msg still outputs "Merge" (and if the branch isn't master " into <branch>"). In this case fmt-merge-msg is outputting junk and should really just be quiet. Fix it.
--- builtin/fmt-merge-msg.c | 3 +++ t/t6200-fmt-merge-msg.sh | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 0 deletions(-)
builtin/fmt-merge-msg.c +3 -0
@@ -281,6 +281,9 @@ int fmt_merge_msg(int merge_summary, struct strbuf *in, struct strbuf *out) {die ("Error in line %d: %.*s" , i, len, p); } +if (!srcs.nr) +return 0 ; +strbuf_addstr (out,"Merge " );for (i =0 ; i < srcs.nr; i++) {struct src_data *src_data = srcs.payload[i];
t/t6200-fmt-merge-msg.sh +19 -0
@@ -21,6 +21,8 @@ test_expect_success setup ' setdate && git commit -m "Initial" && + git clone . remote && + echo uno >one && echo dos >two && git add two &&
@@ -240,4 +242,21 @@ test_expect_success 'merge-msg -F in subdirectory' ' test_cmp expected actual ' +test_expect_success 'merge-msg with nothing to merge' ' + + git config --unset-all merge.log + git config --unset-all merge.summary + git config merge.summary yes && + + ( + cd remote && + git checkout -b unrelated && + setdate && + git fetch origin && + git fmt-merge-msg <.git/FETCH_HEAD >../actual + ) && + + test_cmp /dev/null actual +' + test_done
Signature · 1 line
1.7.0.3.254.g4503b
Re: [PATCH 1/7] fmt-merge-msg: be quiet if nothing to merge
Quoted 4 lines · Stephen Boyd
When
FETCH_HEADcontains only 'not-for-merge' entries fmt-merge-msg still outputs "Merge" (and if the branch isn't master " into <branch>"). In this case fmt-merge-msg is outputting junk and should really just be quiet. Fix it.
Hmm, doesn't pull fail in such a case anyway? Is there a real damage?
I am just trying asses if this is with a maint-worthy urgency. The patch looks sane.
Thanks.
Re: [PATCH 1/7] fmt-merge-msg: be quiet if nothing to merge
Quoted 5 lines · Junio C Hamano
Hmm, doesn't pull fail in such a case anyway? Is there a real damage?
I am just trying asses if this is with a maint-worthy urgency. The patch looks sane.
I don't think this is ever triggered with pull so probably not maint-worthy. I just ordered it that way in case you figured it as such.
PATCH 2/7 t6200: modernize with test_tick
In reply to Stephen BoydThis test defines its own version of test_tick. Get rid of it.
--- t/t6200-fmt-merge-msg.sh | 64 +++++++++++++++++++++------------------------- 1 files changed, 29 insertions(+), 35 deletions(-)
t/t6200-fmt-merge-msg.sh +29 -35
@@ -7,18 +7,10 @@ test_description='fmt-merge-msg test' . ./test-lib.sh -datestamp=1151939923 -setdate () { - GIT_COMMITTER_DATE="$datestamp +0200" - GIT_AUTHOR_DATE="$datestamp +0200" - datestamp=`expr "$datestamp" + 1` - export GIT_COMMITTER_DATE GIT_AUTHOR_DATE -} - test_expect_success setup ' echo one >one && git add one && - setdate && + test_tick && git commit -m "Initial" && git clone . remote &&
@@ -26,46 +18,48 @@ test_expect_success setup ' echo uno >one && echo dos >two && git add two && - setdate && + test_tick && git commit -a -m "Second" && git checkout -b left && - echo $datestamp >one && - setdate && + echo "c1" >one && + test_tick && git commit -a -m "Common #1" && - echo $datestamp >one && - setdate && + echo "c2" >one && + test_tick && git commit -a -m "Common #2" && git branch right && - echo $datestamp >two && - setdate && + echo "l3" >two && + test_tick && git commit -a -m "Left #3" && - echo $datestamp >two && - setdate && + echo "l4" >two && + test_tick && git commit -a -m "Left #4" && - echo $datestamp >two && - setdate && + echo "l5" >two && + test_tick && git commit -a -m "Left #5" && + git tag tag-l5 && git checkout right && - echo $datestamp >three && + echo "r3" >three && git add three && - setdate && + test_tick && git commit -a -m "Right #3" && + git tag tag-r3 && - echo $datestamp >three && - setdate && + echo "r4" >three && + test_tick && git commit -a -m "Right #4" && - echo $datestamp >three && - setdate && + echo "r5" >three && + test_tick && git commit -a -m "Right #5" && git show-branch
@@ -115,7 +109,7 @@ test_expect_success 'merge-msg test #3-1' ' git config merge.log true && git checkout master && - setdate && + test_tick && git fetch . left && git fmt-merge-msg <.git/FETCH_HEAD >actual &&
@@ -129,7 +123,7 @@ test_expect_success 'merge-msg test #3-2' ' git config merge.summary true && git checkout master && - setdate && + test_tick && git fetch . left && git fmt-merge-msg <.git/FETCH_HEAD >actual &&
@@ -161,7 +155,7 @@ test_expect_success 'merge-msg test #4-1' ' git config merge.log true && git checkout master && - setdate && + test_tick && git fetch . left right && git fmt-merge-msg <.git/FETCH_HEAD >actual &&
@@ -175,7 +169,7 @@ test_expect_success 'merge-msg test #4-2' ' git config merge.summary true && git checkout master && - setdate && + test_tick && git fetch . left right && git fmt-merge-msg <.git/FETCH_HEAD >actual &&
@@ -189,7 +183,7 @@ test_expect_success 'merge-msg test #5-1' ' git config merge.log yes && git checkout master && - setdate && + test_tick && git fetch . left right && git fmt-merge-msg <.git/FETCH_HEAD >actual &&
@@ -203,7 +197,7 @@ test_expect_success 'merge-msg test #5-2' ' git config merge.summary yes && git checkout master && - setdate && + test_tick && git fetch . left right && git fmt-merge-msg <.git/FETCH_HEAD >actual &&
@@ -217,7 +211,7 @@ test_expect_success 'merge-msg -F' ' git config merge.summary yes && git checkout master && - setdate && + test_tick && git fetch . left right && git fmt-merge-msg -F .git/FETCH_HEAD >actual &&
@@ -231,7 +225,7 @@ test_expect_success 'merge-msg -F in subdirectory' ' git config merge.summary yes && git checkout master && - setdate && + test_tick && git fetch . left right && mkdir sub && cp .git/FETCH_HEAD sub/FETCH_HEAD &&
@@ -251,7 +245,7 @@ test_expect_success 'merge-msg with nothing to merge' ' ( cd remote && git checkout -b unrelated && - setdate && + test_tick && git fetch origin && git fmt-merge-msg <.git/FETCH_HEAD >../actual ) &&
Signature · 1 line
1.7.0.3.254.g4503b
PATCH 3/7 t6200: test fmt-merge-msg more
In reply to Stephen BoydAdd some more tests so we don't break behavior upon modernizing fmt-merge-msg.
--- t/t6200-fmt-merge-msg.sh | 115 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 115 insertions(+), 0 deletions(-)
t/t6200-fmt-merge-msg.sh +115 -0
@@ -62,6 +62,14 @@ test_expect_success setup ' test_tick && git commit -a -m "Right #5" && + git checkout -b long && + i=0 && + while test $i -lt 30 + do + test_commit $i one && + i=$(($i+1)) + done && + git show-branch '
@@ -253,4 +261,111 @@ test_expect_success 'merge-msg with nothing to merge' ' test_cmp /dev/null actual ' +cat >expected <<\EOF +Merge tag 'tag-r3' + +* tag 'tag-r3': + Right #3 + Common #2 + Common #1 +EOF + +test_expect_success 'merge-msg tag' ' + + git config --unset-all merge.log + git config --unset-all merge.summary + git config merge.summary yes && + + git checkout master && + test_tick && + git fetch . tag tag-r3 && + + git fmt-merge-msg <.git/FETCH_HEAD >actual && + test_cmp expected actual +' + +cat >expected <<\EOF +Merge tags 'tag-r3' and 'tag-l5' + +* tag 'tag-r3': + Right #3 + Common #2 + Common #1 + +* tag 'tag-l5': + Left #5 + Left #4 + Left #3 + Common #2 + Common #1 +EOF + +test_expect_success 'merge-msg two tags' ' + + git config --unset-all merge.log + git config --unset-all merge.summary + git config merge.summary yes && + + git checkout master && + test_tick && + git fetch . tag tag-r3 tag tag-l5 && + + git fmt-merge-msg <.git/FETCH_HEAD >actual && + test_cmp expected actual +' + +cat >expected <<\EOF +Merge branch 'left', tag 'tag-r3' + +* tag 'tag-r3': + Right #3 + Common #2 + Common #1 + +* left: + Left #5 + Left #4 + Left #3 + Common #2 + Common #1 +EOF + +test_expect_success 'merge-msg tag and branch' ' + + git config --unset-all merge.log + git config --unset-all merge.summary + git config merge.summary yes && + + git checkout master && + test_tick && + git fetch . tag tag-r3 left && + + git fmt-merge-msg <.git/FETCH_HEAD >actual && + test_cmp expected actual +' + +cat >expected <<\EOF +Merge branch 'long' + +* long: (35 commits) +EOF + +test_expect_success 'merge-msg lots of commits' ' + + git checkout master && + test_tick && + git fetch . long && + + i=29 && + while test $i -gt 9 + do + echo " $i" && + i=$(($i-1)) + done >>expected && + echo " ..." >>expected + + git fmt-merge-msg <.git/FETCH_HEAD >actual && + test_cmp expected actual +' + test_done
Signature · 1 line
1.7.0.3.254.g4503b
PATCH 4/7 fmt-merge-msg: use pretty.c routines
In reply to Stephen BoydThis command duplicates functionality of the '%s' pretty format. Simplify the code a bit by using the pretty printing routine instead of open-coding it here.
--- builtin/fmt-merge-msg.c | 29 ++++++++--------------------- 1 files changed, 8 insertions(+), 21 deletions(-)
builtin/fmt-merge-msg.c +8 -21
@@ -185,6 +185,7 @@ static void shortlog(const char *name, unsigned char *sha1,struct object *branch;struct list subjects = {NULL ,NULL ,0 ,0 };int flags =UNINTERESTING |TREESAME |SEEN |SHOWN |ADDED ; +struct strbuf sb =STRBUF_INIT ; branch =deref_tag (parse_object (sha1),sha1_to_hex (sha1),40 );if (!branch || branch->type !=OBJ_COMMIT )
@@ -198,7 +199,7 @@ static void shortlog(const char *name, unsigned char *sha1,if (prepare_revision_walk (rev))die ("revision walk setup failed" );while ((commit =get_revision (rev)) !=NULL ) { -char *oneline, *bol, *eol; +struct pretty_print_context ctx = {0 };/* ignore merges */ if (commit->parents && commit->parents->next)
@@ -208,30 +209,16 @@ static void shortlog(const char *name, unsigned char *sha1,if (subjects.nr > limit)continue ; - bol =strstr (commit->buffer,"\n\n" ); -if (bol) { -unsigned char c; -do { - c = *++bol; - }while (isspace (c)); -if (!c) - bol =NULL ; - } +format_commit_message (commit,"%s" , &sb, &ctx); +strbuf_ltrim (&sb); -if (!bol) { +if (!sb.len)append_to_list (&subjects,xstrdup (sha1_to_hex ( commit->object.sha1)),NULL ); -continue ; - } - - eol =strchr (bol,'\n' ); -if (eol) { - oneline =xmemdupz (bol, eol - bol); - }else { - oneline =xstrdup (bol); - } -append_to_list (&subjects, oneline,NULL ); +else +append_to_list (&subjects,strbuf_detach (&sb,NULL ), +NULL ); }if (count > limit)
Signature · 1 line
1.7.0.3.254.g4503b
PATCH 5/7 string-list: add unsorted_string_list_lookup()
In reply to Stephen BoydSometimes users need to lookup a string in an unsorted string_list. In that case they should use this function instead of the version for sorted strings.
--- Documentation/technical/api-string-list.txt | 6 +++++- string-list.c | 13 ++++++++++--- string-list.h | 3 ++- 3 files changed, 17 insertions(+), 5 deletions(-)
Documentation/technical/api-string-list.txt +5 -1
@@ -104,8 +104,12 @@ write `string_list_insert(...)->util = ...;`. `unsorted_string_list_has_string`:: It's like `string_list_has_string()` but for unsorted lists. + +`unsorted_string_list_lookup`:: + + It's like `string_list_lookup()` but for unsorted lists. + -This function needs to look through all items, as opposed to its +The above two functions need to look through all items, as opposed to their counterpart for sorted lists, which performs a binary search. Data structures
string-list.c +10 -3
@@ -168,12 +168,19 @@ void sort_string_list(struct string_list *list)qsort (list->items, list->nr,sizeof (*list->items), cmp_items); } -int unsorted_string_list_has_string (struct string_list *list,const char *string) +struct string_list_item *unsorted_string_list_lookup (struct string_list *list, +const char *string) {int i;for (i =0 ; i < list->nr; i++)if (!strcmp (string, list->items[i].string)) -return 1 ; -return 0 ; +return list->items + i; +return NULL ; +} + +int unsorted_string_list_has_string (struct string_list *list, +const char *string) +{ +return unsorted_string_list_lookup (list, string) !=NULL ; }
string-list.h +2 -1
@@ -38,5 +38,6 @@ struct string_list_item *string_list_lookup(const char *string, struct string_listruct string_list_item *string_list_append (const char *string,struct string_list *list);void sort_string_list (struct string_list *list);int unsorted_string_list_has_string (struct string_list *list,const char *string); - +struct string_list_item *unsorted_string_list_lookup (struct string_list *list, +const char *string);#endif /* STRING_LIST_H */
Signature · 1 line
1.7.0.3.254.g4503b
PATCH 6/7 fmt-merge-msg: remove custom string_list implementation
In reply to Stephen BoydThis command uses a custom version of string list when it could just as easily use the string_list API. Convert it to use string_list and reduce the code size a bit.
---
Anyone else annoyed that string_list_append() is the only function that takes doesn't take the string list as the first argument?
On another note, git-compat-util.h:115 says:
#undef _ALL_SOURCE /* AIX 5.3L defines a struct list with...
which may be unnecessary now that struct list is gone. Need someone on AIX 5.3L to test that though.
Finally, this doesn't free some of the lists since I wanted it to be a straight conversion. I'm feeling lazy right now but I'll think about it.
builtin/fmt-merge-msg.c | 127 ++++++++++++++++------------------------------ 1 files changed, 44 insertions(+), 83 deletions(-)
builtin/fmt-merge-msg.c +44 -83
@@ -4,6 +4,7 @@#include "diff.h" #include "revision.h" #include "tag.h" +#include "string-list.h" static const char *const fmt_merge_msg_usage[] = {"git fmt-merge-msg [--log|--no-log] [--file <file>]" ,
@@ -24,58 +25,21 @@ static int fmt_merge_msg_config(const char *key, const char *value, void *cb)return 0 ; } -struct list { -char **list; -void **payload; -unsigned nr, alloc; +struct src_data { +struct string_list branch, tag, r_branch, generic; +int head_status; }; -static void append_to_list (struct list *list,char *value,void *payload) -{ -if (list->nr == list->alloc) { - list->alloc +=32 ; - list->list =xrealloc (list->list,sizeof (char *) * list->alloc); - list->payload =xrealloc (list->payload, -sizeof (char *) * list->alloc); - } - list->payload[list->nr] = payload; - list->list[list->nr++] = value; -} - -static int find_in_list (struct list *list,char *value) -{ -int i; - -for (i =0 ; i < list->nr; i++) -if (!strcmp (list->list[i], value)) -return i; - -return -1 ; -} - -static void free_list (struct list *list) +void init_src_data (struct src_data *data) { -int i; - -if (list->alloc ==0 ) -return ; - -for (i =0 ; i < list->nr; i++) { -free (list->list[i]); -free (list->payload[i]); - } -free (list->list); -free (list->payload); - list->nr = list->alloc =0 ; + data->branch.strdup_strings =1 ; + data->tag.strdup_strings =1 ; + data->r_branch.strdup_strings =1 ; + data->generic.strdup_strings =1 ; } -struct src_data { -struct list branch, tag, r_branch, generic; -int head_status; -}; - -static struct list srcs = {NULL ,NULL ,0 ,0 }; -static struct list origins = {NULL ,NULL ,0 ,0 }; +static struct string_list srcs = {NULL ,0 ,0 ,1 }; +static struct string_list origins = {NULL ,0 ,0 ,1 };static int handle_line (char *line) {
@@ -83,6 +47,7 @@ static int handle_line(char *line)unsigned char *sha1;char *src, *origin;struct src_data *src_data; +struct string_list_item *item;int pulling_head =0 ;if (len <43 || line[40 ] !='\t' )
@@ -115,64 +80,62 @@ static int handle_line(char *line) pulling_head =1 ; } - i =find_in_list (&srcs, src); -if (i <0 ) { - i = srcs.nr; -append_to_list (&srcs,xstrdup (src), -xcalloc (1 ,sizeof (struct src_data ))); + item =unsorted_string_list_lookup (&srcs, src); +if (!item) { + item =string_list_append (src, &srcs); + item->util =xcalloc (1 ,sizeof (struct src_data )); +init_src_data (item->util); } - src_data = srcs.payload[i]; + src_data = item->util;if (pulling_head) { - origin =xstrdup (src); + origin = src; src_data->head_status |=1 ; }else if (!prefixcmp (line,"branch " )) { - origin =xstrdup (line +7 ); -append_to_list (&src_data->branch, origin,NULL ); + origin = line +7 ; +string_list_append (origin, &src_data->branch); src_data->head_status |=2 ; }else if (!prefixcmp (line,"tag " )) { origin = line; -append_to_list (&src_data->tag,xstrdup (origin +4 ),NULL ); +string_list_append (origin +4 , &src_data->tag); src_data->head_status |=2 ; }else if (!prefixcmp (line,"remote branch " )) { - origin =xstrdup (line +14 ); -append_to_list (&src_data->r_branch, origin,NULL ); + origin = line +14 ; +string_list_append (origin, &src_data->r_branch); src_data->head_status |=2 ; }else { - origin =xstrdup (src); -append_to_list (&src_data->generic,xstrdup (line),NULL ); + origin = src; +string_list_append (line, &src_data->generic); src_data->head_status |=2 ; }if (!strcmp ("." , src) || !strcmp (src, origin)) {int len =strlen (origin); -if (origin[0 ] =='\'' && origin[len -1 ] =='\'' ) { +if (origin[0 ] =='\'' && origin[len -1 ] =='\'' ) origin =xmemdupz (origin +1 , len -2 ); - }else { - origin =xstrdup (origin); - } }else {char *new_origin =xmalloc (strlen (origin) +strlen (src) +5 );sprintf (new_origin,"%s of %s" , origin, src); origin = new_origin; } -append_to_list (&origins, origin, sha1); +string_list_append (origin, &origins)->util = sha1;return 0 ; }static void print_joined (const char *singular,const char *plural, -struct list *list,struct strbuf *out) +struct string_list *list,struct strbuf *out) {if (list->nr ==0 )return ;if (list->nr ==1 ) { -strbuf_addf (out,"%s%s" , singular, list->list[0 ]); +strbuf_addf (out,"%s%s" , singular, list->items[0 ].string); }else {int i;strbuf_addstr (out, plural);for (i =0 ; i < list->nr -1 ; i++) -strbuf_addf (out,"%s%s" , i >0 ?", " :"" , list->list[i]); -strbuf_addf (out," and %s" , list->list[list->nr -1 ]); +strbuf_addf (out,"%s%s" , i >0 ?", " :"" , + list->items[i].string); +strbuf_addf (out," and %s" , list->items[list->nr -1 ].string); } }
@@ -183,7 +146,7 @@ static void shortlog(const char *name, unsigned char *sha1,int i, count =0 ;struct commit *commit;struct object *branch; -struct list subjects = {NULL ,NULL ,0 ,0 }; +struct string_list subjects = {NULL ,0 ,0 ,1 };int flags =UNINTERESTING |TREESAME |SEEN |SHOWN |ADDED ;struct strbuf sb =STRBUF_INIT ;
@@ -213,12 +176,10 @@ static void shortlog(const char *name, unsigned char *sha1,strbuf_ltrim (&sb);if (!sb.len) -append_to_list (&subjects,xstrdup (sha1_to_hex ( - commit->object.sha1)), -NULL ); +string_list_append (sha1_to_hex (commit->object.sha1), + &subjects);else -append_to_list (&subjects,strbuf_detach (&sb,NULL ), -NULL ); +string_list_append (strbuf_detach (&sb,NULL ), &subjects); }if (count > limit)
@@ -230,7 +191,7 @@ static void shortlog(const char *name, unsigned char *sha1,if (i >= limit)strbuf_addf (out," ...\n" );else -strbuf_addf (out," %s\n" , subjects.list[i]); +strbuf_addf (out," %s\n" , subjects.items[i].string);clear_commit_marks ((struct commit *)branch, flags);clear_commit_marks (head, flags);
@@ -238,7 +199,7 @@ static void shortlog(const char *name, unsigned char *sha1, rev->commits =NULL ; rev->pending.nr =0 ; -free_list (&subjects); +string_list_clear (&subjects,0 ); }int fmt_merge_msg (int merge_summary,struct strbuf *in,struct strbuf *out) {
@@ -273,14 +234,14 @@ int fmt_merge_msg(int merge_summary, struct strbuf *in, struct strbuf *out) {strbuf_addstr (out,"Merge " );for (i =0 ; i < srcs.nr; i++) { -struct src_data *src_data = srcs.payload[i]; +struct src_data *src_data = srcs.items[i].util;const char *subsep ="" ;strbuf_addstr (out, sep); sep ="; " ;if (src_data->head_status ==1 ) { -strbuf_addstr (out, srcs.list[i]); +strbuf_addstr (out, srcs.items[i].string);continue ; }if (src_data->head_status ==3 ) {
@@ -309,8 +270,8 @@ int fmt_merge_msg(int merge_summary, struct strbuf *in, struct strbuf *out) {print_joined ("commit " ,"commits " , &src_data->generic, out); } -if (strcmp ("." , srcs.list[i])) -strbuf_addf (out," of %s" , srcs.list[i]); +if (strcmp ("." , srcs.items[i].string)) +strbuf_addf (out," of %s" , srcs.items[i].string); }if (!strcmp ("master" , current_branch))
@@ -329,7 +290,7 @@ int fmt_merge_msg(int merge_summary, struct strbuf *in, struct strbuf *out) { rev.limited =1 ;for (i =0 ; i < origins.nr; i++) -shortlog (origins.list[i], origins.payload[i], +shortlog (origins.items[i].string, origins.items[i].util, head, &rev, limit, out); }return 0 ;
Signature · 1 line
1.7.0.3.254.g4503b
Re: [PATCH 6/7] fmt-merge-msg: remove custom string_list implementation
Quoted 3 lines · Stephen Boyd
This command uses a custom version of string list when it could just as easily use the
string_listAPI. Convert it to usestring_listand reduce the code size a bit.
Thanks, although the above is a bit unfair. Back when 00449f9 (Make git-fmt-merge-msg a builtin, 2006-07-03) was written, there was no such thing like string-list (nor path-list, its predecessor).
Quoted 2 lines
Anyone else annoyed that
string_list_append()is the only function that takes doesn't take the string list as the first argument?
Yes.
Quoted 6 lines
On another note, git-compat-util.h:115 says:
#undef
_ALL_SOURCE/* AIX 5.3L defines a struct list with...which may be unnecessary now that struct list is gone. Need someone on AIX 5.3L to test that though.
Yeah, finding testers for less common platforms is always the hardest part.
Quoted 2 lines
Finally, this doesn't free some of the lists since I wanted it to be a straight conversion. I'm feeling lazy right now but I'll think about it.
Thanks.
[PATCH 8/7] Make string_list_append() consistent with everything else
string_list_append() is the only function in the string_list API which takes the struct string_list as the second argument instead of the first. Swap the ordering to make the string_list API consistent.
This was mostly done with
$ git grep -lz 'string_list_append' | xargs -0 perl -pi -e 's/string_list_append\((.*), ([^)]+)\)/string_list_append\($2, $1)/'
and then some minor fixups and manual verification.
---
Quoted 6 lines · Junio C Hamano
Quoted 2 lines · Stephen Boyd
Anyone else annoyed that
string_list_append()is the only function that takes doesn't take the string list as the first argument?Yes.
This swaps it.
Documentation/technical/api-string-list.txt | 4 +- builtin/apply.c | 2 +- builtin/fast-export.c | 4 +- builtin/fetch.c | 8 ++-- builtin/fmt-merge-msg.c | 18 +++++----- builtin/log.c | 20 ++++++------ builtin/remote.c | 46 +++++++++++++------------- builtin/rerere.c | 2 +- builtin/shortlog.c | 2 +- notes.c | 6 ++-- remote.c | 2 +- revision.c | 4 +- string-list.c | 2 +- string-list.h | 2 +- 14 files changed, 61 insertions(+), 61 deletions(-)
Documentation/technical/api-string-list.txt +2 -2
@@ -38,8 +38,8 @@ struct string_list list; int i; memset(&list, 0, sizeof(struct string_list)); -string_list_append("foo", &list); -string_list_append("bar", &list); +string_list_append(&list, "foo"); +string_list_append(&list, "bar"); for (i = 0; i < list.nr; i++) printf("%s\n", list.items[i].string) ----
builtin/apply.c +1 -1
@@ -3404,7 +3404,7 @@ static void add_name_limit(const char *name, int exclude) {struct string_list_item *it; - it =string_list_append (name, &limit_by_name); + it =string_list_append (&limit_by_name, name); it->util = exclude ?NULL : (void *)1 ; }
builtin/fast-export.c +2 -2
@@ -438,7 +438,7 @@ static void get_tags_and_duplicates(struct object_array *pending,/* handle nested tags */ while (tag && tag->object.type ==OBJ_TAG ) {parse_object (tag->object.sha1); -string_list_append (full_name, extra_refs)->util = tag; +string_list_append (extra_refs, full_name)->util = tag; tag = (struct tag *)tag->tagged; }if (!tag)
@@ -464,7 +464,7 @@ static void get_tags_and_duplicates(struct object_array *pending, }if (commit->util)/* more than one name for the same object */ -string_list_append (full_name, extra_refs)->util = commit; +string_list_append (extra_refs, full_name)->util = commit;else commit->util = full_name; }
builtin/fetch.c +4 -4
@@ -745,7 +745,7 @@ static int get_one_remote_for_fetch(struct remote *remote, void *priv) {struct string_list *list = priv;if (!remote->skip_default_update) -string_list_append (remote->name, list); +string_list_append (list, remote->name);return 0 ; }
@@ -764,8 +764,8 @@ static int get_remote_group(const char *key, const char *value, void *priv)int space =strcspn (value," \t\n" );while (*value) {if (space >1 ) { -string_list_append (xstrndup (value, space), - g->list); +string_list_append (g->list, +xstrndup (value, space)); } value += space + (value[space] !='\0' ); space =strcspn (value," \t\n" );
@@ -786,7 +786,7 @@ static int add_remote_or_group(const char *name, struct string_list *list)if (!remote_is_configured (name))return 0 ; remote =remote_get (name); -string_list_append (remote->name, list); +string_list_append (list, remote->name); }return 1 ; }
builtin/fmt-merge-msg.c +9 -9
@@ -82,7 +82,7 @@ static int handle_line(char *line) item =unsorted_string_list_lookup (&srcs, src);if (!item) { - item =string_list_append (src, &srcs); + item =string_list_append (&srcs, src); item->util =xcalloc (1 ,sizeof (struct src_data ));init_src_data (item->util); }
@@ -93,19 +93,19 @@ static int handle_line(char *line) src_data->head_status |=1 ; }else if (!prefixcmp (line,"branch " )) { origin = line +7 ; -string_list_append (origin, &src_data->branch); +string_list_append (&src_data->branch, origin); src_data->head_status |=2 ; }else if (!prefixcmp (line,"tag " )) { origin = line; -string_list_append (origin +4 , &src_data->tag); +string_list_append (&src_data->tag, origin +4 ); src_data->head_status |=2 ; }else if (!prefixcmp (line,"remote branch " )) { origin = line +14 ; -string_list_append (origin, &src_data->r_branch); +string_list_append (&src_data->r_branch, origin); src_data->head_status |=2 ; }else { origin = src; -string_list_append (line, &src_data->generic); +string_list_append (&src_data->generic, line); src_data->head_status |=2 ; }
@@ -118,7 +118,7 @@ static int handle_line(char *line)sprintf (new_origin,"%s of %s" , origin, src); origin = new_origin; } -string_list_append (origin, &origins)->util = sha1; +string_list_append (&origins, origin)->util = sha1;return 0 ; }
@@ -176,10 +176,10 @@ static void shortlog(const char *name, unsigned char *sha1,strbuf_ltrim (&sb);if (!sb.len) -string_list_append (sha1_to_hex (commit->object.sha1), - &subjects); +string_list_append (&subjects, +sha1_to_hex (commit->object.sha1));else -string_list_append (strbuf_detach (&sb,NULL ), &subjects); +string_list_append (&subjects,strbuf_detach (&sb,NULL )); }if (count > limit)
builtin/log.c +10 -10
@@ -497,13 +497,13 @@ static void add_header(const char *value) len--;if (!strncasecmp (value,"to: " ,4 )) { - item =string_list_append (value +4 , &extra_to); + item =string_list_append (&extra_to, value +4 ); len -=4 ; }else if (!strncasecmp (value,"cc: " ,4 )) { - item =string_list_append (value +4 , &extra_cc); + item =string_list_append (&extra_cc, value +4 ); len -=4 ; }else { - item =string_list_append (value, &extra_hdr); + item =string_list_append (&extra_hdr, value); } item->string[len] ='\0' ;
@@ -527,13 +527,13 @@ static int git_format_config(const char *var, const char *value, void *cb)if (!strcmp (var,"format.to" )) {if (!value)return config_error_nonbool (var); -string_list_append (value, &extra_to); +string_list_append (&extra_to, value);return 0 ; }if (!strcmp (var,"format.cc" )) {if (!value)return config_error_nonbool (var); -string_list_append (value, &extra_cc); +string_list_append (&extra_cc, value);return 0 ; }if (!strcmp (var,"diff.color" ) || !strcmp (var,"color.diff" )) {
@@ -911,7 +911,7 @@ static int to_callback(const struct option *opt, const char *arg, int unset)if (unset)string_list_clear (&extra_to,0 );else -string_list_append (arg, &extra_to); +string_list_append (&extra_to, arg);return 0 ; }
@@ -920,7 +920,7 @@ static int cc_callback(const struct option *opt, const char *arg, int unset)if (unset)string_list_clear (&extra_cc,0 );else -string_list_append (arg, &extra_cc); +string_list_append (&extra_cc, arg);return 0 ; }
@@ -1194,7 +1194,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) rev.ref_message_ids =xcalloc (1 ,sizeof (struct string_list ));if (in_reply_to) {const char *msgid =clean_message_id (in_reply_to); -string_list_append (msgid, rev.ref_message_ids); +string_list_append (rev.ref_message_ids, msgid); } rev.numbered_files = numbered_files; rev.patch_suffix = fmt_patch_suffix;
@@ -1241,8 +1241,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) && (!cover_letter || rev.nr > 1))free (rev.message_id); else - string_list_append(rev.message_id, - rev.ref_message_ids); + string_list_append(rev.ref_message_ids, + rev.message_id); }gen_message_id (&rev,sha1_to_hex (commit->object.sha1)); }
builtin/remote.c +23 -23
148 lines not on this page · raw message
builtin/rerere.c +1 -1
@@ -59,7 +59,7 @@ static void garbage_collect(struct string_list *rr) cutoff = (has_rerere_resolution (e->d_name) ? cutoff_resolve : cutoff_noresolve);if (then < now - cutoff *86400 ) -string_list_append (e->d_name, &to_remove); +string_list_append (&to_remove, e->d_name); }for (i =0 ; i < to_remove.nr; i++)unlink_rr_item (to_remove.items[i].string);
builtin/shortlog.c +1 -1
@@ -115,7 +115,7 @@ static void insert_one_record(struct shortlog *log, } } -string_list_append (buffer, item->util); +string_list_append (item->util, buffer); }static void read_from_stdin (struct shortlog *log)
notes.c +3 -3
@@ -838,7 +838,7 @@ static int string_list_add_one_ref(const char *path, const unsigned char *sha1, {struct string_list *refs = cb;if (!unsorted_string_list_has_string (refs, path)) -string_list_append (path, refs); +string_list_append (refs, path);return 0 ; }
@@ -851,7 +851,7 @@ void string_list_add_refs_by_glob(struct string_list *list, const char *glob)if (get_sha1 (glob, sha1))warning ("notes ref %s is invalid" , glob);if (!unsorted_string_list_has_string (list, glob)) -string_list_append (glob, list); +string_list_append (list, glob); } }
@@ -983,7 +983,7 @@ void init_display_notes(struct display_notes_opt *opt)assert (!display_notes_trees);if (!opt || !opt->suppress_default_notes) { -string_list_append (default_notes_ref (), &display_notes_refs); +string_list_append (&display_notes_refs,default_notes_ref ()); display_ref_env =getenv (GIT_NOTES_DISPLAY_REF_ENVIRONMENT );if (display_ref_env) { string_list_add_refs_from_colon_sep(&display_notes_refs,
remote.c +1 -1
@@ -1709,7 +1709,7 @@ struct ref *get_stale_heads(struct remote *remote, struct ref *fetch_map) info.ref_names = &ref_names; info.stale_refs_tail = &stale_refs;for (ref = fetch_map; ref; ref = ref->next) -string_list_append (ref->name, &ref_names); +string_list_append (&ref_names, ref->name);sort_string_list (&ref_names);for_each_ref (get_stale_heads_cb, &info);string_list_clear (&ref_names,0 );
revision.c +2 -2
@@ -1205,8 +1205,8 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **argelse strbuf_addstr (&buf,"refs/notes/" );strbuf_addstr (&buf, arg+13 ); -string_list_append (strbuf_detach (&buf,NULL ), - revs->notes_opt.extra_notes_refs); +string_list_append (revs->notes_opt.extra_notes_refs, +strbuf_detach (&buf,NULL )); }else if (!strcmp (arg,"--no-notes" )) { revs->show_notes =0 ; revs->show_notes_given =1 ;
string-list.c +1 -1
@@ -148,7 +148,7 @@ void print_string_list(const char *text, const struct string_list *p)printf ("%s:%p\n" , p->items[i].string, p->items[i].util); } -struct string_list_item *string_list_append (const char *string,struct string_list *list) +struct string_list_item *string_list_append (struct string_list *list,const char *string) {ALLOC_GROW (list->items, list->nr +1 , list->alloc); list->items[list->nr].string =
string-list.h +1 -1
@@ -35,7 +35,7 @@ struct string_list_item *string_list_insert_at_index(int insert_at,struct string_list_item *string_list_lookup (const char *string,struct string_list *list);/* Use these functions only on unsorted lists: */ -struct string_list_item *string_list_append (const char *string,struct string_list *list); +struct string_list_item *string_list_append (struct string_list *list,const char *string);void sort_string_list (struct string_list *list);int unsorted_string_list_has_string (struct string_list *list,const char *string); struct string_list_item *unsorted_string_list_lookup(struct string_list *list,
Signature · 1 line
1.7.0.3.313.g87b3c
Re: [PATCH 8/7] Make string_list_append() consistent with everything else
Quoted 5 lines · Stephen Boyd
string_list_append()is the only function in thestring_listAPI which takes
the structstring_listas the second argument instead of the first. Swap the
ordering to make thestring_listAPI consistent.
The only function? It doesn't seem that way ...
jp3@rayne: git(pu)>grep '(' string-list.h | grep -v '(\(const \)*struct string_list'
void print_string_list(const char *text, const struct string_list *p); typedef void (*string_list_clear_func_t)(void *p, const char *str); int for_each_string_list(string_list_each_func_t,
struct string_list_item *string_list_insert(const char *string, struct string_list *list);
struct string_list_item *string_list_insert_at_index(int insert_at, struct string_list_item *string_list_lookup(const char *string, struct string_list *list);
struct string_list_item *string_list_append(const char *string, struct string_list *list);
I don't think that swapping the argument order for append is wrong, but it doesn't seem to be the only function that doesn't take the list as the first argument ... or am I missing something? (probably am)
Signature · 1 line
Julian
Re: [PATCH 6/7] fmt-merge-msg: remove custom string_list implementation
In reply to Junio C HamanoQuoted 10 lines · Junio C Hamano
Quoted 4 lines · Stephen Boyd
This command uses a custom version of string list when it could just as easily use the
string_listAPI. Convert it to usestring_listand reduce the code size a bit.Thanks, although the above is a bit unfair. Back when 00449f9 (Make git-fmt-merge-msg a builtin, 2006-07-03) was written, there was no such thing like string-list (nor path-list, its predecessor).
Sorry, I didn't mean to be misleading. Maybe something like:
This command uses a custom version of string_list since back when it was written 00449f9 (Make git-fmt-merge-msg a builtin, 2006-07-03) there was no string_list API (nor path_list, its predecessor). Convert it to use string_list and reduce the code size a bit.
PATCH 7/7 fmt-merge-msg: hide summary option
In reply to Stephen BoydThe --summary command line option has been deprecated in favor of --log. Hide the option from the help message to further discourage the use of this option.
---
When is this option going to be removed? It's approaching 2 years since the deprecation occured in 6cd9cfe (fmt-merge-msg: add '--(no-)log' options and 'merge.log' config variable, 2008-04-06)
builtin/fmt-merge-msg.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
builtin/fmt-merge-msg.c +3 -1
@@ -301,7 +301,9 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)const char *inpath =NULL ;struct option options[] = {OPT_BOOLEAN (0 ,"log" , &merge_summary,"populate log with the shortlog" ), -OPT_BOOLEAN (0 ,"summary" , &merge_summary,"alias for --log" ), + {OPTION_BOOLEAN ,0 ,"summary" , &merge_summary,NULL , +"alias for --log (deprecated)" , +PARSE_OPT_NOARG |PARSE_OPT_HIDDEN },OPT_FILENAME ('F' ,"file" , &inpath,"file to read from" ),OPT_END () };
Signature · 1 line
1.7.0.3.254.g4503b
Re: [PATCH 7/7] fmt-merge-msg: hide summary option
Quoted 3 lines · Stephen Boyd
When is this option going to be removed? It's approaching 2 years since the deprecation occured in 6cd9cfe (fmt-merge-msg: add '--(no-)log' options and 'merge.log' config variable, 2008-04-06)
We could do that sometime in this autumn timeframe if we start making noises when they are used, just like we did during the 1.7.0 transition against soon-to-be-deprecated "features".
Are there other ancient features we have been passively advertising as deprecated that we should now start the removal process?
Re: [PATCH 7/7] fmt-merge-msg: hide summary option
Quoted 3 lines · Junio C Hamano
We could do that sometime in this autumn timeframe if we start making noises when they are used, just like we did during the 1.7.0 transition against soon-to-be-deprecated "features".
We already make noises when the option is used. Probably need to make some noises in release notes though.
Quoted 2 lines
Are there other ancient features we have been passively advertising as deprecated that we should now start the removal process?
grepping for deprecated shows mostly deprecated commands:
git lost-found
git tar-tree
git peek-remote (synonym to git ls-remote)
git init-db (synonym to git init)
git repo-config (synonym to git config)
I'm pretty sure we don't want to remove them anytime soon though, right?
The only option of interest is 'git reset --mixed' with paths. I don't really know the backstory on that but it looks like it was deprecated when the command was made into a builtin 0e5a7fa (Make "git reset" a builtin., 2007-09-11). Maybe it can become a die now?
Oh and git notes has a deprecation warning but I think we'll probably have to revisit that one in a few years.
Re: [PATCH 7/7] fmt-merge-msg: hide summary option
Quoted 7 lines · Stephen Boyd
Quoted 3 lines · Junio C Hamano
We could do that sometime in this autumn timeframe if we start making noises when they are used, just like we did during the 1.7.0 transition against soon-to-be-deprecated "features".
We already make noises when the option is used. Probably need to make some noises in release notes though.
Then it would be one of the 1.7.2 items, I guess, as we haven't shipped 1.7.1 yet.