@@ -203,16 +203,28 @@ def clone(self):
203
203
def tags (self ):
204
204
versions = []
205
205
repo = git .Repo (self .working_dir )
206
+
207
+ # Build a cache of tag -> commit
208
+ # GitPython is not very optimized for reading large numbers of tags
209
+ ref_cache = {} # 'ref/tags/<tag>' -> hexsha
210
+ for hexsha , ref in git .TagReference ._iter_packed_refs (repo ):
211
+ ref_cache [ref ] = hexsha
212
+
206
213
for tag in repo .tags :
207
- try :
208
- versions .append (VCSVersion (self , str (tag .commit ), str (tag )))
209
- except ValueError :
210
- # ValueError: Cannot resolve commit as tag TAGNAME points to a
211
- # blob object - use the `.object` property instead to access it
212
- # This is not a real tag for us, so we skip it
213
- # https://github.com/rtfd/readthedocs.org/issues/4440
214
- log .warning ('Git tag skipped: %s' , tag , exc_info = True )
215
- continue
214
+ if tag .path in ref_cache :
215
+ hexsha = ref_cache [tag .path ]
216
+ else :
217
+ try :
218
+ hexsha = str (tag .commit )
219
+ except ValueError :
220
+ # ValueError: Cannot resolve commit as tag TAGNAME points to a
221
+ # blob object - use the `.object` property instead to access it
222
+ # This is not a real tag for us, so we skip it
223
+ # https://github.com/rtfd/readthedocs.org/issues/4440
224
+ log .warning ('Git tag skipped: %s' , tag , exc_info = True )
225
+ continue
226
+
227
+ versions .append (VCSVersion (self , hexsha , str (tag )))
216
228
return versions
217
229
218
230
@property
0 commit comments