/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/generate_ids.py

  • Committer: Jelmer Vernooij
  • Date: 2018-07-06 23:36:14 UTC
  • mto: (7027.3.2 python3-n)
  • mto: This revision was merged to the branch mainline in revision 7030.
  • Revision ID: jelmer@jelmer.uk-20180706233614-t4m8krag15t4z4lp
Update python3.passing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2009, 2010, 2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
16
16
 
17
17
"""Common code for generating file or revision ids."""
18
18
 
19
 
from bzrlib.lazy_import import lazy_import
 
19
from __future__ import absolute_import
 
20
 
 
21
from .lazy_import import lazy_import
20
22
lazy_import(globals(), """
21
23
import time
22
 
import unicodedata
23
24
 
24
 
from bzrlib import (
 
25
from breezy import (
25
26
    config,
26
 
    errors,
27
27
    osutils,
28
28
    )
29
29
""")
30
30
 
31
 
from bzrlib import (
 
31
from . import (
 
32
    errors,
32
33
    lazy_regex,
33
34
    )
34
35
 
35
36
# the regex removes any weird characters; we don't escape them
36
37
# but rather just pull them out
37
 
_file_id_chars_re = lazy_regex.lazy_compile(r'[^\w.]')
38
 
_rev_id_chars_re = lazy_regex.lazy_compile(r'[^-\w.+@]')
 
38
_file_id_chars_re = lazy_regex.lazy_compile('[^\\w.]')
 
39
_rev_id_chars_re = lazy_regex.lazy_compile('[^-\\w.+@]')
39
40
_gen_file_id_suffix = None
40
41
_gen_file_id_serial = 0
41
42
 
47
48
    give a highly probably globally unique number. Then each call in the same
48
49
    process adds 1 to a serial number we append to that unique value.
49
50
    """
50
 
    # XXX TODO: change bzrlib.add.smart_add_tree to call workingtree.add() rather
 
51
    # XXX TODO: change breezy.add.smart_add_tree to call workingtree.add() rather
51
52
    # than having to move the id randomness out of the inner loop like this.
52
53
    # XXX TODO: for the global randomness this uses we should add the thread-id
53
54
    # before the serial #.
58
59
    #           suffix forever.
59
60
    global _gen_file_id_suffix, _gen_file_id_serial
60
61
    if _gen_file_id_suffix is None:
61
 
        _gen_file_id_suffix = "-%s-%s-" % (osutils.compact_date(time.time()),
62
 
                                           osutils.rand_chars(16))
 
62
        _gen_file_id_suffix = ("-%s-%s-" % (
 
63
                osutils.compact_date(time.time()), osutils.rand_chars(16))
 
64
            ).encode("ascii")
63
65
    _gen_file_id_serial += 1
64
 
    return _gen_file_id_suffix + str(_gen_file_id_serial)
 
66
    return b"%s%d" % (_gen_file_id_suffix, _gen_file_id_serial)
65
67
 
66
68
 
67
69
def gen_file_id(name):
80
82
    #    filesystems
81
83
    # 4) Removing starting '.' characters to prevent the file ids from
82
84
    #    being considered hidden.
83
 
    ascii_word_only = str(_file_id_chars_re.sub('', name.lower()))
84
 
    short_no_dots = ascii_word_only.lstrip('.')[:20]
 
85
    ascii_word_only = _file_id_chars_re.sub('', name.lower()).encode('ascii', 'replace')
 
86
    short_no_dots = ascii_word_only.lstrip(b'.')[:20]
85
87
    return short_no_dots + _next_id_suffix()
86
88
 
87
89
 
93
95
def gen_revision_id(username, timestamp=None):
94
96
    """Return new revision-id.
95
97
 
96
 
    :param username: This is the value returned by config.username(), which is
97
 
        typically a real name, followed by an email address. If found, we will
98
 
        use just the email address portion. Otherwise we flatten the real name,
99
 
        and use that.
 
98
    :param username: The username of the committer, in the format returned by
 
99
        config.username().  This is typically a real name, followed by an
 
100
        email address. If found, we will use just the email address portion.
 
101
        Otherwise we flatten the real name, and use that.
100
102
    :return: A new revision id.
101
103
    """
102
104
    try:
103
105
        user_or_email = config.extract_email_address(username)
104
 
    except errors.NoEmailInUsername:
 
106
    except config.NoEmailInUsername:
105
107
        user_or_email = username
106
108
 
107
109
    user_or_email = user_or_email.lower()