#!/usr/bin/perl -w
use strict;
use Git;
use StableHelper;

my $editor = $ENV{'EDITOR'} || 'vim';
my $file = $ARGV[0];

die "'$file' does not exist" unless (-f $file);

my $repo = Git->repository(Directory => '/home/latest/linux');

my @lines = <>;

my @commits = StableHelper::get_upstream_commits(@lines);

foreach my $SHA (@commits) {
	git_cmd_try {
		$SHA = $repo->command_oneline('rev-parse', $SHA);
	} "bad SHA";

	$repo->command_noisy('show', '--color', $SHA);
}

print "Run editor [y/N]? ";
if (<STDIN> =~ /^[yY]/) {
	exec $editor, $file;
}

print "Remove [y/N]? ";
if (<STDIN> =~ /^[yY]/) {
	exec 'stable_rm', $file;
}

1;
