@@ -107,6 +107,19 @@ class CLIDependencyListener(DependencyListener):
107107 too long for useful output if recursion is enabled.
108108 """
109109
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+
110123 def new_dependency (self , dependent , dependency , path , line_num ):
111124 dependent_sha1 = dependent .hex
112125 dependency_sha1 = dependency .hex
@@ -117,10 +130,10 @@ def new_dependency(self, dependent, dependency, path, line_num):
117130 else :
118131 print ("%s %s" % (dependent_sha1 , dependency_sha1 ))
119132 else :
120- if not self .options .log :
133+ if not self .options .log and self . _revs [ dependency_sha1 ] <= 1 :
121134 print (dependency_sha1 )
122135
123- if self .options .log :
136+ if self .options .log and self . _revs [ dependency_sha1 ] <= 1 :
124137 cmd = [
125138 'git' ,
126139 '--no-pager' ,
@@ -281,6 +294,12 @@ def refs_to(cls, sha1, repo):
281294
282295 return matching
283296
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+
284303class InvalidCommitish (StandardError ):
285304 def __init__ (self , commitish ):
286305 self .commitish = commitish
@@ -367,6 +386,9 @@ def default_logger(self):
367386 logger .addHandler (handler )
368387 return logger
369388
389+ def seen_commit (self , rev ):
390+ return rev in self .commits
391+
370392 def get_commit (self , rev ):
371393 if rev in self .commits :
372394 return self .commits [rev ]
@@ -670,11 +692,12 @@ def cli(options, args):
670692
671693 detector .add_listener (listener )
672694
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
678701
679702 if options .json :
680703 print (json .dumps (listener .json (), sort_keys = True , indent = 4 ))
@@ -743,26 +766,43 @@ def send_options():
743766 client_options ['repo_path' ] = os .getcwd ()
744767 return jsonify (client_options )
745768
746- @webserver .route ('/deps.json/<commitish >' )
747- def deps (commitish ):
769+ @webserver .route ('/deps.json/<revspec >' )
770+ def deps (revspec ):
748771 detector = DependencyDetector (options )
749772 listener = JSONDependencyListener (options )
750773 detector .add_listener (listener )
751774
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
759799
760- detector .find_dependencies (commitish )
761800 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 ),
766806 }
767807 return jsonify (json )
768808
0 commit comments