~ubuntu-branches/debian/wheezy/bzr-fastimport/wheezy

« back to all changes in this revision

Viewing changes to exporter.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2011-08-22 18:55:41 UTC
  • mfrom: (1.1.12 upstream)
  • Revision ID: james.westby@ubuntu.com-20110822185541-efqh89ead3md1c41
Tags: 0.11.0-1
* New upstream release.
 + Fixes crash in "bzr fast-import-filter". LP: #792935
 + Fixes attribute error in iter_entries_by_dir() during fast-export.
   LP: #631979

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
    else:
62
62
        return open(destination, 'wb')
63
63
 
 
64
# from dulwich.repo:
 
65
def check_ref_format(refname):
 
66
    """Check if a refname is correctly formatted.
 
67
 
 
68
    Implements all the same rules as git-check-ref-format[1].
 
69
 
 
70
    [1] http://www.kernel.org/pub/software/scm/git/docs/git-check-ref-format.html
 
71
 
 
72
    :param refname: The refname to check
 
73
    :return: True if refname is valid, False otherwise
 
74
    """
 
75
    # These could be combined into one big expression, but are listed separately
 
76
    # to parallel [1].
 
77
    if '/.' in refname or refname.startswith('.'):
 
78
        return False
 
79
    if '/' not in refname:
 
80
        return False
 
81
    if '..' in refname:
 
82
        return False
 
83
    for c in refname:
 
84
        if ord(c) < 040 or c in '\177 ~^:?*[':
 
85
            return False
 
86
    if refname[-1] in '/.':
 
87
        return False
 
88
    if refname.endswith('.lock'):
 
89
        return False
 
90
    if '@{' in refname:
 
91
        return False
 
92
    if '\\' in refname:
 
93
        return False
 
94
    return True
 
95
 
 
96
 
64
97
 
65
98
class BzrFastExporter(object):
66
99
 
454
487
 
455
488
            # Renaming a directory implies all children must be renamed.
456
489
            # Note: changes_from() doesn't handle this
457
 
            if kind == 'directory':
 
490
            if kind == 'directory' and tree_old.kind(id_) == 'directory':
458
491
                for p, e in tree_old.inventory.iter_entries_by_dir(from_dir=id_):
459
492
                    if e.kind == 'directory' and self.plain_format:
460
493
                        continue
507
540
                    'revision %s' % (tag, revid))
508
541
            else:
509
542
                git_ref = 'refs/tags/%s' % tag.encode("utf-8")
 
543
                if self.plain_format and not check_ref_format(git_ref):
 
544
                    self.warning('not creating tag %r as its name would not be '
 
545
                                 'valid in git.', git_ref)
 
546
                    continue
510
547
                self.print_cmd(commands.ResetCommand(git_ref, ":" + str(mark)))
511
548
 
512
549
    def _next_tmp_branch_name(self):