transport-helper: updates
v3 cover transport-helper: updates
Hi,
Here are the patches that allow transport helpers to be completely transparent; renaming branches, deleting them, custom refspecs, --force, --dry-run, reporting forced update, everything works.
Some of these were were sent before and rejected without a reason, but here they are again in case anybody is interested.
Diff from v2:
transport-helper.c +4 -2
@@ -821,8 +821,10 @@ static int push_refs_with_export(struct transport *transport,die ("helper %s does not support dry-run" , data->name); } -if (flags &TRANSPORT_PUSH_FORCE ) -set_helper_option (transport,"force" ,"true" ); +if (flags &TRANSPORT_PUSH_FORCE ) { +if (set_helper_option (transport,"force" ,"true" ) !=0 ) +die ("helper %s does not support 'force'" , data->name); + } helper =get_helper (transport);
Felipe Contreras (10):
transport-helper: add 'force' to 'export' helpers
transport-helper: fix extra lines
transport-helper: check for 'forced update' message
fast-export: improve argument parsing
fast-export: add new --refspec option
transport-helper: add support for old:new refspec
fast-import: add support to delete refs
fast-export: add support to delete refs
transport-helper: add support to delete branches
transport-helper: don't update refs in dry-run
Documentation/git-fast-export.txt | 4 ++++ Documentation/git-fast-import.txt | 3 +++ builtin/fast-export.c | 47 ++++++++++++++++++++++++++++++++++++++- fast-import.c | 13 ++++++++--- t/t5801-remote-helpers.sh | 10 ++++++++- t/t9300-fast-import.sh | 18 +++++++++++++++ t/t9350-fast-export.sh | 18 +++++++++++++++ transport-helper.c | 44 ++++++++++++++++++++++++++---------- 8 files changed, 140 insertions(+), 17 deletions(-)
Signature · 1 line
1.8.4-fc
PATCH v3 1/10 transport-helper: add 'force' to 'export' helpers
Otherwise they cannot know when to force the push or not (other than hacks).
--- transport-helper.c | 5 +++++ 1 file changed, 5 insertions(+)
transport-helper.c +5 -0
@@ -814,6 +814,11 @@ static int push_refs_with_export(struct transport *transport,die ("helper %s does not support dry-run" , data->name); } +if (flags &TRANSPORT_PUSH_FORCE ) { +if (set_helper_option (transport,"force" ,"true" ) !=0 ) +die ("helper %s does not support 'force'" , data->name); + } + helper =get_helper (transport);write_constant (helper->in,"export\n" );
Signature · 1 line
1.8.4-fc
PATCH v3 2/10 transport-helper: fix extra lines
In reply to Felipe ContrerasCommit 9c51558 (transport-helper: trivial code shuffle) moved these lines above, but 99d9ec0 (Merge branch 'fc/transport-helper-no-refspec') had a wrong merge conflict and readded them.
--- transport-helper.c | 3 --- 1 file changed, 3 deletions(-)
transport-helper.c +0 -3
@@ -840,9 +840,6 @@ static int push_refs_with_export(struct transport *transport, }free (private); -if (ref->deletion) -die ("remote-helpers do not support ref deletion" ); -if (ref->peer_ref) {if (strcmp (ref->peer_ref->name, ref->name))die ("remote-helpers do not support old:new syntax" );
Signature · 1 line
1.8.4-fc
PATCH v3 3/10 transport-helper: check for 'forced update' message
In reply to Felipe ContrerasSo the remote-helpers can tell us when a forced push was needed.
--- transport-helper.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
transport-helper.c +7 -1
@@ -630,7 +630,7 @@ static int push_update_ref_status(struct strbuf *buf, struct ref *remote_refs) {char *refname, *msg; -int status; +int status, forced =0 ;if (!prefixcmp (buf->buf,"ok " )) { status =REF_STATUS_OK ;
@@ -683,6 +683,11 @@ static int push_update_ref_status(struct strbuf *buf,free (msg); msg =NULL ; } +else if (!strcmp (msg,"forced update" )) { + forced =1 ; +free (msg); + msg =NULL ; + } }if (*ref)
@@ -704,6 +709,7 @@ static int push_update_ref_status(struct strbuf *buf, } (*ref)->status = status; + (*ref)->forced_update = forced; (*ref)->remote_status = msg;return !(status ==REF_STATUS_OK ); }
Signature · 1 line
1.8.4-fc
PATCH v3 4/10 fast-export: improve argument parsing
In reply to Felipe ContrerasWe don't want to pass arguments specific to fast-export to setup_revisions.
--- builtin/fast-export.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
builtin/fast-export.c +2 -1
@@ -694,8 +694,9 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) revs.topo_order =1 ; revs.show_source =1 ; revs.rewrite_parents =1 ; + argc =parse_options (argc, argv, prefix, options, fast_export_usage, +PARSE_OPT_KEEP_ARGV0 |PARSE_OPT_KEEP_UNKNOWN ); argc =setup_revisions (argc, argv, &revs,NULL ); - argc =parse_options (argc, argv, prefix, options, fast_export_usage,0 );if (argc >1 )usage_with_options (fast_export_usage, options);
Signature · 1 line
1.8.4-fc
PATCH v3 5/10 fast-export: add new --refspec option
In reply to Felipe ContrerasSo that we can covert the exported ref names.
--- Documentation/git-fast-export.txt | 4 ++++ builtin/fast-export.c | 30 ++++++++++++++++++++++++++++++ t/t9350-fast-export.sh | 7 +++++++ 3 files changed, 41 insertions(+)
Documentation/git-fast-export.txt +4 -0
@@ -105,6 +105,10 @@ marks the same across runs. in the commit (as opposed to just listing the files which are different from the commit's first parent). +--refspec:: + Apply the specified refspec to each ref exported. Multiple of them can + be specified. + [<git-rev-list-args>...]:: A list of arguments, acceptable to 'git rev-parse' and 'git rev-list', that specifies the specific objects and references
builtin/fast-export.c +30 -0
@@ -17,6 +17,7 @@#include "utf8.h" #include "parse-options.h" #include "quote.h" +#include "remote.h" static const char *fast_export_usage[] = {N_ ("git fast-export [rev-list-opts]" ),
@@ -30,6 +31,8 @@ static int fake_missing_tagger;static int use_done_feature;static int no_data;static int full_tree; +static struct refspec *refspecs; +static int refspecs_nr;static int parse_opt_signed_tag_mode (const struct option *opt,const char *arg,int unset)
@@ -502,6 +505,15 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info,if (dwim_ref (e->name,strlen (e->name), sha1, &full_name) !=1 )continue ; +if (refspecs) { +char *private; + private =apply_refspecs (refspecs, refspecs_nr, full_name); +if (private) { +free (full_name); + full_name = private; + } + } +switch (e->item->type) {case OBJ_COMMIT : commit = (struct commit *)e->item;
@@ -661,6 +673,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)struct commit *commit;char *export_filename =NULL , *import_filename =NULL ;uint32_t lastimportid; +struct string_list refspecs_list;struct option options[] = {OPT_INTEGER (0 ,"progress" , &progress,N_ ("show progress after <n> objects" )),
@@ -681,6 +694,8 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)OPT_BOOLEAN (0 ,"use-done-feature" , &use_done_feature,N_ ("Use the done feature to terminate the stream" )),OPT_BOOL (0 ,"no-data" , &no_data,N_ ("Skip output of blob data" )), +OPT_STRING_LIST (0 ,"refspec" , &refspecs_list,N_ ("refspec" ), +N_ ("Apply refspec to exported refs" )), OPT_END() };
@@ -700,6 +715,19 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)if (argc >1 )usage_with_options (fast_export_usage, options); +if (refspecs_list.nr) { +const char *refspecs_str[refspecs_list.nr]; +int i; + +for (i =0 ; i < refspecs_list.nr; i++) + refspecs_str[i] = refspecs_list.items[i].string; + + refspecs_nr = refspecs_list.nr; + refspecs =parse_fetch_refspec (refspecs_nr, refspecs_str); + +string_list_clear (&refspecs_list,1 ); + } +if (use_done_feature)printf ("feature done\n" );
@@ -734,5 +762,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)if (use_done_feature)printf ("done\n" ); +free_refspec (refspecs_nr, refspecs); +return 0 ; }
t/t9350-fast-export.sh +7 -0
@@ -504,4 +504,11 @@ test_expect_success 'refs are updated even if no commits need to be exported' ' test_cmp expected actual ' +test_expect_success 'use refspec' ' + git fast-export --refspec refs/heads/master:refs/heads/foobar master | \ + grep "^commit " | sort | uniq > actual && + echo "commit refs/heads/foobar" > expected && + test_cmp expected actual +' + test_done
Signature · 1 line
1.8.4-fc
Re: [PATCH v3 05/10] fast-export: add new --refspec option
Quoted 1 line · Felipe Contreras
So that we can covert the exported ref names.
s/covert/convert/ [1]
[1]: http://thread.gmane.org/gmane.comp.version-control.git/225475/focus=225489
Quoted 1 line
Signed-off-by Felipe Contreras <[email protected]>
PATCH v3 6/10 transport-helper: add support for old:new refspec
In reply to Felipe ContrerasBy using fast-export's new --refspec option.
--- t/t5801-remote-helpers.sh | 2 +- transport-helper.c | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-)
t/t5801-remote-helpers.sh +1 -1
@@ -87,7 +87,7 @@ test_expect_success 'push new branch by name' ' compare_refs local HEAD server refs/heads/new-name ' -test_expect_failure 'push new branch with old:new refspec' ' +test_expect_success 'push new branch with old:new refspec' ' (cd local && git push origin new-name:new-refspec ) &&
transport-helper.c +10 -3
@@ -809,7 +809,7 @@ static int push_refs_with_export(struct transport *transport,struct ref *ref;struct child_process *helper, exporter;struct helper_data *data = transport->data; -struct string_list revlist_args =STRING_LIST_INIT_NODUP ; +struct string_list revlist_args =STRING_LIST_INIT_DUP ;struct strbuf buf =STRBUF_INIT ;if (!data->refspecs)
@@ -847,8 +847,13 @@ static int push_refs_with_export(struct transport *transport,free (private);if (ref->peer_ref) { -if (strcmp (ref->peer_ref->name, ref->name)) -die ("remote-helpers do not support old:new syntax" ); +if (strcmp (ref->name, ref->peer_ref->name)) { +struct strbuf buf =STRBUF_INIT ; +strbuf_addf (&buf,"%s:%s" , ref->peer_ref->name, ref->name); +string_list_append (&revlist_args,"--refspec" ); +string_list_append (&revlist_args, buf.buf); +strbuf_release (&buf); + }string_list_append (&revlist_args, ref->peer_ref->name); } }
@@ -856,6 +861,8 @@ static int push_refs_with_export(struct transport *transport,if (get_exporter (transport, &exporter, &revlist_args))die ("Couldn't run fast-export" ); +string_list_clear (&revlist_args,1 ); +if (finish_command (&exporter))die ("Error while running fast-export" );push_update_refs_status (data, remote_refs);
Signature · 1 line
1.8.4-fc
PATCH v3 7/10 fast-import: add support to delete refs
In reply to Felipe Contreras--- Documentation/git-fast-import.txt | 3 +++ fast-import.c | 13 ++++++++++--- t/t9300-fast-import.sh | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-)
Documentation/git-fast-import.txt +3 -0
@@ -483,6 +483,9 @@ Marks must be declared (via `mark`) before they can be used. * Any valid Git SHA-1 expression that resolves to a commit. See ``SPECIFYING REVISIONS'' in linkgit:gitrevisions[7] for details. +* The special null SHA-1 (40 zeros) specifices that the branch is to be + removed. + The special case of restarting an incremental import from the current branch value should be written as: ----
fast-import.c +10 -3
@@ -248,6 +248,7 @@ struct branch {uintmax_t last_commit;uintmax_t num_notes; unsigned active : 1; + unsigned delete : 1; unsigned pack_id : PACK_ID_BITS;unsigned char sha1[20 ]; };
@@ -1674,10 +1675,13 @@ static int update_branch(struct branch *b)struct ref_lock *lock;unsigned char old_sha1[20 ]; -if (is_null_sha1 (b->sha1)) -return 0 ;if (read_ref (b->name, old_sha1))hashclr (old_sha1); +if (is_null_sha1 (b->sha1)) { +if (b->delete) +delete_ref (b->name, old_sha1,0 ); +return 0 ; + } lock =lock_any_ref_for_update (b->name, old_sha1,0 );if (!lock)return error ("Unable to lock %s" , b->name);
@@ -2604,8 +2608,11 @@ static int parse_from(struct branch *b)free (buf); }else parse_from_existing (b); - }else if (!get_sha1 (from, b->sha1)) + }else if (!get_sha1 (from, b->sha1)) {parse_from_existing (b); +if (is_null_sha1 (b->sha1)) + b->delete =1 ; + }else die ("Invalid ref name or SHA1 expression: %s" , from);
t/t9300-fast-import.sh +18 -0
@@ -2934,4 +2934,22 @@ test_expect_success 'S: ls with garbage after sha1 must fail' ' test_i18ngrep "space after tree-ish" err ' +test_expect_success 'T: delete branch' ' + git branch to-delete && + git fast-import <<-EOF && + reset refs/heads/to-delete + from 0000000000000000000000000000000000000000 + EOF + test_must_fail git rev-parse --verify refs/heads/to-delete +' + +test_expect_success 'T: empty reset doesnt delete branch' ' + git branch not-to-delete && + git fast-import <<-EOF && + reset refs/heads/not-to-delete + EOF + git show-ref && + git rev-parse --verify refs/heads/not-to-delete +' + test_done
Signature · 1 line
1.8.4-fc
PATCH v3 8/10 fast-export: add support to delete refs
In reply to Felipe Contreras--- builtin/fast-export.c | 14 ++++++++++++++ t/t9350-fast-export.sh | 11 +++++++++++ 2 files changed, 25 insertions(+)
builtin/fast-export.c +14 -0
@@ -665,6 +665,19 @@ static void import_marks(char *input_file)fclose (f); } +static void handle_deletes (void ) +{ +int i; +for (i =0 ; i < refspecs_nr; i++) { +struct refspec *refspec = &refspecs[i]; +if (*refspec->src) +continue ; + +printf ("reset %s\nfrom %s\n\n" , + refspec->dst,sha1_to_hex (null_sha1)); + } +} +int cmd_fast_export (int argc,const char **argv,const char *prefix) {struct rev_info revs;
@@ -755,6 +768,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) }handle_tags_and_duplicates (&extra_refs); +handle_deletes ();if (export_filename && lastimportid != last_idnum)export_marks (export_filename);
t/t9350-fast-export.sh +11 -0
@@ -511,4 +511,15 @@ test_expect_success 'use refspec' ' test_cmp expected actual ' +test_expect_success 'delete refspec' ' + git branch to-delete && + git fast-export --refspec :refs/heads/to-delete to-delete ^to-delete > actual && + cat > expected <<-EOF && + reset refs/heads/to-delete + from 0000000000000000000000000000000000000000 + + EOF + test_cmp expected actual +' + test_done
Signature · 1 line
1.8.4-fc
PATCH v3 9/10 transport-helper: add support to delete branches
In reply to Felipe ContrerasFor remote-helpers that use 'export' to push.
--- t/t5801-remote-helpers.sh | 8 ++++++++ transport-helper.c | 8 ++++++-- 2 files changed, 14 insertions(+), 2 deletions(-)
t/t5801-remote-helpers.sh +8 -0
@@ -94,6 +94,14 @@ test_expect_success 'push new branch with old:new refspec' ' compare_refs local HEAD server refs/heads/new-refspec ' +test_expect_success 'push delete branch' ' + (cd local && + git push origin :new-name + ) && + test_must_fail git --git-dir="server/.git" \ + rev-parse --verify refs/heads/new-name +' + test_expect_success 'cloning without refspec' ' GIT_REMOTE_TESTGIT_REFSPEC="" \ git clone "testgit::${PWD}/server" local2 2>error &&
transport-helper.c +6 -2
@@ -849,12 +849,16 @@ static int push_refs_with_export(struct transport *transport,if (ref->peer_ref) {if (strcmp (ref->name, ref->peer_ref->name)) {struct strbuf buf =STRBUF_INIT ; -strbuf_addf (&buf,"%s:%s" , ref->peer_ref->name, ref->name); +if (!ref->deletion) +strbuf_addf (&buf,"%s:%s" , ref->peer_ref->name, ref->name); +else +strbuf_addf (&buf,":%s" , ref->name);string_list_append (&revlist_args,"--refspec" );string_list_append (&revlist_args, buf.buf);strbuf_release (&buf); } -string_list_append (&revlist_args, ref->peer_ref->name); +if (!ref->deletion) +string_list_append (&revlist_args, ref->peer_ref->name); } }
Signature · 1 line
1.8.4-fc
[PATCH v3 11/10] fixup! transport-helper: add support to delete branches
Patch 2/10 (transport-helper: fix extra lines) deleted one copy of the lines; patch 9/10 (transport-helper: add support to delete branches) should delete the other copy of the lines.
--- transport-helper.c | 3 --- 1 file changed, 3 deletions(-)
transport-helper.c +0 -3
@@ -878,9 +878,6 @@ static int push_refs_with_export(struct transport *transport,char *private;unsigned char sha1[20 ]; -if (ref->deletion) -die ("remote-helpers do not support ref deletion" ); - private =apply_refspecs (data->refspecs, data->refspec_nr, ref->name);if (private && !get_sha1 (private, sha1)) {strbuf_addf (&buf,"^%s" , private);
Signature · 1 line
1.8.4.1
Re: [PATCH v3 11/10] fixup! transport-helper: add support to delete branches
Quoted 3 lines · Richard Hansen
Patch 2/10 (transport-helper: fix extra lines) deleted one copy of the lines; patch 9/10 (transport-helper: add support to delete branches) should delete the other copy of the lines.
Looks awfully familiar to:
http://article.gmane.org/gmane.comp.version-control.git/235973
But since the project does have double standards, you might have better luck by simply not using my name.
Signature · 1 line
Felipe Contreras
Re: [PATCH v3 11/10] fixup! transport-helper: add support to delete branches
Quoted 11 lines · Felipe Contreras
Quoted 3 lines · Richard Hansen
Patch 2/10 (transport-helper: fix extra lines) deleted one copy of the lines; patch 9/10 (transport-helper: add support to delete branches) should delete the other copy of the lines.
Looks awfully familiar to:
http://article.gmane.org/gmane.comp.version-control.git/235973
But since the project does have double standards, you might have better luck by simply not using my name.
Ahh, nevermind, it's a fix on top of my patch. I actually found this and fixed it on my local branch, but didn't push it. Now I have.
https://github.com/felipec/git/commit/4820caafc1f0b9e346b369bb2bc2b7bfdc8a1957
Signature · 1 line
Felipe Contreras
PATCH v3 10/10 transport-helper: don't update refs in dry-run
In reply to Felipe ContrerasThe remote helper namespace should not be updated.
--- transport-helper.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
transport-helper.c +5 -4
@@ -715,7 +715,8 @@ static int push_update_ref_status(struct strbuf *buf, }static void push_update_refs_status (struct helper_data *data, -struct ref *remote_refs) +struct ref *remote_refs, +int flags) {struct strbuf buf =STRBUF_INIT ;struct ref *ref = remote_refs;
@@ -729,7 +730,7 @@ static void push_update_refs_status(struct helper_data *data,if (push_update_ref_status (&buf, &ref, remote_refs))continue ; -if (!data->refspecs) +if (flags &TRANSPORT_PUSH_DRY_RUN || !data->refspecs)continue ;/* propagate back the update to the remote namespace */
@@ -799,7 +800,7 @@ static int push_refs_with_push(struct transport *transport,sendline (data, &buf);strbuf_release (&buf); -push_update_refs_status (data, remote_refs); +push_update_refs_status (data, remote_refs, flags);return 0 ; }
@@ -869,7 +870,7 @@ static int push_refs_with_export(struct transport *transport,if (finish_command (&exporter))die ("Error while running fast-export" ); -push_update_refs_status (data, remote_refs); +push_update_refs_status (data, remote_refs, flags);return 0 ; }
Signature · 1 line
1.8.4-fc
Quoted 5 lines · Felipe Contreras
Hi,
Here are the patches that allow transport helpers to be completely transparent; renaming branches, deleting them, custom refspecs, --force, --dry-run, reporting forced update, everything works.
These patches don't cleanly apply to master anymore; would you be willing to rebase and post a new version?
I wanted to test these changes via git-remote-bzr on a bzr repository I'm working on, but unfortunately git-remote-bzr doesn't yet support force pushes. I may look into adding force push support to git-remote-bzr, unless you beat me to it. :)
In general these patches look good to me and I'd like to see them merged to master.
Thanks,
Richard