/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
1
# Copyright (C) 2008 Canonical Ltd
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Parser of import data into command objects.
18
19
In order to reuse existing front-ends, the stream format is a subset of
20
the one used by git-fast-import (as of the 1.5.4 release of git at least).
21
The grammar is:
22
23
  stream ::= cmd*;
24
25
  cmd ::= new_blob
26
        | new_commit
27
        | new_tag
28
        | reset_branch
29
        | checkpoint
30
        | progress
31
        ;
32
33
  new_blob ::= 'blob' lf
34
    mark?
35
    file_content;
36
  file_content ::= data;
37
38
  new_commit ::= 'commit' sp ref_str lf
39
    mark?
40
    ('author' sp name '<' email '>' when lf)?
41
    'committer' sp name '<' email '>' when lf
42
    commit_msg
43
    ('from' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf)?
44
    ('merge' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf)*
45
    file_change*
46
    lf?;
47
  commit_msg ::= data;
48
49
  file_change ::= file_clr
50
    | file_del
51
    | file_rnm
52
    | file_cpy
53
    | file_obm
54
    | file_inm;
55
  file_clr ::= 'deleteall' lf;
56
  file_del ::= 'D' sp path_str lf;
57
  file_rnm ::= 'R' sp path_str sp path_str lf;
58
  file_cpy ::= 'C' sp path_str sp path_str lf;
59
  file_obm ::= 'M' sp mode sp (hexsha1 | idnum) sp path_str lf;
60
  file_inm ::= 'M' sp mode sp 'inline' sp path_str lf
61
    data;
62
63
  new_tag ::= 'tag' sp tag_str lf
64
    'from' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf
65
    'tagger' sp name '<' email '>' when lf
66
    tag_msg;
67
  tag_msg ::= data;
68
69
  reset_branch ::= 'reset' sp ref_str lf
70
    ('from' sp (ref_str | hexsha1 | sha1exp_str | idnum) lf)?
71
    lf?;
72
73
  checkpoint ::= 'checkpoint' lf
74
    lf?;
75
76
  progress ::= 'progress' sp not_lf* lf
77
    lf?;
78
79
     # note: the first idnum in a stream should be 1 and subsequent
80
     # idnums should not have gaps between values as this will cause
81
     # the stream parser to reserve space for the gapped values.  An
82
     # idnum can be updated in the future to a new object by issuing
83
     # a new mark directive with the old idnum.
84
     #
85
  mark ::= 'mark' sp idnum lf;
86
  data ::= (delimited_data | exact_data)
87
    lf?;
88
89
    # note: delim may be any string but must not contain lf.
90
    # data_line may contain any data but must not be exactly
0.88.2 by Samuel Bronson
Implement here-document style input data.
91
    # delim. The lf after the final data_line is included in
92
    # the data.
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
93
  delimited_data ::= 'data' sp '<<' delim lf
94
    (data_line lf)*
95
    delim lf;
96
97
     # note: declen indicates the length of binary_data in bytes.
98
     # declen does not include the lf preceeding the binary data.
99
     #
100
  exact_data ::= 'data' sp declen lf
101
    binary_data;
102
103
     # note: quoted strings are C-style quoting supporting \c for
104
     # common escapes of 'c' (e..g \n, \t, \\, \") or \nnn where nnn
105
     # is the signed byte value in octal.  Note that the only
106
     # characters which must actually be escaped to protect the
107
     # stream formatting is: \, " and LF.  Otherwise these values
108
     # are UTF8.
109
     #
110
  ref_str     ::= ref;
111
  sha1exp_str ::= sha1exp;
112
  tag_str     ::= tag;
113
  path_str    ::= path    | '"' quoted(path)    '"' ;
114
  mode        ::= '100644' | '644'
115
                | '100755' | '755'
116
                | '120000'
117
                ;
118
119
  declen ::= # unsigned 32 bit value, ascii base10 notation;
120
  bigint ::= # unsigned integer value, ascii base10 notation;
121
  binary_data ::= # file content, not interpreted;
122
123
  when         ::= raw_when | rfc2822_when;
124
  raw_when     ::= ts sp tz;
125
  rfc2822_when ::= # Valid RFC 2822 date and time;
126
127
  sp ::= # ASCII space character;
128
  lf ::= # ASCII newline (LF) character;
129
130
     # note: a colon (':') must precede the numerical value assigned to
131
     # an idnum.  This is to distinguish it from a ref or tag name as
132
     # GIT does not permit ':' in ref or tag strings.
133
     #
134
  idnum   ::= ':' bigint;
135
  path    ::= # GIT style file path, e.g. "a/b/c";
136
  ref     ::= # GIT ref name, e.g. "refs/heads/MOZ_GECKO_EXPERIMENT";
137
  tag     ::= # GIT tag name, e.g. "FIREFOX_1_5";
138
  sha1exp ::= # Any valid GIT SHA1 expression;
139
  hexsha1 ::= # SHA1 in hexadecimal format;
140
141
     # note: name and email are UTF8 strings, however name must not
142
     # contain '<' or lf and email must not contain any of the
143
     # following: '<', '>', lf.
144
     #
145
  name  ::= # valid GIT author/committer name;
146
  email ::= # valid GIT author/committer email;
147
  ts    ::= # time since the epoch in seconds, ascii base10 notation;
148
  tz    ::= # GIT style timezone;
149
150
     # note: comments may appear anywhere in the input, except
151
     # within a data command.  Any form of the data command
152
     # always escapes the related input from comment processing.
153
     #
154
     # In case it is not clear, the '#' that starts the comment
155
     # must be the first character on that the line (an lf have
156
     # preceeded it).
157
     #
158
  comment ::= '#' not_lf* lf;
159
  not_lf  ::= # Any byte that is not ASCII newline (LF);
160
"""
161
162
163
import re
164
import sys
165
166
import commands
167
import dates
168
import errors
169
170
171
## Stream parsing ##
172
173
class LineBasedParser(object):
174
175
    def __init__(self, input):
176
        """A Parser that keeps track of line numbers.
177
178
        :param input: the file-like object to read from
179
        """
180
        self.input = input
181
        self.lineno = 0
182
        # Lines pushed back onto the input stream
183
        self._buffer = []
184
185
    def abort(self, exception, *args):
186
        """Raise an exception providing line number information."""
187
        raise exception(self.lineno, *args)
188
189
    def readline(self):
190
        """Get the next line including the newline or '' on EOF."""
191
        self.lineno += 1
192
        if self._buffer:
193
            return self._buffer.pop()
194
        else:
195
            return self.input.readline()
196
197
    def next_line(self):
198
        """Get the next line without the newline or None on EOF."""
199
        line = self.readline()
200
        if line:
201
            return line[:-1]
202
        else:
203
            return None
204
205
    def push_line(self, line):
206
        """Push line back onto the line buffer.
207
        
208
        :param line: the line with no trailing newline
209
        """
210
        self.lineno -= 1
211
        self._buffer.append(line + "\n")
212
213
    def read_bytes(self, count):
214
        """Read a given number of bytes from the input stream.
215
        
216
        Throws MissingBytes if the bytes are not found.
217
218
        Note: This method does not read from the line buffer.
0.64.6 by Ian Clatworthy
generic processing method working for one revision in one branch
219
220
        :return: a string
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
221
        """
0.64.143 by Ian Clatworthy
speed up blob parsing
222
        result = self.input.read(count)
223
        found = len(result)
224
        self.lineno += result.count("\n")
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
225
        if found != count:
226
            self.abort(errors.MissingBytes, count, found)
0.64.143 by Ian Clatworthy
speed up blob parsing
227
        return result
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
228
229
    def read_until(self, terminator):
230
        """Read the input stream until the terminator is found.
231
        
232
        Throws MissingTerminator if the terminator is not found.
233
234
        Note: This method does not read from the line buffer.
235
236
        :return: the bytes read up to but excluding the terminator.
237
        """
0.88.2 by Samuel Bronson
Implement here-document style input data.
238
        
239
        lines = []
240
        term = terminator + '\n'
241
        while True:
242
            line = self.input.readline()
243
            if line == term:
244
                break
245
            else:
246
                lines.append(line)
247
        return ''.join(lines)
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
248
249
0.64.3 by Ian Clatworthy
tweak parser for better git-fast-export compatibility
250
# Regular expression used for parsing. (Note: The spec states that the name
251
# part should be non-empty but git-fast-export doesn't always do that so
0.65.2 by James Westby
The space between the author and email is optional in committer.
252
# the first bit is \w*, not \w+.) Also git-fast-import code says the
253
# space before the email is optional.
0.64.103 by Ian Clatworthy
handle empty emails & names/paths that aren't utf8 encoded
254
_WHO_AND_WHEN_RE = re.compile(r'([^<]*)<(.*)> (.+)')
255
_WHO_RE = re.compile(r'([^<]*)<(.*)>')
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
256
257
258
class ImportParser(LineBasedParser):
259
260
    def __init__(self, input, verbose=False, output=sys.stdout):
261
        """A Parser of import commands.
262
263
        :param input: the file-like object to read from
264
        :param verbose: display extra information of not
265
        :param output: the file-like object to write messages to (YAGNI?)
266
        """
267
        LineBasedParser.__init__(self, input)
268
        self.verbose = verbose
269
        self.output = output
270
        # We auto-detect the date format when a date is first encountered
271
        self.date_parser = None
272
0.64.191 by Ian Clatworthy
Force parser to generate commit messages in unicode - even when not in utf8 in the input stream
273
    def _warning(self, msg):
0.64.203 by Ian Clatworthy
fix reporting of non-utf8 commits to go to stderr
274
        sys.stderr.write("warning line %d: %s\n" % (self.lineno, msg))
0.64.191 by Ian Clatworthy
Force parser to generate commit messages in unicode - even when not in utf8 in the input stream
275
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
276
    def iter_commands(self):
277
        """Iterator returning ImportCommand objects."""
278
        while True:
279
            line = self.next_line()
280
            if line is None:
281
                break
282
            elif len(line) == 0 or line.startswith('#'):
283
                continue
284
            # Search for commands in order of likelihood
285
            elif line.startswith('commit '):
286
                yield self._parse_commit(line[len('commit '):])
287
            elif line.startswith('blob'):
288
                yield self._parse_blob()
289
            elif line.startswith('progress '):
290
                yield commands.ProgressCommand(line[len('progress '):])
291
            elif line.startswith('reset '):
292
                yield self._parse_reset(line[len('reset '):])
293
            elif line.startswith('tag '):
294
                yield self._parse_tag(line[len('tag '):])
295
            elif line.startswith('checkpoint'):
296
                yield commands.CheckpointCommand()
297
            else:
298
                self.abort(errors.InvalidCommand, line)
299
300
    def iter_file_commands(self):
301
        """Iterator returning FileCommand objects.
302
        
303
        If an invalid file command is found, the line is silently
304
        pushed back and iteration ends.
305
        """
306
        while True:
307
            line = self.next_line()
308
            if line is None:
309
                break
310
            elif len(line) == 0 or line.startswith('#'):
311
                continue
312
            # Search for file commands in order of likelihood
313
            elif line.startswith('M '):
314
                yield self._parse_file_modify(line[2:])
315
            elif line.startswith('D '):
316
                path = self._path(line[2:])
317
                yield commands.FileDeleteCommand(path)
318
            elif line.startswith('R '):
319
                old, new = self._path_pair(line[2:])
320
                yield commands.FileRenameCommand(old, new)
321
            elif line.startswith('C '):
322
                src, dest = self._path_pair(line[2:])
0.77.11 by Ian Clatworthy
fix parsing of filecopy command
323
                yield commands.FileCopyCommand(src, dest)
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
324
            elif line.startswith('deleteall'):
325
                yield commands.FileDeleteAllCommand()
326
            else:
327
                self.push_line(line)
328
                break
329
330
    def _parse_blob(self):
331
        """Parse a blob command."""
0.64.35 by Ian Clatworthy
identify unmarked blobs and commits by line numbers
332
        lineno = self.lineno
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
333
        mark = self._get_mark_if_any()
334
        data = self._get_data('blob')
0.64.35 by Ian Clatworthy
identify unmarked blobs and commits by line numbers
335
        return commands.BlobCommand(mark, data, lineno)
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
336
337
    def _parse_commit(self, ref):
338
        """Parse a commit command."""
0.64.35 by Ian Clatworthy
identify unmarked blobs and commits by line numbers
339
        lineno  = self.lineno
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
340
        mark = self._get_mark_if_any()
341
        author = self._get_user_info('commit', 'author', False)
342
        committer = self._get_user_info('commit', 'committer')
0.64.78 by Ian Clatworthy
fix from Pieter de Bie - hack around broken front-ends
343
        message = self._get_data('commit', 'message')
344
        try:
345
            message = message.decode('utf_8')
346
        except UnicodeDecodeError:
0.64.191 by Ian Clatworthy
Force parser to generate commit messages in unicode - even when not in utf8 in the input stream
347
            self._warning(
348
                "commit message not in utf8 - replacing unknown characters")
349
            message = message.decode('utf_8', 'replace')
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
350
        from_ = self._get_from()
0.64.60 by Ian Clatworthy
support merges when from clause implicit
351
        merges = []
352
        while True:
353
            merge = self._get_merge()
354
            if merge is not None:
0.64.104 by Ian Clatworthy
handle multiple merges in the one merge clause
355
                # while the spec suggests it's illegal, git-fast-export
356
                # outputs multiple merges on the one line, e.g.
357
                # merge :x :y :z
358
                these_merges = merge.split(" ")
359
                merges.extend(these_merges)
0.64.60 by Ian Clatworthy
support merges when from clause implicit
360
            else:
361
                break
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
362
        return commands.CommitCommand(ref, mark, author, committer, message,
0.64.60 by Ian Clatworthy
support merges when from clause implicit
363
            from_, merges, self.iter_file_commands, lineno)
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
364
365
    def _parse_file_modify(self, info):
366
        """Parse a filemodify command within a commit.
367
368
        :param info: a string in the format "mode dataref path"
369
          (where dataref might be the hard-coded literal 'inline').
370
        """
371
        params = info.split(' ', 2)
372
        path = self._path(params[2])
373
        is_executable, is_symlink = self._mode(params[0])
374
        if is_symlink:
375
            kind = commands.SYMLINK_KIND
376
        else:
377
            kind = commands.FILE_KIND
378
        if params[1] == 'inline':
379
            dataref = None
380
            data = self._get_data('filemodify')
381
        else:
382
            dataref = params[1]
383
            data = None
384
        return commands.FileModifyCommand(path, kind, is_executable, dataref,
385
            data)
386
387
    def _parse_reset(self, ref):
388
        """Parse a reset command."""
389
        from_ = self._get_from()
390
        return commands.ResetCommand(ref, from_)
391
392
    def _parse_tag(self, name):
393
        """Parse a tag command."""
394
        from_ = self._get_from('tag')
0.64.78 by Ian Clatworthy
fix from Pieter de Bie - hack around broken front-ends
395
        tagger = self._get_user_info('tag', 'tagger', accept_just_who=True)
0.64.76 by Ian Clatworthy
fix utf-8 decoding bugs
396
        message = self._get_data('tag', 'message').decode('utf_8')
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
397
        return commands.TagCommand(name, from_, tagger, message)
398
399
    def _get_mark_if_any(self):
400
        """Parse a mark section."""
401
        line = self.next_line()
402
        if line.startswith('mark :'):
403
            return line[len('mark :'):]
404
        else:
405
            self.push_line(line)
406
            return None
407
408
    def _get_from(self, required_for=None):
409
        """Parse a from section."""
410
        line = self.next_line()
0.64.172 by Ian Clatworthy
handle commit commands with no from clause and no sub-commands
411
        if line is None:
412
            return None
413
        elif line.startswith('from '):
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
414
            return line[len('from '):]
415
        elif required_for:
416
            self.abort(errors.MissingSection, required_for, 'from')
417
        else:
418
            self.push_line(line)
419
            return None
420
421
    def _get_merge(self):
422
        """Parse a merge section."""
423
        line = self.next_line()
0.64.172 by Ian Clatworthy
handle commit commands with no from clause and no sub-commands
424
        if line is None:
425
            return None
426
        elif line.startswith('merge '):
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
427
            return line[len('merge '):]
428
        else:
429
            self.push_line(line)
430
            return None
431
0.64.78 by Ian Clatworthy
fix from Pieter de Bie - hack around broken front-ends
432
    def _get_user_info(self, cmd, section, required=True,
433
        accept_just_who=False):
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
434
        """Parse a user section."""
435
        line = self.next_line()
436
        if line.startswith(section + ' '):
0.64.78 by Ian Clatworthy
fix from Pieter de Bie - hack around broken front-ends
437
            return self._who_when(line[len(section + ' '):], cmd, section,
438
                accept_just_who=accept_just_who)
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
439
        elif required:
440
            self.abort(errors.MissingSection, cmd, section)
441
        else:
442
            self.push_line(line)
443
            return None
444
445
    def _get_data(self, required_for, section='data'):
446
        """Parse a data section."""
447
        line = self.next_line()
448
        if line.startswith('data '):
449
            rest = line[len('data '):]
450
            if rest.startswith('<<'):
451
                return self.read_until(rest[2:])
452
            else:
453
                size = int(rest)
0.65.1 by James Westby
The data sections have an optional LF at the end in the byte count format.
454
                read_bytes = self.read_bytes(size)
455
                # optional LF after data.
456
                next = self.input.readline()
457
                self.lineno += 1
458
                if len(next) > 1 or next != "\n":
0.65.5 by James Westby
Make the parser handle multiple words in the committer name.
459
                    self.push_line(next[:-1])
0.65.1 by James Westby
The data sections have an optional LF at the end in the byte count format.
460
                return read_bytes
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
461
        else:
462
            self.abort(errors.MissingSection, required_for, section)
463
0.64.78 by Ian Clatworthy
fix from Pieter de Bie - hack around broken front-ends
464
    def _who_when(self, s, cmd, section, accept_just_who=False):
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
465
        """Parse who and when information from a string.
466
        
0.65.5 by James Westby
Make the parser handle multiple words in the committer name.
467
        :return: a tuple of (name,email,timestamp,timezone). name may be
468
            the empty string if only an email address was given.
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
469
        """
470
        match = _WHO_AND_WHEN_RE.search(s)
471
        if match:
472
            datestr = match.group(3)
473
            if self.date_parser is None:
474
                # auto-detect the date format
0.64.3 by Ian Clatworthy
tweak parser for better git-fast-export compatibility
475
                if len(datestr.split(' ')) == 2:
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
476
                    format = 'raw'
477
                elif datestr == 'now':
478
                    format = 'now'
479
                else:
480
                    format = 'rfc2822'
481
                self.date_parser = dates.DATE_PARSERS_BY_NAME[format]
0.84.1 by Ian Clatworthy
improve error msg when bad timezone encountered
482
            when = self.date_parser(datestr, self.lineno)
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
483
        else:
0.64.78 by Ian Clatworthy
fix from Pieter de Bie - hack around broken front-ends
484
            match = _WHO_RE.search(s)
485
            if accept_just_who and match:
486
                # HACK around missing time
487
                # TODO: output a warning here
488
                when = dates.DATE_PARSERS_BY_NAME['now']('now')
489
            else:
490
                self.abort(errors.BadFormat, cmd, section, s)
491
        name = match.group(1)
492
        if len(name) > 0:
493
            if name[-1] == " ":
0.64.103 by Ian Clatworthy
handle empty emails & names/paths that aren't utf8 encoded
494
                try:
495
                    name = name[:-1].decode('utf_8')
496
                except UnicodeDecodeError:
497
                    # The spec says names are *typically* utf8 encoded
498
                    # but that isn't enforced by git-fast-export (at least)
499
                    name = name[:-1]
0.64.197 by Ian Clatworthy
Gracefully handle email addresses with unicode characters
500
        email = match.group(2)
501
        # While it shouldn't happen, some datasets have email addresses
502
        # which contain unicode characters. See bug 338186. We sanitize
503
        # the data at this level just in case.
504
        try:
505
            email = "%s" % (email,)
506
        except UnicodeDecodeError:
507
            email = "%s" % (email.decode('utf_8'),)
508
        return (name, email, when[0], when[1])
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
509
510
    def _path(self, s):
511
        """Parse a path."""
0.64.10 by Ian Clatworthy
1st cut are dequoting paths
512
        if s.startswith('"'):
513
            if s[-1] != '"':
0.64.175 by Ian Clatworthy
fix parsing when a rename old-path has spaces in it
514
                self.abort(errors.BadFormat, '?', '?', s)
0.64.10 by Ian Clatworthy
1st cut are dequoting paths
515
            else:
516
                return _unquote_c_string(s[1:-1])
0.64.103 by Ian Clatworthy
handle empty emails & names/paths that aren't utf8 encoded
517
        try:
518
            return s.decode('utf_8')
519
        except UnicodeDecodeError:
520
            # The spec recommends utf8 encoding but that isn't enforced
521
            return s
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
522
523
    def _path_pair(self, s):
524
        """Parse two paths separated by a space."""
0.64.10 by Ian Clatworthy
1st cut are dequoting paths
525
        # TODO: handle a space in the first path
0.64.175 by Ian Clatworthy
fix parsing when a rename old-path has spaces in it
526
        if s.startswith('"'):
527
            parts = s[1:].split('" ', 1)
528
        else:
529
            parts = s.split(' ', 1)
0.64.181 by Ian Clatworthy
Ignore quotes around second path in a pair (Dmitri Paduchikh)
530
        if len(parts) != 2:
531
            self.abort(errors.BadFormat, '?', '?', s)
532
        elif parts[1].startswith('"') and parts[1].endswith('"'):
533
            parts[1] = parts[1][1:-1]
534
        elif parts[1].startswith('"') or parts[1].endswith('"'):
535
            self.abort(errors.BadFormat, '?', '?', s)
536
        return map(_unquote_c_string, parts)
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
537
538
    def _mode(self, s):
539
        """Parse a file mode into executable and symlink flags.
540
        
541
        :return (is_executable, is_symlink)
542
        """
543
        # Note: Output from git-fast-export slightly different to spec
544
        if s in ['644', '100644', '0100644']:
545
            return False, False
546
        elif s in ['755', '100755', '0100755']:
547
            return True, False
0.64.3 by Ian Clatworthy
tweak parser for better git-fast-export compatibility
548
        elif s in ['120000', '0120000']:
0.64.1 by Ian Clatworthy
1st cut: gfi parser + --info processing method
549
            return False, True
550
        else:
551
            self.abort(errors.BadFormat, 'filemodify', 'mode', s)
552
0.64.10 by Ian Clatworthy
1st cut are dequoting paths
553
554
def _unquote_c_string(s):
555
    """replace C-style escape sequences (\n, \", etc.) with real chars."""
556
    # HACK: Python strings are close enough
557
    return s.decode('string_escape', 'replace')