@@ -471,10 +471,8 @@ def __iter__(self):
471
471
... for line in Tree("954829887af5d9071aa92c427133ca2cdd0813cc"))
472
472
True
473
473
"""
474
- try :
475
- data = self .data
476
- except ObjectNotFound :
477
- data = ''
474
+ data = self .data
475
+
478
476
i = 0
479
477
while i < len (data ):
480
478
# mode
@@ -592,7 +590,7 @@ def blobs(self):
592
590
(<Blob: 2bdf5d686c6cd488b706be5c99c3bb1e166cf2f6>, ...,
593
591
<Blob: c006bef767d08b41633b380058a171b7786b71ab>)
594
592
"""
595
- return (Blob (sha ) for sha in self .files . values () )
593
+ return (Blob (sha ) for sha in self .blob_shas )
596
594
597
595
598
596
class Commit (GitObject ):
@@ -759,7 +757,8 @@ def children(self):
759
757
def blob_shas (self ):
760
758
""" SHA hashes of all blobs in the commit
761
759
762
- >>> Commit('af0048f4aac8f4760bf9b816e01524d7fb20a3fc').blob_shas # doctest: +NORMALIZE_WHITESPACE
760
+ >>> Commit('af0048f4aac8f4760bf9b816e01524d7fb20a3fc').blob_shas
761
+ ... # doctest: +NORMALIZE_WHITESPACE
763
762
('b2f49ffef1c8d7ce83a004b34035f917713e2766',
764
763
'c92011c5ccc32a9248bd929a6e56f846ac5b8072',
765
764
'bf3c2d2df2ef710f995b590ac3e2c851b592c871')
@@ -786,7 +785,8 @@ def blob_shas_rel(self):
786
785
def blobs (self ):
787
786
""" A generator of `Blob` objects included in this commit
788
787
789
- >>> tuple(Commit('af0048f4aac8f4760bf9b816e01524d7fb20a3fc').blobs) # doctest: +NORMALIZE_WHITESPACE
788
+ >>> tuple(Commit('af0048f4aac8f4760bf9b816e01524d7fb20a3fc').blobs)
789
+ ... # doctest: +NORMALIZE_WHITESPACE
790
790
(<Blob: b2f49ffef1c8d7ce83a004b34035f917713e2766>,
791
791
<Blob: c92011c5ccc32a9248bd929a6e56f846ac5b8072>,
792
792
<Blob: bf3c2d2df2ef710f995b590ac3e2c851b592c871>)
@@ -840,8 +840,8 @@ def __iter__(self):
840
840
True
841
841
"""
842
842
for sha in self .commit_shas :
843
- c = Commit (sha )
844
843
try :
844
+ c = Commit (sha )
845
845
author = c .author
846
846
except ObjectNotFound :
847
847
continue
@@ -880,7 +880,8 @@ def all(cls, name_prefix=''):
880
880
def commit_shas (self ):
881
881
""" SHA1 of all commits in the project
882
882
883
- >>> Project('user2589_django-currencies').commit_shas # doctest: +NORMALIZE_WHITESPACE
883
+ >>> Project('user2589_django-currencies').commit_shas
884
+ ... # doctest: +NORMALIZE_WHITESPACE
884
885
('2dbcd43f077f2b5511cc107d63a0b9539a6aa2a7',
885
886
'7572fc070c44f85e2a540f9a5a05a95d1dd2662d')
886
887
"""
@@ -893,7 +894,8 @@ def commits(self):
893
894
It has the same effect as iterating a `Project` instance itself,
894
895
with some additional validation of commit dates.
895
896
896
- >>> tuple(Project('user2589_django-currencies').commits) # doctest: +NORMALIZE_WHITESPACE
897
+ >>> tuple(Project('user2589_django-currencies').commits)
898
+ ... # doctest: +NORMALIZE_WHITESPACE
897
899
(<Commit: 2dbcd43f077f2b5511cc107d63a0b9539a6aa2a7>,
898
900
<Commit: 7572fc070c44f85e2a540f9a5a05a95d1dd2662d>)
899
901
"""
@@ -975,19 +977,22 @@ def commits_fp(self):
975
977
# simplified version (argmax): ~153 seconds
976
978
# self.head(): ~190 seconds
977
979
978
- # Sometimes (very rarely) commit dates are wrong, so the latest commit
979
- # is not actually the head. The magic below is to account for this
980
+ # at this point we know all commits are in the dataset
981
+ # (validated in __iter___)
980
982
commits = {c .sha : c for c in self .commits }
981
983
commit = max (commits .values (), key = lambda c : c .authored_at or DAY_Z )
982
984
while commit :
985
+ try : # here there is no guarantee commit is in the dataset
986
+ first_parent = commit .parent_shas and commit .parent_shas [0 ]
987
+ except ObjectNotFound :
988
+ break
989
+
983
990
yield commit
984
- if not commit .parent_shas :
991
+
992
+ if not first_parent :
985
993
break
986
- if commit .parent_shas [0 ] in commits :
987
- # save a bit of time on instantiation
988
- commit = commits [commit .parent_shas [0 ]]
989
- else :
990
- commit = Commit (commit .parent_shas [0 ])
994
+
995
+ commit = commits .get (first_parent , Commit (first_parent ))
991
996
992
997
993
998
class File (_Base ):
0 commit comments