~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzr

  • Committer: John Arbash Meinel
  • Date: 2009-10-07 15:48:32 UTC
  • mto: (4679.6.1 2.1-export-c-api)
  • mto: This revision was merged to the branch mainline in revision 4735.
  • Revision ID: john@arbash-meinel.com-20091007154832-lpipxg46lynh9wmr
Rename StaticTupleInterner => SimpleSet.

This is a bit more appropriate, because the internal data type is not
specialized into StaticTuple objects only. Partially because I didn't
see a specific memory/speed tradeoff to caching the hash, and
that accessing said hash was siginficantly faster than just
calling PyObject_Hash().

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#! /usr/bin/python
2
 
 
3
 
# Copyright (C) 2004, 2005 by Martin Pool
4
 
# Copyright (C) 2005 by Canonical Ltd
5
 
 
 
1
#! /usr/bin/env python
 
2
 
 
3
# Copyright (C) 2005, 2006, 2007, 2008, 2009 Canonical Ltd
 
4
#
6
5
# This program is free software; you can redistribute it and/or modify
7
6
# it under the terms of the GNU General Public License as published by
8
7
# the Free Software Foundation; either version 2 of the License, or
9
8
# (at your option) any later version.
10
 
 
 
9
#
11
10
# This program is distributed in the hope that it will be useful,
12
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
13
# GNU General Public License for more details.
15
 
 
 
14
#
16
15
# You should have received a copy of the GNU General Public License
17
16
# along with this program; if not, write to the Free Software
18
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
 
 
20
 
import sys, bzrlib, bzrlib.commands
 
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
18
 
 
19
"""Bazaar -- a free distributed version-control tool"""
 
20
 
 
21
import os
 
22
import sys
 
23
import warnings
 
24
 
 
25
# update this on each release
 
26
_script_version = (2, 1, 0)
 
27
 
 
28
if __doc__ is None:
 
29
    print "bzr does not support python -OO."
 
30
    sys.exit(2)
 
31
try:
 
32
    version_info = sys.version_info
 
33
except AttributeError:
 
34
    version_info = 1, 5 # 1.5 or older
 
35
 
 
36
REINVOKE = "__BZR_REINVOKE"
 
37
NEED_VERS = (2, 4)
 
38
KNOWN_PYTHONS = ('python2.4', 'python2.5', 'python2.6')
 
39
 
 
40
if version_info < NEED_VERS:
 
41
    if not os.environ.has_key(REINVOKE):
 
42
        # mutating os.environ doesn't work in old Pythons
 
43
        os.putenv(REINVOKE, "1")
 
44
        for python in KNOWN_PYTHONS:
 
45
            try:
 
46
                os.execvp(python, [python] + sys.argv)
 
47
            except OSError:
 
48
                pass
 
49
    sys.stderr.write("bzr: error: cannot find a suitable python interpreter\n")
 
50
    sys.stderr.write("  (need %d.%d or later)\n" % NEED_VERS)
 
51
    sys.exit(1)
 
52
if hasattr(os, "unsetenv"):
 
53
    os.unsetenv(REINVOKE)
 
54
 
 
55
 
 
56
profiling = False
 
57
if '--profile-imports' in sys.argv:
 
58
    sys.argv.remove('--profile-imports')
 
59
    import profile_imports
 
60
    profile_imports.install()
 
61
    profiling = True
 
62
 
 
63
if sys.platform == 'darwin':
 
64
    # jameinel says this hack is to force python to honor the LANG setting,
 
65
    # even on Darwin.  Otherwise it is apparently hardcoded to Mac-Roman,
 
66
    # which is incorrect for the normal Terminal.app which wants UTF-8.
 
67
    #
 
68
    # "It might be that I should be setting the "system locale" somewhere else
 
69
    # on the system, rather than setting LANG=en_US.UTF-8 in .bashrc.
 
70
    # Switching to 'posix' and setting LANG worked for me."
 
71
    #
 
72
    # So we can remove this if someone works out the right way to tell Mac
 
73
    # Python which encoding to use.  -- mbp 20080703
 
74
    sys.platform = 'posix'
 
75
    try:
 
76
        import locale
 
77
    finally:
 
78
        sys.platform = 'darwin'
 
79
else:
 
80
    import locale
 
81
 
 
82
 
 
83
# The python2.6 release includes some libraries that have deprecation warnings
 
84
# against the interpreter - see https://bugs.launchpad.net/bzr/+bug/387139
 
85
warnings.filterwarnings('ignore',
 
86
    r"(struct integer overflow masking is deprecated|"
 
87
    r"'L' format requires 0 <= number <= 4294967295)",
 
88
    DeprecationWarning,
 
89
    'gzip',
 
90
    )
 
91
 
 
92
 
 
93
try:
 
94
    locale.setlocale(locale.LC_ALL, '')
 
95
except locale.Error, e:
 
96
    sys.stderr.write('bzr: warning: %s\n'
 
97
                     '  bzr could not set the application locale.\n'
 
98
                     '  Although this should be no problem for bzr itself,\n'
 
99
                     '  it might cause problems with some plugins.\n'
 
100
                     '  To investigate the issue, look at the output\n'
 
101
                     '  of the locale(1p) tool available on POSIX systems.\n'
 
102
                     % e)
 
103
 
 
104
# instruct bzrlib/__init__.py to install lazy_regex
 
105
sys._bzr_lazy_regex = True
 
106
try:
 
107
    import bzrlib
 
108
except ImportError, e:
 
109
    sys.stderr.write("bzr: ERROR: "
 
110
        "Couldn't import bzrlib and dependencies.\n"
 
111
        "Please check the directory containing bzrlib is on your PYTHONPATH.\n"
 
112
        "\n")
 
113
    raise
 
114
 
 
115
if bzrlib.version_info[:3] != _script_version:
 
116
    sys.stderr.write("bzr: WARNING: bzrlib version doesn't match the bzr program.\n"
 
117
            "This may indicate an installation problem.\n"
 
118
            "bzrlib from %s is version %r\n"
 
119
            % (bzrlib.__path__, bzrlib.version_info))
 
120
 
 
121
import bzrlib.inspect_for_copy
 
122
bzrlib.inspect_for_copy.import_copy_with_hacked_inspect()
 
123
 
 
124
import bzrlib.breakin
 
125
bzrlib.breakin.hook_debugger_to_signal()
 
126
 
 
127
import bzrlib.decorators
 
128
if ('--lsprof' in sys.argv
 
129
    or '--lsprof-file' in sys.argv
 
130
    or '--profile' in sys.argv
 
131
    or '--lsprof-timed' in sys.argv):
 
132
    bzrlib.decorators.use_pretty_decorators()
 
133
else:
 
134
    bzrlib.decorators.use_fast_decorators()
 
135
 
 
136
import bzrlib.commands
 
137
import bzrlib.trace
21
138
 
22
139
 
23
140
if __name__ == '__main__':
24
 
    sys.exit(bzrlib.commands.main(sys.argv))
25
 
    
 
141
    bzrlib.trace.enable_default_logging()
 
142
    exit_val = bzrlib.commands.main()
 
143
 
 
144
    if profiling:
 
145
        profile_imports.log_stack_info(sys.stderr)
 
146
 
 
147
    # run anything registered by atexit, because it won't be run in the normal
 
148
    # way
 
149
    sys.exitfunc()
 
150
 
 
151
    # By this point we really have completed everything we want to do, and
 
152
    # there's no point doing any additional cleanup.  Abruptly exiting here
 
153
    # stops any background threads getting into trouble as code is unloaded,
 
154
    # and it may also be slightly faster, through avoiding gc of objects that
 
155
    # are just about to be discarded anyhow.  This does mean that atexit hooks
 
156
    # won't run but we don't use them.  Also file buffers won't be flushed,
 
157
    # but our policy is to always close files from a finally block. -- mbp 20070215
 
158
    try:
 
159
        sys.stdout.flush()
 
160
        sys.stderr.flush()
 
161
    except IOError, e:
 
162
        import errno
 
163
        if e.errno in [errno.EINVAL, errno.EPIPE]:
 
164
            pass
 
165
        else:
 
166
            raise
 
167
    if bzrlib.trace._trace_file:
 
168
        # this is also _bzr_log
 
169
        bzrlib.trace._trace_file.flush()
 
170
    os._exit(exit_val)
 
171
else:
 
172
    raise ImportError("The bzr script cannot be imported.")