@@ -107,6 +107,19 @@ class CLIDependencyListener(DependencyListener):
107
107
too long for useful output if recursion is enabled.
108
108
"""
109
109
110
+ def __init__ (self , options ):
111
+ super (CLIDependencyListener , self ).__init__ (options )
112
+
113
+ # Count each mention of each revision, so we can avoid duplicating
114
+ # commits in the output.
115
+ self ._revs = {}
116
+
117
+ def new_commit (self , commit ):
118
+ rev = commit .hex
119
+ if rev not in self ._revs :
120
+ self ._revs [rev ] = 0
121
+ self ._revs [rev ] += 1
122
+
110
123
def new_dependency (self , dependent , dependency , path , line_num ):
111
124
dependent_sha1 = dependent .hex
112
125
dependency_sha1 = dependency .hex
@@ -117,10 +130,10 @@ def new_dependency(self, dependent, dependency, path, line_num):
117
130
else :
118
131
print ("%s %s" % (dependent_sha1 , dependency_sha1 ))
119
132
else :
120
- if not self .options .log :
133
+ if not self .options .log and self . _revs [ dependency_sha1 ] <= 1 :
121
134
print (dependency_sha1 )
122
135
123
- if self .options .log :
136
+ if self .options .log and self . _revs [ dependency_sha1 ] <= 1 :
124
137
cmd = [
125
138
'git' ,
126
139
'--no-pager' ,
@@ -281,6 +294,12 @@ def refs_to(cls, sha1, repo):
281
294
282
295
return matching
283
296
297
+ @classmethod
298
+ def rev_list (cls , rev_range ):
299
+ cmd = ['git' , 'rev-list' , rev_range ]
300
+ return subprocess .check_output (cmd ).strip ().split ('\n ' )
301
+
302
+
284
303
class InvalidCommitish (StandardError ):
285
304
def __init__ (self , commitish ):
286
305
self .commitish = commitish
@@ -367,6 +386,9 @@ def default_logger(self):
367
386
logger .addHandler (handler )
368
387
return logger
369
388
389
+ def seen_commit (self , rev ):
390
+ return rev in self .commits
391
+
370
392
def get_commit (self , rev ):
371
393
if rev in self .commits :
372
394
return self .commits [rev ]
@@ -670,11 +692,12 @@ def cli(options, args):
670
692
671
693
detector .add_listener (listener )
672
694
673
- for dependent_rev in args :
674
- try :
675
- detector .find_dependencies (dependent_rev )
676
- except KeyboardInterrupt :
677
- pass
695
+ for revspec in args :
696
+ for rev in GitUtils .rev_list (revspec ):
697
+ try :
698
+ detector .find_dependencies (rev )
699
+ except KeyboardInterrupt :
700
+ pass
678
701
679
702
if options .json :
680
703
print (json .dumps (listener .json (), sort_keys = True , indent = 4 ))
@@ -743,26 +766,43 @@ def send_options():
743
766
client_options ['repo_path' ] = os .getcwd ()
744
767
return jsonify (client_options )
745
768
746
- @webserver .route ('/deps.json/<commitish >' )
747
- def deps (commitish ):
769
+ @webserver .route ('/deps.json/<revspec >' )
770
+ def deps (revspec ):
748
771
detector = DependencyDetector (options )
749
772
listener = JSONDependencyListener (options )
750
773
detector .add_listener (listener )
751
774
752
- try :
753
- root_commit = detector .get_commit (commitish )
754
- except InvalidCommitish as e :
755
- return json_error (
756
- 422 , 'Invalid commitish' ,
757
- "Could not resolve commitish '%s'" % commitish ,
758
- commitish = commitish )
775
+ if '..' in revspec :
776
+ try :
777
+ revisions = GitUtils .rev_list (revspec )
778
+ except subprocess .CalledProcessError as e :
779
+ return json_err (
780
+ 422 , 'Invalid revision range' ,
781
+ "Could not resolve revision range '%s'" % revspec ,
782
+ revspec = revspec )
783
+ else :
784
+ revisions = [revspec ]
785
+
786
+ for rev in revisions :
787
+ try :
788
+ commit = detector .get_commit (rev )
789
+ except InvalidCommitish as e :
790
+ return json_error (
791
+ 422 , 'Invalid revision' ,
792
+ "Could not resolve revision '%s'" % rev ,
793
+ rev = rev )
794
+
795
+ detector .find_dependencies (rev )
796
+
797
+ tip_commit = detector .get_commit (revisions [0 ])
798
+ tip_sha1 = tip_commit .hex
759
799
760
- detector .find_dependencies (commitish )
761
800
json = listener .json ()
762
- json ['root' ] = {
763
- 'commitish' : commitish ,
764
- 'sha1' : root_commit .hex ,
765
- 'abbrev' : GitUtils .abbreviate_sha1 (root_commit .hex ),
801
+ json ['query' ] = {
802
+ 'revspec' : revspec ,
803
+ 'revisions' : revisions ,
804
+ 'tip_sha1' : tip_sha1 ,
805
+ 'tip_abbrev' : GitUtils .abbreviate_sha1 (tip_sha1 ),
766
806
}
767
807
return jsonify (json )
768
808
0 commit comments