diff options
Diffstat (limited to 'contrib/remote-helpers')
-rw-r--r-- | contrib/remote-helpers/Makefile | 1 | ||||
-rwxr-xr-x | contrib/remote-helpers/git-remote-bzr | 64 | ||||
-rwxr-xr-x | contrib/remote-helpers/test-bzr.sh | 118 | ||||
-rwxr-xr-x | contrib/remote-helpers/test-hg-hg-git.sh | 1 | ||||
-rwxr-xr-x | contrib/remote-helpers/test-hg.sh | 2 |
5 files changed, 152 insertions, 34 deletions
diff --git a/contrib/remote-helpers/Makefile b/contrib/remote-helpers/Makefile index 9a76575f78..239161de33 100644 --- a/contrib/remote-helpers/Makefile +++ b/contrib/remote-helpers/Makefile @@ -3,6 +3,7 @@ TESTS := $(wildcard test*.sh) export T := $(addprefix $(CURDIR)/,$(TESTS)) export MAKE := $(MAKE) -e export PATH := $(CURDIR):$(PATH) +export TEST_LINT := test-lint-executable test-lint-shell-syntax test: $(MAKE) -C ../../t $@ diff --git a/contrib/remote-helpers/git-remote-bzr b/contrib/remote-helpers/git-remote-bzr index c5822e4ac9..bd25e08202 100755 --- a/contrib/remote-helpers/git-remote-bzr +++ b/contrib/remote-helpers/git-remote-bzr @@ -25,6 +25,7 @@ bzrlib.plugin.load_plugins() import bzrlib.generate_ids import bzrlib.transport +import bzrlib.errors import sys import os @@ -183,15 +184,24 @@ def get_filechanges(cur, prev): changes = cur.changes_from(prev) + def u(s): + return s.encode('utf-8') + for path, fid, kind in changes.added: - modified[path] = fid + modified[u(path)] = fid for path, fid, kind in changes.removed: - removed[path] = None + removed[u(path)] = None for path, fid, kind, mod, _ in changes.modified: - modified[path] = fid + modified[u(path)] = fid for oldpath, newpath, fid, kind, mod, _ in changes.renamed: - removed[oldpath] = None - modified[newpath] = fid + removed[u(oldpath)] = None + if kind == 'directory': + lst = cur.list_files(from_dir=newpath, recursive=True) + for path, file_class, kind, fid, entry in lst: + if kind != 'directory': + modified[u(newpath + '/' + path)] = fid + else: + modified[u(newpath)] = fid return modified, removed @@ -260,7 +270,12 @@ def export_branch(branch, name): tz = rev.timezone committer = rev.committer.encode('utf-8') committer = "%s %u %s" % (fixup_user(committer), time, gittz(tz)) - author = committer + authors = rev.get_apparent_authors() + if authors: + author = authors[0].encode('utf-8') + author = "%s %u %s" % (fixup_user(author), time, gittz(tz)) + else: + author = committer msg = rev.message.encode('utf-8') msg += '\n' @@ -297,10 +312,10 @@ def export_branch(branch, name): else: print "merge :%s" % m + for f in removed: + print "D %s" % (f,) for f in modified_final: print "M %s :%u %s" % f - for f in removed: - print "D %s" % (f) print count += 1 @@ -321,12 +336,9 @@ def export_branch(branch, name): def export_tag(repo, name): global tags - try: - print "reset refs/tags/%s" % name - print "from :%u" % rev_to_mark(tags[name]) - print - except KeyError: - warn("TODO: fetch tag '%s'" % name) + print "reset refs/tags/%s" % name + print "from :%u" % rev_to_mark(tags[name]) + print def do_import(parser): global dirname @@ -501,6 +513,11 @@ class CustomTree(): def get_symlink_target(self, file_id): return self.updates[file_id]['data'] +def c_style_unescape(string): + if string[0] == string[-1] == '"': + return string.decode('string-escape')[1:-1] + return string + def parse_commit(parser): global marks, blob_marks, bmarks, parsed_refs global mode @@ -540,6 +557,7 @@ def parse_commit(parser): f = { 'deleted' : True } else: die('Unknown file command: %s' % line) + path = c_style_unescape(path).decode('utf-8') files[path] = f repo = parser.repo @@ -619,10 +637,9 @@ def do_export(parser): peer.import_last_revision_info_and_tags(repo, revno, revid) else: peer.import_last_revision_info(repo.repository, revno, revid) - wt = peer.bzrdir.open_workingtree() else: wt = repo.bzrdir.open_workingtree() - wt.update() + wt.update() print "ok %s" % ref print @@ -641,12 +658,25 @@ def do_capabilities(parser): print +def ref_is_valid(name): + return not True in [c in name for c in '~^: \\'] + def do_list(parser): global tags print "? refs/heads/%s" % 'master' - for tag, revid in parser.repo.tags.get_tag_dict().items(): + + branch = parser.repo + branch.lock_read() + for tag, revid in branch.tags.get_tag_dict().items(): + try: + branch.revision_id_to_dotted_revno(revid) + except bzrlib.errors.NoSuchRevision: + continue + if not ref_is_valid(tag): + continue print "? refs/tags/%s" % tag tags[tag] = revid + branch.unlock() print "@refs/heads/%s HEAD" % 'master' print diff --git a/contrib/remote-helpers/test-bzr.sh b/contrib/remote-helpers/test-bzr.sh index 70aa8a010a..e800c97fcf 100755 --- a/contrib/remote-helpers/test-bzr.sh +++ b/contrib/remote-helpers/test-bzr.sh @@ -17,20 +17,6 @@ if ! "$PYTHON_PATH" -c 'import bzrlib'; then test_done fi -cmd=' -import bzrlib -bzrlib.initialize() -import bzrlib.plugin -bzrlib.plugin.load_plugins() -import bzrlib.plugins.fastimport -' - -if ! "$PYTHON_PATH" -c "$cmd"; then - echo "consider setting BZR_PLUGIN_PATH=$HOME/.bazaar/plugins" 1>&2 - skip_all='skipping remote-bzr tests; bzr-fastimport not available' - test_done -fi - check () { (cd $1 && git log --format='%s' -1 && @@ -136,7 +122,109 @@ test_expect_success 'special modes' ' (cd gitrepo && git cat-file -p HEAD:link > ../actual) && - echo -n content > expected && + printf content > expected && + test_cmp expected actual +' + +cat > expected <<EOF +100644 blob 54f9d6da5c91d556e6b54340b1327573073030af content +100755 blob 68769579c3eaadbe555379b9c3538e6628bae1eb executable +120000 blob 6b584e8ece562ebffc15d38808cd6b98fc3d97ea link +040000 tree 35c0caa46693cef62247ac89a680f0c5ce32b37b movedir-new +EOF + +test_expect_success 'moving directory' ' + (cd bzrrepo && + mkdir movedir && + echo one > movedir/one && + echo two > movedir/two && + bzr add movedir && + bzr commit -m movedir && + bzr mv movedir movedir-new && + bzr commit -m movedir-new) && + + (cd gitrepo && + git pull && + git ls-tree HEAD > ../actual) && + + test_cmp expected actual +' + +test_expect_success 'different authors' ' + (cd bzrrepo && + echo john >> content && + bzr commit -m john \ + --author "Jane Rey <jrey@example.com>" \ + --author "John Doe <jdoe@example.com>") && + + (cd gitrepo && + git pull && + git show --format="%an <%ae>, %cn <%ce>" --quiet > ../actual) && + + echo "Jane Rey <jrey@example.com>, A U Thor <author@example.com>" > expected && + test_cmp expected actual +' + +test_expect_success 'fetch utf-8 filenames' ' + mkdir -p tmp && cd tmp && + test_when_finished "cd .. && rm -rf tmp && LC_ALL=C" && + + export LC_ALL=en_US.UTF-8 + + ( + bzr init bzrrepo && + cd bzrrepo && + + echo test >> "áéíóú" && + bzr add "áéíóú" && + echo test >> "îø∫∆" && + bzr add "îø∫∆" && + bzr commit -m utf-8 && + echo test >> "áéíóú" && + bzr commit -m utf-8 && + bzr rm "îø∫∆" && + bzr mv "áéíóú" "åß∂" && + bzr commit -m utf-8 + ) && + + ( + git clone "bzr::$PWD/bzrrepo" gitrepo && + cd gitrepo && + git ls-files > ../actual + ) && + + echo "\"\\303\\245\\303\\237\\342\\210\\202\"" > expected && + test_cmp expected actual +' + +test_expect_success 'push utf-8 filenames' ' + mkdir -p tmp && cd tmp && + test_when_finished "cd .. && rm -rf tmp && LC_ALL=C" && + + export LC_ALL=en_US.UTF-8 + + ( + bzr init bzrrepo && + cd bzrrepo && + + echo one >> content && + bzr add content && + bzr commit -m one + ) && + + ( + git clone "bzr::$PWD/bzrrepo" gitrepo && + cd gitrepo && + + echo test >> "áéíóú" && + git add "áéíóú" && + git commit -m utf-8 && + + git push + ) && + + (cd bzrrepo && bzr ls > ../actual) && + echo -e "content\náéíóú" > expected && test_cmp expected actual ' diff --git a/contrib/remote-helpers/test-hg-hg-git.sh b/contrib/remote-helpers/test-hg-hg-git.sh index 7e3967f5b6..3f253b7de7 100755 --- a/contrib/remote-helpers/test-hg-hg-git.sh +++ b/contrib/remote-helpers/test-hg-hg-git.sh @@ -140,7 +140,6 @@ test_expect_success 'executable bit' ' git_clone_$x hgrepo-$x gitrepo2-$x && git_log gitrepo2-$x > log-$x done && - cp -r log-* output-* /tmp/foo/ && test_cmp output-hg output-git && test_cmp log-hg log-git diff --git a/contrib/remote-helpers/test-hg.sh b/contrib/remote-helpers/test-hg.sh index 5f81dfae6c..7bb81f2f8e 100755 --- a/contrib/remote-helpers/test-hg.sh +++ b/contrib/remote-helpers/test-hg.sh @@ -115,7 +115,7 @@ test_expect_success 'update bookmark' ' git push ) && - hg -R hgrepo bookmarks | grep "devel\s\+3:" + hg -R hgrepo bookmarks | egrep "devel[ ]+3:" ' test_done |