def cli(options, args): detector = DependencyDetector(options) if options.json: listener = JSONDependencyListener(options) else: listener = CLIDependencyListener(options) detector.add_listener(listener) if len(args) > 1: options.multi = True for revspec in args: revs = GitUtils.rev_parse(revspec) if len(revs) > 1: revs = GitUtils.rev_list(revspec) if len(revs) > 1: options.multi = True for rev in revs: detector.find_dependencies(rev) if options.json: print(json.dumps(listener.json(), sort_keys=True, indent=4))
def get_dependencies(self): """ Detect commit dependency tree, and return a tuple of dicts mapping this in both directions. Note that the dependency tree goes in the reverse direction to the git commit graph, in that the leaves of the dependency tree are the oldest commits, because newer commits depend on older commits :return: (dependencies_from, dependencies_on) """ detector_args = OpenStruct({ 'recurse': True, 'exclude_commits': [self.base], 'debug': self.debug, 'context_lines': self.context_lines, }) detector = DependencyDetector(detector_args, self.repo) listener = ExplodeDependencyListener({}) detector.add_listener(listener) revs = GitUtils.rev_list("%s..%s" % (self.base, self.head)) for rev in revs: try: detector.find_dependencies(rev) except KeyboardInterrupt: pass return (detector.commits, listener.dependencies_from(), listener.dependencies_on())
def deps(revspec): detector = DependencyDetector(options) listener = JSONDependencyListener(options) detector.add_listener(listener) if '..' in revspec: try: revisions = GitUtils.rev_list(revspec) except subprocess.CalledProcessError: return json_error(422, 'Invalid revision range', "Could not resolve revision range '%s'" % revspec, revspec=revspec) else: revisions = [revspec] for rev in revisions: try: detector.get_commit(rev) except InvalidCommitish: return json_error(422, 'Invalid revision', "Could not resolve revision '%s'" % rev, rev=rev) detector.find_dependencies(rev) tip_commit = detector.get_commit(revisions[0]) tip_sha1 = tip_commit.hex json = listener.json() json['query'] = { 'revspec': revspec, 'revisions': revisions, 'tip_sha1': tip_sha1, 'tip_abbrev': GitUtils.abbreviate_sha1(tip_sha1), } return jsonify(json)