#!/usr/bin/perl
# usage: tb-list [<patch-spec>]
#  lists all patches matching <patch-spec> and other criteria

use warnings;
use strict;

use Getopt::Long;
use Topbloke;

Getopt::Long::Configure(qw(bundling));

our $deleted=0;
our $deleted_only=0;
our $current=0;
our $related=0;
our $leaves=0;
our $sort='';

GetOptions("d|deleted!" => \$deleted,         # including deleted patches
	   "deleted-only!" => \$deleted_only, # only deleted patches
	   "r|related=s" => \$related,       # only patches related to this one
	   "l|last|leaf|leaves" => \$leaves, # only leaf patches
	   "sort=s" => \$sort,
    ) or die "bad options\n";

our $spec;

if (@ARGV==1) {
    $spec = parse_patch_spec($ARGV[0]);
} elsif (!@ARGV) {
} else {
    die "too many arguments\n";
}

our @sort = grep { /./ } split m/,/, $sort;
push @sort, $spec ? 'created' : 'topo';
foreach $sort (@sort) {
    die "bad sort $sort\n" unless grep { $_ eq $sort } 
        qw(fullname created nick topo);
}

use Data::Dumper;

foreach_patch($spec, $deleted || $deleted_only, [], sub {
    print Dumper(\@_);
	      });
