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

  • Committer: Gustav Hartvigsson
  • Date: 2021-01-09 21:36:27 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210109213627-h1xwcutzy9m7a99b
Added 'Case Preserving Working Tree Use Cases' from Canonical Wiki

* Addod a page from the Canonical Bazaar wiki
  with information on the scmeatics of case
  perserving filesystems an a case insensitive
  filesystem works.
  
  * Needs re-work, but this will do as it is the
    same inforamoton as what was on the linked
    page in the currint documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
from bzrlib import registry
18
 
from bzrlib.lazy_import import lazy_import
 
17
from . import (
 
18
    errors,
 
19
    registry,
 
20
    )
 
21
from .lazy_import import lazy_import
19
22
lazy_import(globals(), """
20
 
from bzrlib import errors, urlutils
 
23
from breezy import urlutils
21
24
""")
22
25
 
23
26
 
37
40
"""
38
41
 
39
42
 
40
 
_bugs_help = \
41
 
"""When making a commit, metadata about bugs fixed by that change can be
 
43
_bugs_help = """\
 
44
When making a commit, metadata about bugs fixed by that change can be
42
45
recorded by using the ``--fixes`` option. For each bug marked as fixed, an
43
46
entry is included in the 'bugs' revision property stating '<url> <status>'.
44
47
(The only ``status`` value currently supported is ``fixed.``)
48
51
 
49
52
    bzr commit --fixes <tracker>:<id>
50
53
 
 
54
or::
 
55
 
 
56
    bzr commit --fixes <id>
 
57
 
51
58
where "<tracker>" is an identifier for the bug tracker, and "<id>" is the
52
59
identifier for that bug within the bugtracker, usually the bug number.
 
60
If "<tracker>" is not specified the ``bugtracker`` set in the branch
 
61
or global configuration is used.
53
62
 
54
63
Bazaar knows about a few bug trackers that have many users. If
55
64
you use one of these bug trackers then there is no setup required to
73
82
 
74
83
If you use Bugzilla or Trac, then you only need to set a configuration
75
84
variable which contains the base URL of the bug tracker. These options
76
 
can go into ``bazaar.conf``, ``branch.conf`` or into a branch-specific
 
85
can go into ``breezy.conf``, ``branch.conf`` or into a branch-specific
77
86
configuration section in ``locations.conf``.  You can set up these values
78
87
for each of the projects you work on.
79
88
 
93
102
--fixes`` to mark bugs in that tracker as being fixed by that commit. For
94
103
example::
95
104
 
96
 
    bugzilla_squid_url = http://www.squid-cache.org/bugs
 
105
    bugzilla_squid_url = http://bugs.squid-cache.org
97
106
 
98
107
would allow ``bzr commit --fixes squid:1234`` to mark Squid's bug 1234 as
99
108
fixed.
127
136
 
128
137
    bugtracker_cpan_url = http://rt.cpan.org/Public/Bug/Display.html?id={id}
129
138
 
130
 
for CPAN's RT bug tracker.
 
139
would allow ``bzr commit --fixes cpan:1234`` to mark bug 1234 in CPAN's
 
140
RT bug tracker as fixed, or::
 
141
 
 
142
    bugtracker_hudson_url = http://issues.hudson-ci.org/browse/{id}
 
143
 
 
144
would allow ``bzr commit --fixes hudson:HUDSON-1234`` to mark bug HUDSON-1234
 
145
in Hudson's JIRA bug tracker as fixed.
131
146
"""
132
147
 
133
148
 
 
149
class MalformedBugIdentifier(errors.BzrError):
 
150
 
 
151
    _fmt = ('Did not understand bug identifier %(bug_id)s: %(reason)s. '
 
152
            'See "brz help bugs" for more information on this feature.')
 
153
 
 
154
    def __init__(self, bug_id, reason):
 
155
        self.bug_id = bug_id
 
156
        self.reason = reason
 
157
 
 
158
 
 
159
class InvalidBugTrackerURL(errors.BzrError):
 
160
 
 
161
    _fmt = ("The URL for bug tracker \"%(abbreviation)s\" doesn't "
 
162
            "contain {id}: %(url)s")
 
163
 
 
164
    def __init__(self, abbreviation, url):
 
165
        self.abbreviation = abbreviation
 
166
        self.url = url
 
167
 
 
168
 
 
169
class UnknownBugTrackerAbbreviation(errors.BzrError):
 
170
 
 
171
    _fmt = ("Cannot find registered bug tracker called %(abbreviation)s "
 
172
            "on %(branch)s")
 
173
 
 
174
    def __init__(self, abbreviation, branch):
 
175
        self.abbreviation = abbreviation
 
176
        self.branch = branch
 
177
 
 
178
 
 
179
class InvalidLineInBugsProperty(errors.BzrError):
 
180
 
 
181
    _fmt = ("Invalid line in bugs property: '%(line)s'")
 
182
 
 
183
    def __init__(self, line):
 
184
        self.line = line
 
185
 
 
186
 
 
187
class InvalidBugUrl(errors.BzrError):
 
188
 
 
189
    _fmt = "Invalid bug URL: %(url)s"
 
190
 
 
191
    def __init__(self, url):
 
192
        self.url = url
 
193
 
 
194
 
 
195
class InvalidBugStatus(errors.BzrError):
 
196
 
 
197
    _fmt = ("Invalid bug status: '%(status)s'")
 
198
 
 
199
    def __init__(self, status):
 
200
        self.status = status
 
201
 
 
202
 
134
203
def get_bug_url(abbreviated_bugtracker_name, branch, bug_id):
135
204
    """Return a URL pointing to the canonical web page of the bug identified by
136
205
    'bug_id'.
153
222
            tracker = tracker_type.get(abbreviated_bugtracker_name, branch)
154
223
            if tracker is not None:
155
224
                return tracker
156
 
        raise errors.UnknownBugTrackerAbbreviation(abbreviated_bugtracker_name,
157
 
                                                   branch)
 
225
        raise UnknownBugTrackerAbbreviation(
 
226
            abbreviated_bugtracker_name, branch)
158
227
 
159
228
    def help_topic(self, topic):
160
229
        return _bugs_help
189
258
        try:
190
259
            int(bug_id)
191
260
        except ValueError:
192
 
            raise errors.MalformedBugIdentifier(bug_id, "Must be an integer")
 
261
            raise MalformedBugIdentifier(bug_id, "Must be an integer")
193
262
 
194
263
 
195
264
class UniqueIntegerBugTracker(IntegerBugTracker):
205
274
        self.base_url = base_url
206
275
 
207
276
    def get(self, abbreviated_bugtracker_name, branch):
208
 
        """Returns the tracker if the abbreviation matches. Returns None
209
 
        otherwise."""
210
 
        if abbreviated_bugtracker_name != self.abbreviation:
211
 
            return None
212
 
        return self
213
 
 
214
 
    def _get_bug_url(self, bug_id):
215
 
        """Return the URL for bug_id."""
216
 
        return self.base_url + bug_id
 
277
        """Returns the tracker if the abbreviation matches, otherwise ``None``.
 
278
        """
 
279
        if abbreviated_bugtracker_name != self.abbreviation:
 
280
            return None
 
281
        return self
 
282
 
 
283
    def _get_bug_url(self, bug_id):
 
284
        """Return the URL for bug_id."""
 
285
        return self.base_url + str(bug_id)
 
286
 
 
287
 
 
288
class ProjectIntegerBugTracker(IntegerBugTracker):
 
289
    """A bug tracker that exists in one place only with per-project ids.
 
290
 
 
291
    If you have one of these trackers then register an instance passing in an
 
292
    abbreviated name for the bug tracker and a base URL. The bug ids are
 
293
    appended directly to the URL.
 
294
    """
 
295
 
 
296
    def __init__(self, abbreviated_bugtracker_name, base_url):
 
297
        self.abbreviation = abbreviated_bugtracker_name
 
298
        self._base_url = base_url
 
299
 
 
300
    def get(self, abbreviated_bugtracker_name, branch):
 
301
        """Returns the tracker if the abbreviation matches, otherwise ``None``.
 
302
        """
 
303
        if abbreviated_bugtracker_name != self.abbreviation:
 
304
            return None
 
305
        return self
 
306
 
 
307
    def check_bug_id(self, bug_id):
 
308
        try:
 
309
            (project, bug_id) = bug_id.rsplit('/', 1)
 
310
        except ValueError:
 
311
            raise MalformedBugIdentifier(bug_id, "Expected format: project/id")
 
312
        try:
 
313
            int(bug_id)
 
314
        except ValueError:
 
315
            raise MalformedBugIdentifier(bug_id, "Bug id must be an integer")
 
316
 
 
317
    def _get_bug_url(self, bug_id):
 
318
        (project, bug_id) = bug_id.rsplit('/', 1)
 
319
        """Return the URL for bug_id."""
 
320
        if '{id}' not in self._base_url:
 
321
            raise InvalidBugTrackerURL(self._abbreviation, self._base_url)
 
322
        if '{project}' not in self._base_url:
 
323
            raise InvalidBugTrackerURL(self._abbreviation, self._base_url)
 
324
        return self._base_url.replace(
 
325
            '{project}', project).replace('{id}', str(bug_id))
217
326
 
218
327
 
219
328
tracker_registry.register(
224
333
    'debian', UniqueIntegerBugTracker('deb', 'http://bugs.debian.org/'))
225
334
 
226
335
 
227
 
tracker_registry.register('gnome',
228
 
    UniqueIntegerBugTracker('gnome', 'http://bugzilla.gnome.org/show_bug.cgi?id='))
229
 
 
230
 
 
231
 
class URLParametrizedIntegerBugTracker(IntegerBugTracker):
 
336
tracker_registry.register(
 
337
    'gnome', UniqueIntegerBugTracker(
 
338
        'gnome', 'http://bugzilla.gnome.org/show_bug.cgi?id='))
 
339
 
 
340
 
 
341
tracker_registry.register(
 
342
    'github', ProjectIntegerBugTracker(
 
343
        'github', 'https://github.com/{project}/issues/{id}'))
 
344
 
 
345
 
 
346
class URLParametrizedBugTracker(BugTracker):
232
347
    """A type of bug tracker that can be found on a variety of different sites,
233
348
    and thus needs to have the base URL configured.
234
349
 
235
350
    Looks for a config setting in the form '<type_name>_<abbreviation>_url'.
236
 
    `type_name` is the name of the type of tracker (e.g. 'bugzilla' or 'trac')
237
 
    and `abbreviation` is a short name for the particular instance (e.g.
238
 
    'squid' or 'apache').
 
351
    `type_name` is the name of the type of tracker and `abbreviation`
 
352
    is a short name for the particular instance.
239
353
    """
240
354
 
241
355
    def get(self, abbreviation, branch):
242
356
        config = branch.get_config()
243
357
        url = config.get_user_option(
244
 
            "%s_%s_url" % (self.type_name, abbreviation))
 
358
            "%s_%s_url" % (self.type_name, abbreviation), expand=False)
245
359
        if url is None:
246
360
            return None
247
361
        self._base_url = url
256
370
        return urlutils.join(self._base_url, self._bug_area) + str(bug_id)
257
371
 
258
372
 
 
373
class URLParametrizedIntegerBugTracker(IntegerBugTracker,
 
374
                                       URLParametrizedBugTracker):
 
375
    """A type of bug tracker that  only allows integer bug IDs.
 
376
 
 
377
    This can be found on a variety of different sites, and thus needs to have
 
378
    the base URL configured.
 
379
 
 
380
    Looks for a config setting in the form '<type_name>_<abbreviation>_url'.
 
381
    `type_name` is the name of the type of tracker (e.g. 'bugzilla' or 'trac')
 
382
    and `abbreviation` is a short name for the particular instance (e.g.
 
383
    'squid' or 'apache').
 
384
    """
 
385
 
 
386
 
259
387
tracker_registry.register(
260
388
    'trac', URLParametrizedIntegerBugTracker('trac', 'ticket/'))
261
389
 
264
392
    URLParametrizedIntegerBugTracker('bugzilla', 'show_bug.cgi?id='))
265
393
 
266
394
 
267
 
class GenericBugTracker(URLParametrizedIntegerBugTracker):
 
395
class GenericBugTracker(URLParametrizedBugTracker):
268
396
    """Generic bug tracker specified by an URL template."""
269
397
 
270
398
    def __init__(self):
277
405
    def _get_bug_url(self, bug_id):
278
406
        """Given a validated bug_id, return the bug's web page's URL."""
279
407
        if '{id}' not in self._base_url:
280
 
            raise errors.InvalidBugTrackerURL(self._abbreviation,
281
 
                                              self._base_url)
 
408
            raise InvalidBugTrackerURL(self._abbreviation, self._base_url)
282
409
        return self._base_url.replace('{id}', str(bug_id))
283
410
 
284
411
 
286
413
 
287
414
 
288
415
FIXED = 'fixed'
 
416
RELATED = 'related'
289
417
 
290
 
ALLOWED_BUG_STATUSES = set([FIXED])
 
418
ALLOWED_BUG_STATUSES = {FIXED, RELATED}
291
419
 
292
420
 
293
421
def encode_fixes_bug_urls(bug_urls):
294
422
    """Get the revision property value for a commit that fixes bugs.
295
423
 
296
 
    :param bug_urls: An iterable of escaped URLs to bugs. These normally
 
424
    :param bug_urls: An iterable of (escaped URL, tag) tuples. These normally
297
425
        come from `get_bug_url`.
298
426
    :return: A string that will be set as the 'bugs' property of a revision
299
427
        as part of a commit.
300
428
    """
301
 
    return '\n'.join(('%s %s' % (url, FIXED)) for url in bug_urls)
 
429
    lines = []
 
430
    for (url, tag) in bug_urls:
 
431
        if ' ' in url:
 
432
            raise InvalidBugUrl(url)
 
433
        lines.append('%s %s' % (url, tag))
 
434
    return '\n'.join(lines)
 
435
 
 
436
 
 
437
def decode_bug_urls(bug_text):
 
438
    """Decode a bug property text.
 
439
 
 
440
    :param bug_text: Contents of a bugs property
 
441
    :return: iterator over (url, status) tuples
 
442
    """
 
443
    for line in bug_text.splitlines():
 
444
        try:
 
445
            url, status = line.split(None, 2)
 
446
        except ValueError:
 
447
            raise InvalidLineInBugsProperty(line)
 
448
        if status not in ALLOWED_BUG_STATUSES:
 
449
            raise InvalidBugStatus(status)
 
450
        yield url, status