Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1759)

Side by Side Diff: infra/libs/git2/data/commit.py

Issue 355153002: Refactor infra git libs and testing. (Closed) Base URL: https://chromium.googlesource.com/infra/infra@fake_testing_support
Patch Set: Change config ref to have a sandard naming scheme Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 import collections 4 import collections
5 import hashlib 5 import hashlib
6 import logging 6 import logging
7 import re 7 import re
8 8
9 from cStringIO import StringIO 9 from cStringIO import StringIO
10 10
11 from infra.services.gnumbd.support.util import cached_property, freeze 11 from infra.libs.decorators import cached_property
12 from infra.libs.types import freeze
13
14 from infra.libs.git2.data.data import Alterable
12 15
13 LOGGER = logging.getLogger(__name__) 16 LOGGER = logging.getLogger(__name__)
14 17
18
15 ################################################################################ 19 ################################################################################
16 # Exceptions 20 # Exceptions
17 ################################################################################ 21 ################################################################################
18 22
19 class PartialCommit(Exception): 23 class PartialCommit(Exception):
20 def __init__(self, hsh, raw): 24 def __init__(self, hsh, raw):
21 super(PartialCommit, self).__init__( 25 super(PartialCommit, self).__init__(
22 'Commit %s has partial content: %r' % (hsh, raw)) 26 'Commit %s has partial content: %r' % (hsh, raw))
23 self.raw = raw 27 self.raw = raw
24 28
25 29
26 class UnexpectedHeader(Exception): 30 class UnexpectedHeader(Exception):
27 def __init__(self, hsh, header, value): 31 def __init__(self, hsh, header, value):
28 super(UnexpectedHeader, self).__init__( 32 super(UnexpectedHeader, self).__init__(
29 'Unexpected header in commit %s: %r -> %r' % (hsh, header, value)) 33 'Unexpected header in commit %s: %r -> %r' % (hsh, header, value))
30 34
31 35
32 ################################################################################ 36 ################################################################################
33 # Base Class
34 ################################################################################
35
36 class Alterable(object):
37 def to_dict(self): # pragma: no cover
38 """The shallow dictionary representation of this object (i.e. the dictionary
39 may contain Alterable instances as values)."""
40 raise NotImplementedError()
41
42 def alter(self, **kwargs): # pragma: no cover
43 """Returns a copy of self, except with the fields listed in kwargs replaced
44 with new values."""
45 raise NotImplementedError()
46
47 @classmethod
48 def from_raw(cls, data): # pragma: no cover
49 """Construct an instance of this class from a string."""
50 raise NotImplementedError()
51
52
53 ################################################################################
54 # Implementation 37 # Implementation
55 ################################################################################ 38 ################################################################################
56 39
57 class CommitTimestamp(Alterable): 40 class CommitTimestamp(Alterable):
58 def __init__(self, secs, sign, hours, mins): 41 def __init__(self, secs, sign, hours, mins):
59 super(CommitTimestamp, self).__init__() 42 super(CommitTimestamp, self).__init__()
60 assert isinstance(secs, int) 43 assert isinstance(secs, int)
61 assert sign in '+-' 44 assert sign in '+-'
62 assert 0 <= hours < 24 45 assert 0 <= hours < 24
63 assert 0 <= mins < 60 46 assert 0 <= mins < 60
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 LOGGER.warn('Footers comprise entire message') 428 LOGGER.warn('Footers comprise entire message')
446 message_lines = [] 429 message_lines = []
447 430
448 footer_lines.reverse() 431 footer_lines.reverse()
449 432
450 if not tree or set(('author', 'committer')).difference(users.keys()): 433 if not tree or set(('author', 'committer')).difference(users.keys()):
451 raise PartialCommit(hsh_fn(), data) 434 raise PartialCommit(hsh_fn(), data)
452 435
453 return cls(tree, parents, users['author'], users['committer'], 436 return cls(tree, parents, users['author'], users['committer'],
454 other_header_lines, message_lines, footer_lines) 437 other_header_lines, message_lines, footer_lines)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698