| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  |  | 
| 2 |  |  |  |  |  |  | # Created on: 2014-03-11 20:58:59 | 
| 3 |  |  |  |  |  |  | # Create by:  Ivan Wills | 
| 4 |  |  |  |  |  |  | # $Id$ | 
| 5 |  |  |  |  |  |  | # $Revision$, $HeadURL$, $Date$ | 
| 6 |  |  |  |  |  |  | # $Revision$, $Source$, $Date$ | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | use strict; | 
| 9 | 2 |  |  | 2 |  | 97536 | use warnings; | 
|  | 2 |  |  |  |  | 15 |  | 
|  | 2 |  |  |  |  | 49 |  | 
| 10 | 2 |  |  | 2 |  | 9 | use version; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 38 |  | 
| 11 | 2 |  |  | 2 |  | 378 | use English qw/ -no_match_vars /; | 
|  | 2 |  |  |  |  | 1613 |  | 
|  | 2 |  |  |  |  | 10 |  | 
| 12 | 2 |  |  | 2 |  | 614 | use Term::ANSIColor qw/colored/; | 
|  | 2 |  |  |  |  | 3048 |  | 
|  | 2 |  |  |  |  | 9 |  | 
| 13 | 2 |  |  | 2 |  | 1189 | use App::Git::Workflow; | 
|  | 2 |  |  |  |  | 7177 |  | 
|  | 2 |  |  |  |  | 1557 |  | 
| 14 | 2 |  |  | 2 |  | 397 | use App::Git::Workflow::Command qw/get_options/; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 75 |  | 
| 15 | 2 |  |  | 2 |  | 351 |  | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 1034 |  | 
| 16 |  |  |  |  |  |  | our $VERSION  = version->new(1.1.19); | 
| 17 |  |  |  |  |  |  | our $workflow = App::Git::Workflow->new; | 
| 18 |  |  |  |  |  |  | our ($name)   = $PROGRAM_NAME =~ m{^.*/(.*?)$}mxs; | 
| 19 |  |  |  |  |  |  | our %option = ( | 
| 20 |  |  |  |  |  |  | master => 'origin/master', | 
| 21 |  |  |  |  |  |  | ); | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | get_options( | 
| 24 |  |  |  |  |  |  | \%option, | 
| 25 | 4 |  |  | 4 | 1 | 16 | 'search|s=s', | 
| 26 |  |  |  |  |  |  | 'colour|color|c', | 
| 27 |  |  |  |  |  |  | 'insensitive|i', | 
| 28 |  |  |  |  |  |  | 'unmerged|u!', | 
| 29 |  |  |  |  |  |  | 'master|m=s', | 
| 30 |  |  |  |  |  |  | 'limit|n=i', | 
| 31 |  |  |  |  |  |  | ); | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | $ARGV[0] ||= ''; | 
| 34 |  |  |  |  |  |  | my $grep = $option{insensitive} ? "(?i:$ARGV[0])" : $ARGV[0]; | 
| 35 | 4 |  | 100 |  |  | 11 | shift @ARGV; | 
| 36 | 4 | 100 |  |  |  | 11 |  | 
| 37 | 4 |  |  |  |  | 7 | my $count = 1; | 
| 38 |  |  |  |  |  |  |  | 
| 39 | 4 |  |  |  |  | 6 | for my $tag ( sort {_sorter()} grep {/$grep/} $workflow->git->tag ) { | 
| 40 |  |  |  |  |  |  | if ( $option{unmerged} ) { | 
| 41 | 4 |  |  |  |  | 14 | next if unmerged($tag, $option{master}); | 
|  | 4 |  |  |  |  | 8 |  | 
|  | 11 |  |  |  |  | 76 |  | 
| 42 | 6 | 50 |  |  |  | 19 | } | 
| 43 | 0 | 0 |  |  |  | 0 |  | 
| 44 |  |  |  |  |  |  | last if $option{limit} && $count++ > $option{limit}; | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 6 | 50 | 33 |  |  | 19 | if (@ARGV) { | 
| 47 |  |  |  |  |  |  | my $shown = 0; | 
| 48 | 6 | 50 |  |  |  | 15 | for my $file (@ARGV) { | 
| 49 | 0 |  |  |  |  | 0 | my @contents = map { | 
| 50 | 0 |  |  |  |  | 0 | my $found = $_; | 
| 51 |  |  |  |  |  |  | if ($option{colour}) { | 
| 52 | 0 |  |  |  |  | 0 | $found =~ s/($grep)/colored ['red'], $1/egxms; | 
| 53 | 0 | 0 |  |  |  | 0 | } | 
| 54 | 0 |  |  |  |  | 0 | $found | 
|  | 0 |  |  |  |  | 0 |  | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  | grep {/$option{search}/} | 
| 57 | 0 |  |  |  |  | 0 | `git show $tag:$file`; | 
| 58 | 0 |  |  |  |  | 0 | if (@contents) { | 
|  | 0 |  |  |  |  | 0 |  | 
| 59 |  |  |  |  |  |  | if (!$shown++) { | 
| 60 | 0 | 0 |  |  |  | 0 | print "$tag\n"; | 
| 61 | 0 | 0 |  |  |  | 0 | } | 
| 62 | 0 |  |  |  |  | 0 | print " $file\n"; | 
| 63 |  |  |  |  |  |  | print @contents; | 
| 64 | 0 |  |  |  |  | 0 | print "\n"; | 
| 65 | 0 |  |  |  |  | 0 | } | 
| 66 | 0 |  |  |  |  | 0 | } | 
| 67 |  |  |  |  |  |  | } | 
| 68 |  |  |  |  |  |  | else { | 
| 69 |  |  |  |  |  |  | if ( $option{colour} ) { | 
| 70 |  |  |  |  |  |  | $tag =~ s/($grep)/colored ['red'], $1 /egxms; | 
| 71 | 6 | 50 |  |  |  | 10 | } | 
| 72 | 0 |  |  |  |  | 0 | print "$tag\n"; | 
|  | 0 |  |  |  |  | 0 |  | 
| 73 |  |  |  |  |  |  | } | 
| 74 | 6 |  |  |  |  | 164 | } | 
| 75 |  |  |  |  |  |  | } | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | no warnings; | 
| 78 |  |  |  |  |  |  | my $A = $a; | 
| 79 |  |  |  |  |  |  | my $B = $b; | 
| 80 | 2 |  |  | 2 |  | 13 | $A =~ s/(\d+)/sprintf "%06d", $1/egxms; | 
|  | 2 |  |  |  |  | 3 |  | 
|  | 2 |  |  |  |  | 553 |  | 
| 81 | 4 |  |  | 4 |  | 8 | $B =~ s/(\d+)/sprintf "%06d", $1/egxms; | 
| 82 | 4 |  |  |  |  | 5 | $A cmp $B; | 
| 83 | 4 |  |  |  |  | 9 | } | 
|  | 2 |  |  |  |  | 11 |  | 
| 84 | 4 |  |  |  |  | 6 |  | 
|  | 2 |  |  |  |  | 8 |  | 
| 85 | 4 |  |  |  |  | 10 | my %dest; | 
| 86 |  |  |  |  |  |  | my ($source, $dest) = @_; | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | if ( ! $dest{$dest} ) { | 
| 89 |  |  |  |  |  |  | @{$dest{$dest}} = map {/^(.*)\n/; $1} `git log --format=format:%H $dest`; | 
| 90 | 0 |  |  | 0 | 1 |  | die "No destination branch commits for '$dest'" if !@{$dest{$dest}}; | 
| 91 |  |  |  |  |  |  | } | 
| 92 | 0 | 0 |  |  |  |  |  | 
| 93 | 0 |  |  |  |  |  | my $source_sha = `git log --format=format:%H -n 1 $source`; | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 94 | 0 | 0 |  |  |  |  | chomp $source_sha; | 
|  | 0 |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | return scalar grep {$_ && $_ eq $source_sha} @{$dest{$dest}}; | 
| 97 | 0 |  |  |  |  |  | } | 
| 98 | 0 |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | 1; | 
| 100 | 0 | 0 |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
|  | 0 |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | =head1 NAME | 
| 103 |  |  |  |  |  |  |  | 
| 104 |  |  |  |  |  |  | git-tag-grep - grep tags (and optionally files with them) | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | =head1 VERSION | 
| 107 |  |  |  |  |  |  |  | 
| 108 |  |  |  |  |  |  | This documentation refers to git-tag-grep version 1.1.19 | 
| 109 |  |  |  |  |  |  |  | 
| 110 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | git-tag-grep [option] regex | 
| 113 |  |  |  |  |  |  | git-tag-grep ((-s|--search) regex) [option] regex -- file(s) | 
| 114 |  |  |  |  |  |  |  | 
| 115 |  |  |  |  |  |  | OPTIONS: | 
| 116 |  |  |  |  |  |  | regex         grep's perl (-P) regular expression | 
| 117 |  |  |  |  |  |  | file          When a file is specified the regexp will be run on the file | 
| 118 |  |  |  |  |  |  | not the tag name. | 
| 119 |  |  |  |  |  |  | -v            Find all tags that don't match regex | 
| 120 |  |  |  |  |  |  | -u --unmerged | 
| 121 |  |  |  |  |  |  | Only show tags not merged to --master | 
| 122 |  |  |  |  |  |  | --no-unmerged | 
| 123 |  |  |  |  |  |  | Only show tags merged to master | 
| 124 |  |  |  |  |  |  | -m --master[=]str | 
| 125 |  |  |  |  |  |  | Branch to check against for --unmerged and --no-unmerged | 
| 126 |  |  |  |  |  |  | (Default origin/master) | 
| 127 |  |  |  |  |  |  | -n --limit[=]int | 
| 128 |  |  |  |  |  |  | Limit the out put to this number | 
| 129 |  |  |  |  |  |  | -s --search[=]regex | 
| 130 |  |  |  |  |  |  | Search term for looking within files | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | --verbose  Show more detailed option | 
| 133 |  |  |  |  |  |  | --version  Prints the version information | 
| 134 |  |  |  |  |  |  | --help     Prints this help information | 
| 135 |  |  |  |  |  |  | --man      Prints the full documentation for git-tag-grep | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | Note: to search in all tags set the regex to '' | 
| 138 |  |  |  |  |  |  | eg git tag-grep --search thin '' -- file1 file2 | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 141 |  |  |  |  |  |  |  | 
| 142 |  |  |  |  |  |  | Short hand for running | 
| 143 |  |  |  |  |  |  |  | 
| 144 |  |  |  |  |  |  | C<git tag | grep -P 'regex'> | 
| 145 |  |  |  |  |  |  |  | 
| 146 |  |  |  |  |  |  | =head1 SUBROUTINES/METHODS | 
| 147 |  |  |  |  |  |  |  | 
| 148 |  |  |  |  |  |  | =head2 C<run ()> | 
| 149 |  |  |  |  |  |  |  | 
| 150 |  |  |  |  |  |  | Executes the git workflow command | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | =head2 C<unmerged ($source, $dest)> | 
| 153 |  |  |  |  |  |  |  | 
| 154 |  |  |  |  |  |  | Check if there are any commits in C<$source> that are not in C<$dest> | 
| 155 |  |  |  |  |  |  |  | 
| 156 |  |  |  |  |  |  | =head1 DIAGNOSTICS | 
| 157 |  |  |  |  |  |  |  | 
| 158 |  |  |  |  |  |  | =head1 CONFIGURATION AND ENVIRONMENT | 
| 159 |  |  |  |  |  |  |  | 
| 160 |  |  |  |  |  |  | =head1 DEPENDENCIES | 
| 161 |  |  |  |  |  |  |  | 
| 162 |  |  |  |  |  |  | =head1 INCOMPATIBILITIES | 
| 163 |  |  |  |  |  |  |  | 
| 164 |  |  |  |  |  |  | =head1 BUGS AND LIMITATIONS | 
| 165 |  |  |  |  |  |  |  | 
| 166 |  |  |  |  |  |  | There are no known bugs in this module. | 
| 167 |  |  |  |  |  |  |  | 
| 168 |  |  |  |  |  |  | Please report problems to Ivan Wills (ivan.wills@gmail.com). | 
| 169 |  |  |  |  |  |  |  | 
| 170 |  |  |  |  |  |  | Patches are welcome. | 
| 171 |  |  |  |  |  |  |  | 
| 172 |  |  |  |  |  |  | =head1 AUTHOR | 
| 173 |  |  |  |  |  |  |  | 
| 174 |  |  |  |  |  |  | Ivan Wills - (ivan.wills@gmail.com) | 
| 175 |  |  |  |  |  |  |  | 
| 176 |  |  |  |  |  |  | =head1 LICENSE AND COPYRIGHT | 
| 177 |  |  |  |  |  |  |  | 
| 178 |  |  |  |  |  |  | Copyright (c) 2014 Ivan Wills (14 Mullion Close, Hornsby Heights, NSW Australia 2077). | 
| 179 |  |  |  |  |  |  | All rights reserved. | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  | This module is free software; you can redistribute it and/or modify it under | 
| 182 |  |  |  |  |  |  | the same terms as Perl itself. See L<perlartistic>.  This program is | 
| 183 |  |  |  |  |  |  | distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | 
| 184 |  |  |  |  |  |  | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A | 
| 185 |  |  |  |  |  |  | PARTICULAR PURPOSE. | 
| 186 |  |  |  |  |  |  |  | 
| 187 |  |  |  |  |  |  | =cut |