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

Side by Side Diff: infra/libs/git2/ref.py

Issue 477623003: Add git subtree daemon service. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@add_dtree_support
Patch Set: address comments Created 6 years, 4 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
« no previous file with comments | « no previous file | infra/libs/git2/repo.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 4
5 from infra.libs.git2.util import CalledProcessError 5 from infra.libs.git2.util import CalledProcessError
6 from infra.libs.git2.util import INVALID 6 from infra.libs.git2.util import INVALID
7 7
8 class Ref(object): 8 class Ref(object):
9 """Represents a single simple ref in a git Repo.""" 9 """Represents a single simple ref in a git Repo."""
10 def __init__(self, repo, ref_str): 10 def __init__(self, repo, ref_str):
11 """ 11 """
12 @type repo: Repo 12 @type repo: Repo
13 @type ref_str: str 13 @type ref_str: str
14 """ 14 """
15 self._repo = repo 15 self._repo = repo
16 self._ref = ref_str 16 self._ref = ref_str
17 17
18 # Comparison & Representation 18 # Comparison & Representation
19 def __eq__(self, other): 19 def __eq__(self, other):
20 return (self is other) or ( 20 return (self is other) or (
21 isinstance(other, Ref) and ( 21 isinstance(other, Ref) and (
22 self.ref == other.ref and 22 self.ref == other.ref and
23 self.repo is other.repo 23 self.repo is other.repo
24 ) 24 )
25 ) 25 )
26 26
27 def __ne__(self, other): 27 def __ne__(self, other):
28 return not (self == other) 28 return not (self == other)
29 29
30 def __hash__(self):
31 return hash((self._repo, self._ref))
32
30 def __repr__(self): 33 def __repr__(self):
31 return 'Ref({_repo!r}, {_ref!r})'.format(**self.__dict__) 34 return 'Ref({_repo!r}, {_ref!r})'.format(**self.__dict__)
32 35
33 # Accessors 36 # Accessors
34 # pylint: disable=W0212 37 # pylint: disable=W0212
35 repo = property(lambda self: self._repo) 38 repo = property(lambda self: self._repo)
36 ref = property(lambda self: self._ref) 39 ref = property(lambda self: self._ref)
37 40
38 # Properties 41 # Properties
39 @property 42 @property
(...skipping 15 matching lines...) Expand all
55 if self.commit is INVALID: 58 if self.commit is INVALID:
56 arg = other.ref 59 arg = other.ref
57 else: 60 else:
58 arg = '%s..%s' % (self.ref, other.ref) 61 arg = '%s..%s' % (self.ref, other.ref)
59 for hsh in self.repo.run('rev-list', '--reverse', arg).splitlines(): 62 for hsh in self.repo.run('rev-list', '--reverse', arg).splitlines():
60 yield self.repo.get_commit(hsh) 63 yield self.repo.get_commit(hsh)
61 64
62 def update_to(self, commit): 65 def update_to(self, commit):
63 """Update the local copy of the ref to |commit|.""" 66 """Update the local copy of the ref to |commit|."""
64 self.repo.run('update-ref', self.ref, commit.hsh) 67 self.repo.run('update-ref', self.ref, commit.hsh)
OLDNEW
« no previous file with comments | « no previous file | infra/libs/git2/repo.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698