/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/plugins/fastimport/exporter.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-07-04 12:50:55 UTC
  • mfrom: (7027.2.8 git-fixes)
  • Revision ID: breezy.the.bot@gmail.com-20180704125055-8nni25pn2439p48v
Fix eol handling in knits on Python 3, port fastimport plugin to Python 3.

Merged from https://code.launchpad.net/~jelmer/brz/fastimport-fixes/+merge/348924

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
    progress,
64
64
    trace,
65
65
    )
 
66
from ...sixish import int2byte
66
67
 
67
68
from . import (
68
69
    helpers,
97
98
    """
98
99
    # These could be combined into one big expression, but are listed separately
99
100
    # to parallel [1].
100
 
    if '/.' in refname or refname.startswith('.'):
101
 
        return False
102
 
    if '/' not in refname:
103
 
        return False
104
 
    if '..' in refname:
105
 
        return False
106
 
    for c in refname:
107
 
        if ord(c) < 0o40 or c in '\177 ~^:?*[':
 
101
    if b'/.' in refname or refname.startswith(b'.'):
 
102
        return False
 
103
    if b'/' not in refname:
 
104
        return False
 
105
    if b'..' in refname:
 
106
        return False
 
107
    for i in range(len(refname)):
 
108
        if ord(refname[i:i+1]) < 0o40 or refname[i] in b'\177 ~^:?*[':
108
109
            return False
109
 
    if refname[-1] in '/.':
110
 
        return False
111
 
    if refname.endswith('.lock'):
112
 
        return False
113
 
    if '@{' in refname:
114
 
        return False
115
 
    if '\\' in refname:
 
110
    if refname[-1] in b'/.':
 
111
        return False
 
112
    if refname.endswith(b'.lock'):
 
113
        return False
 
114
    if b'@{' in refname:
 
115
        return False
 
116
    if b'\\' in refname:
116
117
        return False
117
118
    return True
118
119
 
130
131
    """
131
132
    new_refname = re.sub(
132
133
        # '/.' in refname or startswith '.'
133
 
        r"/\.|^\."
 
134
        br"/\.|^\."
134
135
        # '..' in refname
135
 
        r"|\.\."
 
136
        br"|\.\."
136
137
        # ord(c) < 040
137
 
        r"|[" + "".join([chr(x) for x in range(0o40)]) + r"]"
 
138
        br"|[" + b"".join([int2byte(x) for x in range(0o40)]) + br"]"
138
139
        # c in '\177 ~^:?*['
139
 
        r"|[\177 ~^:?*[]"
 
140
        br"|[\177 ~^:?*[]"
140
141
        # last char in "/."
141
 
        r"|[/.]$"
 
142
        br"|[/.]$"
142
143
        # endswith '.lock'
143
 
        r"|.lock$"
 
144
        br"|.lock$"
144
145
        # "@{" in refname
145
 
        r"|@{"
 
146
        br"|@{"
146
147
        # "\\" in refname
147
 
        r"|\\",
148
 
        "_", refname)
 
148
        br"|\\",
 
149
        b"_", refname)
149
150
    return new_refname
150
151
 
151
152
 
286
287
            time_required)
287
288
 
288
289
    def print_cmd(self, cmd):
289
 
        self.outf.write("%r\n" % cmd)
 
290
        self.outf.write(b"%r\n" % cmd)
290
291
 
291
292
    def _save_marks(self):
292
293
        if self.export_marks_file:
412
413
                continue
413
414
            try:
414
415
                parent_mark = self.revid_to_mark[p]
415
 
                non_ghost_parents.append(":%s" % parent_mark)
 
416
                non_ghost_parents.append(b":%d" % parent_mark)
416
417
            except KeyError:
417
418
                # ghost - ignore
418
419
                continue
437
438
                    pass
438
439
 
439
440
        # Build and return the result
440
 
        return commands.CommitCommand(git_ref, str(mark), author_info,
 
441
        return commands.CommitCommand(git_ref, mark, author_info,
441
442
            committer_info, revobj.message.encode("utf-8"), from_, merges, iter(file_cmds),
442
443
            more_authors=more_author_info, properties=properties)
443
444
 
610
611
                self.warning('not creating tag %r pointing to non-existent '
611
612
                    'revision %s' % (tag, revid))
612
613
            else:
613
 
                git_ref = 'refs/tags/%s' % tag.encode("utf-8")
 
614
                git_ref = b'refs/tags/%s' % tag.encode("utf-8")
614
615
                if self.plain_format and not check_ref_format(git_ref):
615
616
                    if self.rewrite_tags:
616
617
                        new_ref = sanitize_ref_name_for_git(git_ref)
621
622
                        self.warning('not creating tag %r as its name would not be '
622
623
                                     'valid in git.', git_ref)
623
624
                        continue
624
 
                self.print_cmd(commands.ResetCommand(git_ref, ":" + str(mark)))
 
625
                self.print_cmd(commands.ResetCommand(git_ref, b":%d" % mark))
625
626
 
626
627
    def _next_tmp_ref(self):
627
628
        """Return a unique branch name. The name will start with "tmp"."""