run method

  1. @override
Future run()
override

Runs this command.

The return value is wrapped in a Future if necessary and returned by CommandRunner.runCommand.

Implementation

@override
Future run() async {
  var gitRootDir = GitRepository.findRootDir(Directory.current.path)!;
  var repo = await GitRepository.load(gitRootDir);

  GitHash? sha;
  if (argResults!.rest.isNotEmpty) {
    sha = GitHash(argResults!.rest.first);
  } else {
    sha = await repo.headHash();
    if (sha == null) {
      print('fatal: head hash not found');
      return;
    }
  }

  var seen = <GitHash>{};
  var parents = <GitHash?>[];
  parents.add(sha);

  while (parents.isNotEmpty) {
    var sha = parents[0]!;
    parents.removeAt(0);
    seen.add(sha);

    var objRes = await repo.objStorage.readCommit(sha);
    if (objRes.failed) {
      print('panic: object with sha $sha not found');
      return;
    }
    var commit = objRes.get();

    printCommit(repo, commit, sha);
    for (var p in commit.parents) {
      if (seen.contains(p)) continue;
      parents.add(p);
    }
  }
}