transport-helper: updates
v7 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.
Changes since v6:
contrib/remote-helpers/test-hg.sh +2 -2
@@ -599,7 +599,7 @@ test_expect_success 'remote big push fetch first' ' ) ' -test_expect_failure 'remote big push force' ' +test_expect_success 'remote big push force' ' test_when_finished "rm -rf hgrepo gitrepo*" && setup_big_push
@@ -629,7 +629,7 @@ test_expect_failure 'remote big push force' ' check_bookmark hgrepo new_bmark six ' -test_expect_failure 'remote big push dry-run' ' +test_expect_success 'remote big push dry-run' ' test_when_finished "rm -rf hgrepo gitrepo*" && setup_big_push
transport-helper.c +1 -1
@@ -863,7 +863,7 @@ static int push_refs_with_export(struct transport *transport,if (flags &TRANSPORT_PUSH_FORCE ) {if (set_helper_option (transport,"force" ,"true" ) !=0 ) -die ("helper %s does not support 'force'" , data->name); +warning ("helper %s does not support 'force'" , data->name); } helper =get_helper (transport);
Felipe Contreras (10):
transport-helper: fix extra lines
transport-helper: don't update refs in dry-run
transport-helper: add 'force' to 'export' helpers
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
Richard Hansen (1):
test-hg.sh: tests are now expected to pass
Documentation/git-fast-export.txt | 4 +++ Documentation/git-fast-import.txt | 3 +++ Documentation/gitremote-helpers.txt | 4 +++ builtin/fast-export.c | 49 ++++++++++++++++++++++++++++++++++++- contrib/remote-helpers/test-hg.sh | 4 +-- fast-import.c | 13 +++++++--- git-remote-testgit.sh | 18 ++++++++++++++ t/t5801-remote-helpers.sh | 23 ++++++++++++++++- t/t9300-fast-import.sh | 18 ++++++++++++++ t/t9350-fast-export.sh | 18 ++++++++++++++ transport-helper.c | 47 +++++++++++++++++++++++------------ 11 files changed, 179 insertions(+), 22 deletions(-)
Signature · 1 line
1.8.4.2+fc1
PATCH v7 1/11 transport-helper: fix extra lines
Commit 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
@@ -875,9 +875,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.2+fc1
PATCH v6 5/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
@@ -701,8 +701,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.2+fc1
PATCH v6 6/10 fast-export: add new --refspec option
In reply to Felipe ContrerasSo that we can convert the exported ref names.
--- Documentation/git-fast-export.txt | 4 ++++ builtin/fast-export.c | 32 ++++++++++++++++++++++++++++++++ t/t9350-fast-export.sh | 7 +++++++ 3 files changed, 43 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 +32 -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]" ),
@@ -31,6 +32,8 @@ static int use_done_feature;static int no_data;static int full_tree;static struct string_list extra_refs =STRING_LIST_INIT_NODUP ; +static struct refspec *refspecs; +static int refspecs_nr;static int parse_opt_signed_tag_mode (const struct option *opt,const char *arg,int unset)
@@ -525,6 +528,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; + } + } + commit =get_commit (e, full_name);if (!commit) { warning("%s: Unexpected object of type %s, skipping.",
@@ -668,6 +680,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 =STRING_LIST_INIT_NODUP ;struct option options[] = {OPT_INTEGER (0 ,"progress" , &progress,N_ ("show progress after <n> objects" )),
@@ -688,6 +701,8 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)OPT_BOOL (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() };
@@ -707,6 +722,21 @@ 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; +int i; + + refspecs_str =xmalloc (sizeof (*refspecs_str) * refspecs_list.nr); +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 ); +free (refspecs_str); + } +if (use_done_feature)printf ("feature done\n" );
@@ -741,5 +771,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.2+fc1
PATCH v7 2/11 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
@@ -728,7 +728,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;
@@ -742,7 +743,7 @@ static void push_update_refs_status(struct helper_data *data,if (push_update_ref_status (&buf, &ref, remote_refs))continue ; -if (!data->refspecs || data->no_private_update) +if (flags &TRANSPORT_PUSH_DRY_RUN || !data->refspecs || data->no_private_update)continue ;/* propagate back the update to the remote namespace */
@@ -833,7 +834,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 ; }
@@ -887,7 +888,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.2+fc1
PATCH v6 7/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
@@ -850,7 +850,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)
@@ -888,8 +888,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); } }
@@ -897,6 +902,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, flags);
Signature · 1 line
1.8.4.2+fc1
PATCH v7 3/11 transport-helper: add 'force' to 'export' helpers
In reply to Felipe ContrerasOtherwise they cannot know when to force the push or not (other than hacks).
--- Documentation/gitremote-helpers.txt | 4 ++++ git-remote-testgit.sh | 18 ++++++++++++++++++ t/t5801-remote-helpers.sh | 13 +++++++++++++ transport-helper.c | 5 +++++ 4 files changed, 40 insertions(+)
Documentation/gitremote-helpers.txt +4 -0
@@ -437,6 +437,10 @@ set by Git if the remote helper has the 'option' capability. 'option check-connectivity' \{'true'|'false'\}:: Request the helper to check connectivity of a clone. +'option force' \{'true'|'false'\}:: + Request the helper to perform a force update. Defaults to + 'false'. + SEE ALSO -------- linkgit:git-remote[1]
git-remote-testgit.sh +18 -0
@@ -15,6 +15,8 @@ test -z "$refspec" && prefix="refs" export GIT_DIR="$url/.git" +force= + mkdir -p "$dir" if test -z "$GIT_REMOTE_TESTGIT_NO_MARKS"
@@ -39,6 +41,7 @@ do fi test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags" test -n "$GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE" && echo "no-private-update" + echo 'option' echo ;; list)
@@ -93,6 +96,7 @@ do before=$(git for-each-ref --format=' %(refname) %(objectname) ') git fast-import \ + ${force:+--force} \ ${testgitmarks:+"--import-marks=$testgitmarks"} \ ${testgitmarks:+"--export-marks=$testgitmarks"} \ --quiet
@@ -115,6 +119,20 @@ do echo ;; + option\ *) + read cmd opt val <<-EOF + $line + EOF + case $opt in + force) + test $val = "true" && force="true" || force= + echo "ok" + ;; + *) + echo "unsupported" + ;; + esac + ;; '') exit ;;
t/t5801-remote-helpers.sh +13 -0
@@ -94,6 +94,19 @@ test_expect_failure 'push new branch with old:new refspec' ' compare_refs local HEAD server refs/heads/new-refspec ' +test_expect_success 'forced push' ' + (cd local && + git checkout -b force-test && + echo content >> file && + git commit -a -m eight && + git push origin force-test && + echo content >> file && + git commit -a --amend -m eight-modified && + git push --force origin force-test + ) && + compare_refs local refs/heads/force-test server refs/heads/force-test +' + test_expect_success 'cloning without refspec' ' GIT_REMOTE_TESTGIT_REFSPEC="" \ git clone "testgit::${PWD}/server" local2 2>error &&
transport-helper.c +5 -0
@@ -855,6 +855,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 ) +warning ("helper %s does not support 'force'" , data->name); + } + helper =get_helper (transport);write_constant (helper->in,"export\n" );
Signature · 1 line
1.8.4.2+fc1
PATCH v7 4/11 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
@@ -644,7 +644,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 ;
@@ -702,6 +702,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)
@@ -723,6 +728,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.2+fc1
PATCH v6 8/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) specifies 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 ]; };
@@ -1690,10 +1691,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 ,NULL );if (!lock)return error ("Unable to lock %s" , b->name);
@@ -2620,8 +2624,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
@@ -2999,4 +2999,22 @@ test_expect_success 'T: ls root tree' ' test_cmp expect actual ' +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.2+fc1
PATCH v7 5/11 test-hg.sh: tests are now expected to pass
In reply to Felipe ContrerasFrom: Richard Hansen <[email protected]>
--- contrib/remote-helpers/test-hg.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
contrib/remote-helpers/test-hg.sh +2 -2
@@ -599,7 +599,7 @@ test_expect_success 'remote big push fetch first' ' ) ' -test_expect_failure 'remote big push force' ' +test_expect_success 'remote big push force' ' test_when_finished "rm -rf hgrepo gitrepo*" && setup_big_push
@@ -629,7 +629,7 @@ test_expect_failure 'remote big push force' ' check_bookmark hgrepo new_bmark six ' -test_expect_failure 'remote big push dry-run' ' +test_expect_success 'remote big push dry-run' ' test_when_finished "rm -rf hgrepo gitrepo*" && setup_big_push
Signature · 1 line
1.8.4.2+fc1
PATCH v7 6/11 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
@@ -701,8 +701,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.2+fc1
PATCH v7 7/11 fast-export: add new --refspec option
In reply to Felipe ContrerasSo that we can convert the exported ref names.
--- Documentation/git-fast-export.txt | 4 ++++ builtin/fast-export.c | 32 ++++++++++++++++++++++++++++++++ t/t9350-fast-export.sh | 7 +++++++ 3 files changed, 43 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 +32 -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]" ),
@@ -31,6 +32,8 @@ static int use_done_feature;static int no_data;static int full_tree;static struct string_list extra_refs =STRING_LIST_INIT_NODUP ; +static struct refspec *refspecs; +static int refspecs_nr;static int parse_opt_signed_tag_mode (const struct option *opt,const char *arg,int unset)
@@ -525,6 +528,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; + } + } + commit =get_commit (e, full_name);if (!commit) { warning("%s: Unexpected object of type %s, skipping.",
@@ -668,6 +680,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 =STRING_LIST_INIT_NODUP ;struct option options[] = {OPT_INTEGER (0 ,"progress" , &progress,N_ ("show progress after <n> objects" )),
@@ -688,6 +701,8 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)OPT_BOOL (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() };
@@ -707,6 +722,21 @@ 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; +int i; + + refspecs_str =xmalloc (sizeof (*refspecs_str) * refspecs_list.nr); +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 ); +free (refspecs_str); + } +if (use_done_feature)printf ("feature done\n" );
@@ -741,5 +771,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.2+fc1
PATCH v7 8/11 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
@@ -850,7 +850,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)
@@ -888,8 +888,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); } }
@@ -897,6 +902,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, flags);
Signature · 1 line
1.8.4.2+fc1
PATCH v7 9/11 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) specifies 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 ]; };
@@ -1690,10 +1691,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 ,NULL );if (!lock)return error ("Unable to lock %s" , b->name);
@@ -2620,8 +2624,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
@@ -2999,4 +2999,22 @@ test_expect_success 'T: ls root tree' ' test_cmp expect actual ' +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.2+fc1
PATCH v6 9/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
@@ -673,6 +673,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;
@@ -764,6 +777,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) }handle_tags_and_duplicates (); +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.2+fc1
PATCH v7 10/11 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
@@ -673,6 +673,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;
@@ -764,6 +777,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) }handle_tags_and_duplicates (); +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.2+fc1
PATCH v6 10/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 | 11 ++++++----- 2 files changed, 14 insertions(+), 5 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 'forced push' ' (cd local && git checkout -b force-test &&
transport-helper.c +6 -5
@@ -876,9 +876,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);
@@ -890,12 +887,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.2+fc1
PATCH v7 11/11 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 | 11 ++++++----- 2 files changed, 14 insertions(+), 5 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 'forced push' ' (cd local && git checkout -b force-test &&
transport-helper.c +6 -5
@@ -876,9 +876,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);
@@ -890,12 +887,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.2+fc1
Quoted 1 line · Felipe Contreras
Here are the patches that allow transport helpers to be completely transparent;
Thanks, will replace what is on 'pu'.
Quoted 2 lines
Felipe Contreras (10):
transport-helper: fix extra lines
I'll retitle this one to "mismerge fix" to make it clear where the blame lies ;-)
PATCH v3 1/1 remote-bzr: support the new 'force' option
In reply to Felipe Contreras---
This is a reroll of:
http://article.gmane.org/gmane.comp.version-control.git/237699
based on feedback from Felipe:
http://article.gmane.org/gmane.comp.version-control.git/237756
This patch is an optional extension to Felipe's "transport-helper:
updates" patch series:
http://thread.gmane.org/gmane.comp.version-control.git/237738
and it requires those changes to work.
Changes from v2:
* remove 'import types' (no longer necessary)
* change '(opt, val) = parser[1:3]' to 'opt, val = parser[1:3]'
* add 'Reviewed-by: Felipe Contreras <[email protected]>' to commit message based on Felipe's comment in:
http://article.gmane.org/gmane.comp.version-control.git/237756
contrib/remote-helpers/git-remote-bzr | 31 ++++++++++++++++++++++++++++++- contrib/remote-helpers/test-bzr.sh | 22 +++++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-)
contrib/remote-helpers/git-remote-bzr +30 -1
@@ -684,7 +684,8 @@ def do_export(parser): peer = bzrlib.branch.Branch.open(peers[name], possible_transports=transports) try: - peer.bzrdir.push_branch(branch, revision_id=revid) + peer.bzrdir.push_branch(branch, revision_id=revid, + overwrite=force) except bzrlib.errors.DivergedBranches: print "error %s non-fast forward" % ref continue
@@ -718,8 +719,32 @@ def do_capabilities(parser): print "*import-marks %s" % path print "*export-marks %s" % path + print "option" print +class InvalidOptionValue(Exception): + pass + +def get_bool_option(val): + if val == 'true': + return True + elif val == 'false': + return False + else: + raise InvalidOptionValue() + +def do_option(parser): + global force + opt, val = parser[1:3] + try: + if opt == 'force': + force = get_bool_option(val) + print 'ok' + else: + print 'unsupported' + except InvalidOptionValue: + print "error '%s' is not a valid value for option '%s'" % (val, opt) + def ref_is_valid(name): return not True in [c in name for c in '~^: \\']
@@ -882,6 +907,7 @@ def main(args): global is_tmp global branches, peers global transports + global force alias = args[1] url = args[2]
@@ -895,6 +921,7 @@ def main(args): branches = {} peers = {} transports = [] + force = False if alias[5:] == url: is_tmp = True
@@ -930,6 +957,8 @@ def main(args): do_import(parser) elif parser.check('export'): do_export(parser) + elif parser.check('option'): + do_option(parser) else: die('unhandled command: %s' % line) sys.stdout.flush()
contrib/remote-helpers/test-bzr.sh +21 -1
@@ -66,13 +66,33 @@ test_expect_success 'pushing' ' test_cmp expected actual ' +test_expect_success 'forced pushing' ' + ( + cd gitrepo && + echo three-new >content && + git commit -a --amend -m three-new && + git push -f + ) && + + ( + cd bzrrepo && + # the forced update overwrites the bzr branch but not the bzr + # working directory (it tries to merge instead) + bzr revert + ) && + + echo three-new >expected && + cat bzrrepo/content >actual && + test_cmp expected actual +' + test_expect_success 'roundtrip' ' ( cd gitrepo && git pull && git log --format="%s" -1 origin/master >actual ) && - echo three >expected && + echo three-new >expected && test_cmp expected actual && (cd gitrepo && git push && git pull) &&
Signature · 1 line
1.8.5.rc2.10.g50cf47a