Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbb24f67

Browse files
committed
Fixed object bug that would cause object ids not to be resolved to sha's as this was assumed - now there is a test for it as well
repo: removed diff and commit_diff methods, added 'head' property returning the current head as Reference object
1 parent919164d commitbb24f67

File tree

6 files changed

+39
-41
lines changed

6 files changed

+39
-41
lines changed

‎CHANGES‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ Repo
6060
related repositories, i.e. clones, git-rev-list would be sufficient to find
6161
commits that would need to be transferred for example.
6262
- 'create' method which equals the 'init' method's functionality
63+
- 'diff' - it returned a mere string which still had to be parsed
64+
- 'commit_diff' - moved to Commit, Tree and Diff types respectively
6365
* Renamed the following methods:
6466
- commits to iter_commits to improve the performance, adjusted signature
6567
- init_bare to init, implying less about the options to be used

‎lib/git/objects/base.py‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,12 @@ class Object(LazyMixin):
1515
1616
This Object also serves as a constructor for instances of the correct type::
1717
18-
inst = Object(repo,id)
18+
inst = Object.new(repo,id)
1919
"""
2020
TYPES= ("blob","tree","commit","tag")
2121
__slots__= ("repo","id","size","data" )
2222
type=None# to be set by subclass
2323

24-
def__new__(cls,repo,id,*args,**kwargs):
25-
ifclsisObject:
26-
hexsha,typename,size=repo.git.get_object_header(id)
27-
obj_type=utils.get_object_type_by_name(typename)
28-
inst=super(Object,cls).__new__(obj_type,repo,hexsha,*args,**kwargs)
29-
inst.size=size
30-
returninst
31-
else:
32-
returnsuper(Object,cls).__new__(cls,repo,id,*args,**kwargs)
33-
3424
def__init__(self,repo,id):
3525
"""
3626
Initialize an object by identifying it by its id. All keyword arguments
@@ -45,7 +35,25 @@ def __init__(self, repo, id):
4535
super(Object,self).__init__()
4636
self.repo=repo
4737
self.id=id
48-
38+
39+
@classmethod
40+
defnew(cls,repo,id):
41+
"""
42+
Return
43+
New Object instance of a type appropriate to the object type behind
44+
id. The id of the newly created object will be a hexsha even though
45+
the input id may have been a Reference or Rev-Spec
46+
47+
Note
48+
This cannot be a __new__ method as it would always call __init__
49+
with the input id which is not necessarily a hexsha.
50+
"""
51+
hexsha,typename,size=repo.git.get_object_header(id)
52+
obj_type=utils.get_object_type_by_name(typename)
53+
inst=obj_type(repo,hexsha)
54+
inst.size=size
55+
returninst
56+
4957
def_set_self_from_args_(self,args_dict):
5058
"""
5159
Initialize attributes on self from the given dict that was retrieved

‎lib/git/refs.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def object(self):
7272
"""
7373
# have to be dynamic here as we may be a tag which can point to anything
7474
# Our path will be resolved to the hexsha which will be used accordingly
75-
returnObject(self.repo,self.path)
75+
returnObject.new(self.repo,self.path)
7676

7777
@classmethod
7878
defiter_items(cls,repo,common_path="refs",**kwargs):

‎lib/git/repo.py‎

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ def heads(self):
106106
# alias heads
107107
branches=heads
108108

109+
@property
110+
defhead(self):
111+
"""
112+
Return
113+
Head Object, reference pointing to the current head of the repository
114+
"""
115+
returnHead(self,'HEAD')
116+
117+
109118
@property
110119
deftags(self):
111120
"""
@@ -129,7 +138,7 @@ def commit(self, rev=None):
129138
ifrevisNone:
130139
rev=self.active_branch
131140

132-
c=Object(self,rev)
141+
c=Object.new(self,rev)
133142
assertc.type=="commit","Revision %s did not point to a commit, but to %s"% (rev,c)
134143
returnc
135144

@@ -327,34 +336,7 @@ def active_branch(self):
327336
"""
328337
returnHead(self,self.git.symbolic_ref('HEAD').strip() )
329338

330-
331-
defdiff(self,a,b,*paths):
332-
"""
333-
The diff from commit ``a`` to commit ``b``, optionally restricted to the given file(s)
334-
335-
``a``
336-
is the base commit
337-
``b``
338-
is the other commit
339-
340-
``paths``
341-
is an optional list of file paths on which to restrict the diff
342339

343-
Returns
344-
``str``
345-
"""
346-
returnself.git.diff(a,b,'--',*paths)
347-
348-
defcommit_diff(self,commit):
349-
"""
350-
The commit diff for the given commit
351-
``commit`` is the commit name/id
352-
353-
Returns
354-
``git.Diff[]``
355-
"""
356-
returnCommit.diff(self,commit)
357-
358340
defblame(self,rev,file):
359341
"""
360342
The blame information for the given file at the given revision.

‎test/git/test_base.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,6 @@ def test_get_object_type_by_name(self):
9090

9191
assert_raises(ValueError,get_object_type_by_name,"doesntexist" )
9292

93+
deftest_object_resolution(self):
94+
# objects must be resolved to shas so they compare equal
95+
assertself.repo.head.object==self.repo.active_branch.object

‎test/git/test_repo.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ def test_active_branch(self, git):
199199
assert_equal(self.repo.active_branch.name,'major-refactoring')
200200
assert_equal(git.call_args, (('symbolic_ref','HEAD'), {}))
201201

202+
deftest_head(self):
203+
assertself.repo.head.object==self.repo.active_branch.object
204+
202205
@patch_object(Git,'_call_process')
203206
deftest_should_display_blame_information(self,git):
204207
git.return_value=fixture('blame')

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp