Merge branch 'fc/remote-bzr'
authorJunio C Hamano <gitster@pobox.com>
Fri, 26 Apr 2013 22:18:26 +0000 (15:18 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 26 Apr 2013 22:18:26 +0000 (15:18 -0700)
* fc/remote-bzr:
remote-bzr: use proper push method

1  2 
contrib/remote-helpers/git-remote-bzr
index aa7bc97beecc6af7adca5b6886d8e7c61f9173b1,6fedc28afb71e517a808ed9fe19cc23dc3a5f94a..a622122c86205c8dc58dcb75e145b3347f8e164b
@@@ -25,7 -25,6 +25,7 @@@ bzrlib.plugin.load_plugins(
  
  import bzrlib.generate_ids
  import bzrlib.transport
 +import bzrlib.errors
  
  import sys
  import os
@@@ -184,24 -183,21 +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
 +        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[newpath + '/' + path] = fid
 +                    modified[u(newpath + '/' + path)] = fid
          else:
 -            modified[newpath] = fid
 +            modified[u(newpath)] = fid
  
      return modified, removed
  
@@@ -227,7 -223,7 +227,7 @@@ def export_files(tree, files)
              # is the blog already exported?
              if h in filenodes:
                  mark = filenodes[h]
 -                final.append((mode, mark, path.encode('utf-8')))
 +                final.append((mode, mark, path))
                  continue
  
              d = tree.get_file_text(fid)
          print "data %d" % len(d)
          print d
  
 -        final.append((mode, mark, path.encode('utf-8')))
 +        final.append((mode, mark, path))
  
      return final
  
  def export_branch(branch, name):
 -    global prefix, dirname
 +    global prefix
  
      ref = '%s/heads/%s' % (prefix, name)
      tip = marks.get_tip(name)
      marks.set_tip(name, revid)
  
  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)
 +    global tags, prefix
 +
 +    ref = '%s/tags/%s' % (prefix, name)
 +    print "reset %s" % ref
 +    print "from :%u" % rev_to_mark(tags[name])
 +    print
  
  def do_import(parser):
      global dirname
@@@ -633,12 -630,12 +633,12 @@@ def do_export(parser)
      for ref, revid in parsed_refs.iteritems():
          if ref == 'refs/heads/master':
              repo.generate_revision_history(revid, marks.get_tip('master'))
-             revno, revid = repo.last_revision_info()
              if peer:
-                 if hasattr(peer, "import_last_revision_info_and_tags"):
-                     peer.import_last_revision_info_and_tags(repo, revno, revid)
-                 else:
-                     peer.import_last_revision_info(repo.repository, revno, revid)
+                 try:
+                     repo.push(peer, stop_revision=revid)
+                 except bzrlib.errors.DivergedBranches:
+                     print "error %s non-fast forward" % ref
+                     continue
              else:
                  wt = repo.bzrdir.open_workingtree()
                  wt.update()
@@@ -651,7 -648,6 +651,7 @@@ def do_capabilities(parser)
      print "import"
      print "export"
      print "refspec refs/heads/*:%s/heads/*" % prefix
 +    print "refspec refs/tags/*:%s/tags/*" % prefix
  
      path = os.path.join(dirname, 'marks-git')
  
  
      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'
  
 -    history = parser.repo.revision_history()
 -    for tag, revid in parser.repo.tags.get_tag_dict().items():
 -        if revid not in history:
 +    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