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

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
from __future__ import absolute_import
20
20
 
21
 
from .lazy_import import lazy_import
 
21
from bzrlib.lazy_import import lazy_import
22
22
lazy_import(globals(), """
23
23
import time
24
24
 
25
 
from breezy import (
 
25
from bzrlib import (
26
26
    config,
 
27
    errors,
27
28
    osutils,
28
29
    )
29
30
""")
30
31
 
31
 
from . import (
32
 
    errors,
 
32
from bzrlib import (
33
33
    lazy_regex,
34
34
    )
35
35
 
36
36
# the regex removes any weird characters; we don't escape them
37
37
# but rather just pull them out
38
 
_file_id_chars_re = lazy_regex.lazy_compile('[^\\w.]')
39
 
_rev_id_chars_re = lazy_regex.lazy_compile('[^-\\w.+@]')
 
38
_file_id_chars_re = lazy_regex.lazy_compile(r'[^\w.]')
 
39
_rev_id_chars_re = lazy_regex.lazy_compile(r'[^-\w.+@]')
40
40
_gen_file_id_suffix = None
41
41
_gen_file_id_serial = 0
42
42
 
48
48
    give a highly probably globally unique number. Then each call in the same
49
49
    process adds 1 to a serial number we append to that unique value.
50
50
    """
51
 
    # XXX TODO: change breezy.add.smart_add_tree to call workingtree.add() rather
 
51
    # XXX TODO: change bzrlib.add.smart_add_tree to call workingtree.add() rather
52
52
    # than having to move the id randomness out of the inner loop like this.
53
53
    # XXX TODO: for the global randomness this uses we should add the thread-id
54
54
    # before the serial #.
59
59
    #           suffix forever.
60
60
    global _gen_file_id_suffix, _gen_file_id_serial
61
61
    if _gen_file_id_suffix is None:
62
 
        _gen_file_id_suffix =  ("-%s-%s-" % (
63
 
                osutils.compact_date(time.time()), osutils.rand_chars(16))
64
 
            ).encode("ascii")
 
62
        _gen_file_id_suffix = "-%s-%s-" % (osutils.compact_date(time.time()),
 
63
                                           osutils.rand_chars(16))
65
64
    _gen_file_id_serial += 1
66
 
    return b"%s%d" % (_gen_file_id_suffix, _gen_file_id_serial)
 
65
    return _gen_file_id_suffix + str(_gen_file_id_serial)
67
66
 
68
67
 
69
68
def gen_file_id(name):
82
81
    #    filesystems
83
82
    # 4) Removing starting '.' characters to prevent the file ids from
84
83
    #    being considered hidden.
85
 
    ascii_word_only = _file_id_chars_re.sub('', name.lower()).encode('ascii')
86
 
    short_no_dots = ascii_word_only.lstrip(b'.')[:20]
 
84
    ascii_word_only = str(_file_id_chars_re.sub('', name.lower()))
 
85
    short_no_dots = ascii_word_only.lstrip('.')[:20]
87
86
    return short_no_dots + _next_id_suffix()
88
87
 
89
88
 
103
102
    """
104
103
    try:
105
104
        user_or_email = config.extract_email_address(username)
106
 
    except config.NoEmailInUsername:
 
105
    except errors.NoEmailInUsername:
107
106
        user_or_email = username
108
107
 
109
108
    user_or_email = user_or_email.lower()