| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||||||||||||||||
| 2 | package Autofixup; | ||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use 5.008004; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use File::Copy; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use File::Spec (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use File::Temp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Getopt::Long qw(:config bundling); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use IPC::Open3; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | our $VERSION = 0.005000; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | my $VERBOSE; | |||||||||||||||||||||||||||||||||||||||||
| 17 | my @GIT_OPTIONS; | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | # Strictness levels. | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 3 | my @STRICTNESS_LEVELS = ( | |||||||||||||||||||||||||||||||||||||||||
| 21 | my $CONTEXT = 0, | ||||||||||||||||||||||||||||||||||||||||||
| 22 | my $ADJACENT = 1, | ||||||||||||||||||||||||||||||||||||||||||
| 23 | my $SURROUNDED = 2, | ||||||||||||||||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | my $usage =<<'END'; | |||||||||||||||||||||||||||||||||||||||||
| 27 | usage: git-autofixup [<options>] [<revision>] [--] [<path>...] | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | -h show usage | ||||||||||||||||||||||||||||||||||||||||||
| 30 | --help show manpage | ||||||||||||||||||||||||||||||||||||||||||
| 31 | --version show version | ||||||||||||||||||||||||||||||||||||||||||
| 32 | -v, --verbose increase verbosity (use up to 2 times) | ||||||||||||||||||||||||||||||||||||||||||
| 33 | -c N, --context N set number of diff context lines (default 3) | ||||||||||||||||||||||||||||||||||||||||||
| 34 | -e, --exit-code use more detailed exit codes (see --help) | ||||||||||||||||||||||||||||||||||||||||||
| 35 | -s N, --strict N set strictness (default 0) | ||||||||||||||||||||||||||||||||||||||||||
| 36 | Assign a hunk to fixup a topic branch commit if: | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 0: either only one topic branch commit is blamed in the hunk context or | ||||||||||||||||||||||||||||||||||||||||||
| 39 | blocks of added lines are adjacent to exactly one topic branch commit. | ||||||||||||||||||||||||||||||||||||||||||
| 40 | Removing upstream lines is allowed for this level. | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 1: blocks of added lines are adjacent to exactly one topic branch commit | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 2: blocks of added lines are surrounded by exactly one topic branch commit | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | Regardless of strictness level, removed lines are correlated with the | ||||||||||||||||||||||||||||||||||||||||||
| 45 | commit they're blamed on, and all the blocks of changed lines in a hunk | ||||||||||||||||||||||||||||||||||||||||||
| 46 | must be correlated with the same topic branch commit in order to be | ||||||||||||||||||||||||||||||||||||||||||
| 47 | assigned to it. See the --help for more details. | ||||||||||||||||||||||||||||||||||||||||||
| 48 | -g ARG, --gitopt ARG | ||||||||||||||||||||||||||||||||||||||||||
| 49 | Specify option for git. Can be used multiple times. Deprecated in favor of | ||||||||||||||||||||||||||||||||||||||||||
| 50 | GIT_CONFIG_{COUNT,KEY,VALUE} environment variables; see `git help config`. | ||||||||||||||||||||||||||||||||||||||||||
| 51 | END | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | # Parse hunks out of `git diff` output. Return an array of hunk hashrefs. | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 54 | ▶ | sub parse_hunks { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_hunks: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 54 | my $fh = shift; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 54 | my ($file_a, $file_b); | |||||||||||||||||||||||||||||||||||||||||
| 57 | 54 | my @hunks; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 54 | my $line; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 54 | ▶ | while ($line = <$fh>) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 313 | ▶ | if ($line =~ /^--- (.*)/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 61 | $file_a = dequote_diff_filename($1); | |||||||||||||||||||||||||||||||||||||||||
| 62 | } elsif ($line =~ /^\+\+\+ (.*)/) { | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 61 | $file_b = dequote_diff_filename($1); | |||||||||||||||||||||||||||||||||||||||||
| 64 | } elsif ($line =~ /^@@ -(\d+)(?:,(\d+))? \+\d+(?:,\d+)? @@/) { | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 63 | my $header = $line; | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 63 | ▶ | next if $file_a ne $file_b; # Ignore creations and deletions. | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 60 | my $lines = []; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 60 | while (1) { | |||||||||||||||||||||||||||||||||||||||||
| 71 | 218 | $line = <$fh>; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 218 | ▶ | if (!defined($line) || $line =~ /^[^ +\\-]/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $line or $line =~ /^[^ +\\-]/
MC/DC100%2/2
not defined $line or $line =~ /^[^ +\\-]/
not defined $line
$line =~ /^[^ +\\-]/
Truth table100%3/3
not(A) or B
A= not defined $lineB= $line =~ /^[^ +\\-]/
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 60 | last; | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 158 | push @{$lines}, $line; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 60 | ▶ | push(@hunks, { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | file => $file_a, | ||||||||||||||||||||||||||||||||||||||||||
| 80 | start => $1, | ||||||||||||||||||||||||||||||||||||||||||
| 81 | count => defined($2) ? $2 : 1, | ||||||||||||||||||||||||||||||||||||||||||
| 82 | header => $header, | ||||||||||||||||||||||||||||||||||||||||||
| 83 | lines => $lines, | ||||||||||||||||||||||||||||||||||||||||||
| 84 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 85 | # The next line after a hunk could be a header for the next commit | ||||||||||||||||||||||||||||||||||||||||||
| 86 | # or hunk. | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 60 | ▶ | redo if defined $line; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 54 | return @hunks; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | # Dequote and unescape filenames that appear in diff output. | ||||||||||||||||||||||||||||||||||||||||||
| 94 | # | ||||||||||||||||||||||||||||||||||||||||||
| 95 | # If the filename is otherwise "normal" but contains spaces it's followed by a | ||||||||||||||||||||||||||||||||||||||||||
| 96 | # trailing tab, and if it contains uncommon control characters or non-ASCII | ||||||||||||||||||||||||||||||||||||||||||
| 97 | # characters, then the filename gets surrounded in double-quotes and non-ASCII | ||||||||||||||||||||||||||||||||||||||||||
| 98 | # characters get replaced with octal escape sequences. | ||||||||||||||||||||||||||||||||||||||||||
| 99 | # | ||||||||||||||||||||||||||||||||||||||||||
| 100 | # For details about exactly what gets quoted, see the sq_lookup array in | ||||||||||||||||||||||||||||||||||||||||||
| 101 | # git/quote.c. | ||||||||||||||||||||||||||||||||||||||||||
| 102 | # | ||||||||||||||||||||||||||||||||||||||||||
| 103 | # Assume --no-prefix or similar has been used and the diff doesn't include | ||||||||||||||||||||||||||||||||||||||||||
| 104 | # src/dst prefixes. | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 122 | ▶ | sub dequote_diff_filename { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dequote_diff_filename: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 122 | $_ = shift; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 122 | s/\t$//m; # Remove trailing tab. | |||||||||||||||||||||||||||||||||||||||||
| 108 | 122 | ▶ | if (startswith($_, '"')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 4 | s/^"|"$//gm; # Remove surrounding quotes. | |||||||||||||||||||||||||||||||||||||||||
| 110 | # Replace octal and control character escapes. | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 4 | s/\\((?:\d{3})|(?:[abtnvfr"\\]))/"qq(\\$1)"/eeg; | |||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 122 | return $_; | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 307 | ▶ | sub git_cmd { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
git_cmd: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | 307 | return ('git', @GIT_OPTIONS, @_); | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||
| 120 | # With a linear git history there'll be a single merge base that's easy to | ||||||||||||||||||||||||||||||||||||||||||
| 121 | # refer to with @{upstream}, but during an interactive rebase we need to get | ||||||||||||||||||||||||||||||||||||||||||
| 122 | # the "current" branch from the rebase metadata. | ||||||||||||||||||||||||||||||||||||||||||
| 123 | # | ||||||||||||||||||||||||||||||||||||||||||
| 124 | # Unusual cases: | ||||||||||||||||||||||||||||||||||||||||||
| 125 | # | ||||||||||||||||||||||||||||||||||||||||||
| 126 | # While there can be multiple merge bases if there have been criss-cross | ||||||||||||||||||||||||||||||||||||||||||
| 127 | # merges, there'll still be a single fork point unless the relevant reflog | ||||||||||||||||||||||||||||||||||||||||||
| 128 | # entries have already been garbage-collected. | ||||||||||||||||||||||||||||||||||||||||||
| 129 | # | ||||||||||||||||||||||||||||||||||||||||||
| 130 | # When multiple upstreams are configured via `branch.<name>.merge` in git's | ||||||||||||||||||||||||||||||||||||||||||
| 131 | # config the most correct approach is probably to find the fork-point for each | ||||||||||||||||||||||||||||||||||||||||||
| 132 | # merge value and return those. But it seems unlikely that someone is doing | ||||||||||||||||||||||||||||||||||||||||||
| 133 | # octopus merges and using git-autofixup, so we're not handling that specially | ||||||||||||||||||||||||||||||||||||||||||
| 134 | # currently. | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 8 | ▶ | sub find_merge_bases { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_merge_bases: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 8 | my $upstream = '@{upstream}'; | |||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | # If an interactive rebase is in progress, derive the upstream from the | ||||||||||||||||||||||||||||||||||||||||||
| 139 | # rebase meatadata. | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 8 | my $gitdir = git_dir(); | |||||||||||||||||||||||||||||||||||||||||
| 141 | 8 | ▶ | if (-e "$gitdir/rebase-merge") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 2 | my $branch = slurp("$gitdir/rebase-merge/head-name"); | |||||||||||||||||||||||||||||||||||||||||
| 143 | 2 | chomp $branch; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | $branch =~ s#^refs/heads/##; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 2 | $upstream = "$branch\@{upstream}"; | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | # `git merge-base` will fail if there's no tracking branch. In that case | ||||||||||||||||||||||||||||||||||||||||||
| 149 | # redirect stderr and communicate failure by returning an empty list. Also, | ||||||||||||||||||||||||||||||||||||||||||
| 150 | # with the --fork-point option, no merge bases are returned if the relevant | ||||||||||||||||||||||||||||||||||||||||||
| 151 | # reflog entries have been GC'd, so fall back to normal merge-bases. | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 8 | my @merge_bases = (); | |||||||||||||||||||||||||||||||||||||||||
| 153 | 8 | my ($out, $err, $exit_code) = capture(qw(git merge-base --all --fork-point), $upstream, 'HEAD'); | |||||||||||||||||||||||||||||||||||||||||
| 154 | 8 | ▶ | if ($exit_code == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 6 | @merge_bases = map {chomp; $_} split(/\n/, $out); | |||||||||||||||||||||||||||||||||||||||||
| 156 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 2 | my ($out, $err, $exit_code) = capture(qw(git merge-base --all), $upstream, 'HEAD'); | |||||||||||||||||||||||||||||||||||||||||
| 158 | 2 | ▶ | if ($exit_code != 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | die "git merge-base: $err"; | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | 2 | @merge_bases = map {chomp; $_} split("\n", $out); | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | 8 | ▶ | return wantarray ? @merge_bases : \@merge_bases; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 11 | ▶ | sub git_dir { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
git_dir: called CC=2 SCAR=7.9
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 11 | my ($out, $err, $exit_code) = capture(qw(git rev-parse --git-dir)); | |||||||||||||||||||||||||||||||||||||||||
| 169 | 11 | ▶ | if ($exit_code != 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | warn "git rev-parse --git-dir: $err\n"; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | die "Can't find repo's git dir\n"; | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 11 | chomp $out; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 11 | return $out; | |||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | 54 | ▶ | sub toplevel_dir { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
toplevel_dir: called CC=2 SCAR=7.9
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 54 | my ($out, $err, $exit_code) = capture(qw(git rev-parse --show-toplevel)); | |||||||||||||||||||||||||||||||||||||||||
| 179 | 54 | ▶ | if ($exit_code != 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | warn "git rev-parse --show-toplevel: $err\n"; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | die "Can't find repo's toplevel dir\n"; | |||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | 54 | chomp $out; | |||||||||||||||||||||||||||||||||||||||||
| 184 | 54 | return $out; | |||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | # Run the given command, capture stdout and stderr, and return an array of | ||||||||||||||||||||||||||||||||||||||||||
| 188 | # (stdout, stderr, exit_code). | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 168 | ▶ | sub capture { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
capture: called CC=5 SCAR=16.7
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 168 | ▶ | open(my $out_fh, '>', undef) or die "create stdout tempfile: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 168 | ▶ | open(my $err_fh, '>', undef) or die "create stderr tempfile: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 192 | 168 | my $pid = open3(my $in_fh, $out_fh, $err_fh, @_); | |||||||||||||||||||||||||||||||||||||||||
| 193 | 168 | waitpid $pid, 0; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 168 | ▶ | if ($? & 127) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | my $signal = $? & 127; | |||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | die "capture: child died with signal $signal; exiting"; | |||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 168 | my $exit_code = $? >> 8; | |||||||||||||||||||||||||||||||||||||||||
| 199 | 168 | local $/; # slurp | |||||||||||||||||||||||||||||||||||||||||
| 200 | 168 | my $stdout = readline $out_fh; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 168 | my $stderr = readline $err_fh; | |||||||||||||||||||||||||||||||||||||||||
| 202 | 168 | my @array = ($stdout, $stderr, $exit_code); | |||||||||||||||||||||||||||||||||||||||||
| 203 | 168 | ▶ | return wantarray ? @array : \@array; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | # Return a description of what $? means. | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 3 | ▶ | sub child_error_desc { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
child_error_desc: called CC=3 SCAR=13.3
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 3 | my $err = shift; | |||||||||||||||||||||||||||||||||||||||||
| 209 | 3 | ▶ | if ($err == -1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | return "failed to execute: $!"; | |||||||||||||||||||||||||||||||||||||||||
| 211 | } elsif ($err & 127) { | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | return "died with signal " . ($err & 127); | |||||||||||||||||||||||||||||||||||||||||
| 213 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 3 | return "exited with " . ($err >> 8); | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 2 | ▶ | sub slurp { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
slurp: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 2 | my $filename = shift; | |||||||||||||||||||||||||||||||||||||||||
| 220 | 2 | ▶ | open my $fh, '<', $filename or die "slurp $filename: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 2 | local $/; | |||||||||||||||||||||||||||||||||||||||||
| 222 | 2 | my $content = readline $fh; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 2 | return $content; | |||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 54 | ▶ | sub summary_for_commits { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
summary_for_commits: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 54 | my @upstreams = @_; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 54 | my %commits; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 54 | my $negative = join(" ", map {"^$_"} @upstreams); | |||||||||||||||||||||||||||||||||||||||||
| 230 | 54 | my @lines = qx(git log --no-merges --format=%H:%s HEAD $negative); | |||||||||||||||||||||||||||||||||||||||||
| 231 | 54 | ▶ | die "git log: " . child_error_desc($?) if $?; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 54 | for (@lines) { | |||||||||||||||||||||||||||||||||||||||||
| 233 | 64 | chomp; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 64 | my ($sha, $msg) = split ':', $_, 2; | |||||||||||||||||||||||||||||||||||||||||
| 235 | 64 | $commits{$sha} = $msg; | |||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 54 | return \%commits; | |||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | # Return targets of fixup!/squash! commits. | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 54 | ▶ | sub sha_aliases { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sha_aliases: called CC=7 SCAR=20.6
| |||||||||||||||||||||||||||||||||||||||||||
| 242 | 54 | my $summary_for = shift; | |||||||||||||||||||||||||||||||||||||||||
| 243 | 54 | my %aliases; | |||||||||||||||||||||||||||||||||||||||||
| 244 | 54 | my @targets = keys(%{$summary_for}); | |||||||||||||||||||||||||||||||||||||||||
| 245 | 54 | for my $sha (@targets) { | |||||||||||||||||||||||||||||||||||||||||
| 246 | 64 | my $summary = $summary_for->{$sha}; | |||||||||||||||||||||||||||||||||||||||||
| 247 | 64 | ▶ | next if $summary !~ /^(?:fixup|squash)! (.*)/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 3 | my $prefix = $1; | |||||||||||||||||||||||||||||||||||||||||
| 249 | 3 | ▶ | if ($prefix =~ /^(?:(?:fixup|squash)! ){2}/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | die "fixup commits for fixup commits aren't supported: $sha"; | |||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 3 | my @matches = grep {startswith($summary_for->{$_}, $prefix)} @targets; | |||||||||||||||||||||||||||||||||||||||||
| 253 | 3 | ▶ | if (@matches > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | die "ambiguous fixup commit target: multiple commit summaries start with: $prefix\n"; | |||||||||||||||||||||||||||||||||||||||||
| 255 | } elsif (@matches == 0) { | ||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | die "no fixup target in topic branch: $sha\n"; | |||||||||||||||||||||||||||||||||||||||||
| 257 | } elsif (@matches == 1) { | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 3 | $aliases{$sha} = $matches[0]; | |||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 54 | return \%aliases; | |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | # Given hunk, blame, and commit data, return the SHA for the commit the hunk | ||||||||||||||||||||||||||||||||||||||||||
| 265 | # should fixup, or undef if an appropriate commit isn't found. | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 60 | ▶ | sub fixup_sha { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fixup_sha: called CC=11 SCAR=24.6
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 60 | my $args = shift; | |||||||||||||||||||||||||||||||||||||||||
| 268 | 60 | my $hunk = $args->{hunk}; | |||||||||||||||||||||||||||||||||||||||||
| 269 | 60 | my $blame = $args->{blame}; | |||||||||||||||||||||||||||||||||||||||||
| 270 | 60 | my $summary_for = $args->{summary_for}; | |||||||||||||||||||||||||||||||||||||||||
| 271 | 60 | my $strict = $args->{strict}; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 60 | ▶ | if (grep {!defined} ($hunk, $blame, $summary_for, $strict)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | croak 'missing argument'; | |||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | 60 | my @targets; | |||||||||||||||||||||||||||||||||||||||||
| 277 | 60 | ▶ | if ($args->{strict} == $CONTEXT) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | 41 | @targets = fixup_targets_from_all_context($args); | |||||||||||||||||||||||||||||||||||||||||
| 279 | 41 | my @topic_targets = grep {defined $summary_for->{$_}} @targets; | |||||||||||||||||||||||||||||||||||||||||
| 280 | 41 | ▶ | if (@topic_targets > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | # The context assignment is ambiguous, but an adjacency assignment | ||||||||||||||||||||||||||||||||||||||||||
| 282 | # might not be. | ||||||||||||||||||||||||||||||||||||||||||
| 283 | 3 | @targets = fixup_targets_from_adjacent_context($args); | |||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||
| 285 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 286 | 19 | @targets = fixup_targets_from_adjacent_context($args); | |||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||
| 289 | 60 | my $upstream_is_blamed = grep {!defined $summary_for->{$_}} @targets; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 60 | my @topic_targets = grep {defined $summary_for->{$_}} @targets; | |||||||||||||||||||||||||||||||||||||||||
| 291 | 60 | ▶ | if ($strict && $upstream_is_blamed) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
$strict and $upstream_is_blamed
MC/DC100%2/2
$strict and $upstream_is_blamed
$strict
$upstream_is_blamed
Truth table100%3/3
A and B
A= $strictB= $upstream_is_blamed
| |||||||||||||||||||||||||||||||||||||||||||
| 292 | 4 | ▶ | $VERBOSE && print hunk_desc($hunk), " changes lines blamed on upstream\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||
| 294 | } elsif (@topic_targets > 1) { | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | $VERBOSE && print hunk_desc($hunk), " has multiple targets\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 297 | } elsif (@topic_targets == 0) { | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 5 | ▶ | $VERBOSE && print hunk_desc($hunk), " has no targets\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | 5 | return; | |||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 51 | return $topic_targets[0]; | |||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | ▶ | sub hunk_desc { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
hunk_desc: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | my $hunk = shift; | |||||||||||||||||||||||||||||||||||||||||
| 306 | return join " ", ( | ||||||||||||||||||||||||||||||||||||||||||
| 307 | $hunk->{file}, | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | $hunk->{header} =~ /(@@[^@]*@@)/, | |||||||||||||||||||||||||||||||||||||||||
| 309 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||
| 312 | 41 | ▶ | sub fixup_targets_from_all_context { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fixup_targets_from_all_context: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||||||||||||||||
| 313 | 41 | my $args = shift; | |||||||||||||||||||||||||||||||||||||||||
| 314 | 41 | my ($hunk, $blame, $summary_for) = @{$args}{qw(hunk blame summary_for)}; | |||||||||||||||||||||||||||||||||||||||||
| 315 | 41 | ▶ | croak 'missing argument' if grep {!defined} ($hunk, $blame, $summary_for); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | 41 | my @targets = uniq(map {$_->{sha}} values(%{$blame})); | |||||||||||||||||||||||||||||||||||||||||
| 318 | 41 | ▶ | return wantarray ? @targets : \@targets; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | } | ||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 113 | ▶ | sub uniq { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
uniq: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | 113 | my %seen; | |||||||||||||||||||||||||||||||||||||||||
| 323 | 113 | return grep {!$seen{$_}++} @_; | |||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 22 | ▶ | sub fixup_targets_from_adjacent_context { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fixup_targets_from_adjacent_context: called CC=16 SCAR=27.8
| |||||||||||||||||||||||||||||||||||||||||||
| 327 | 22 | my $args = shift; | |||||||||||||||||||||||||||||||||||||||||
| 328 | 22 | my $hunk = $args->{hunk}; | |||||||||||||||||||||||||||||||||||||||||
| 329 | 22 | my $blame = $args->{blame}; | |||||||||||||||||||||||||||||||||||||||||
| 330 | 22 | my $summary_for = $args->{summary_for}; | |||||||||||||||||||||||||||||||||||||||||
| 331 | 22 | my $strict = $args->{strict}; | |||||||||||||||||||||||||||||||||||||||||
| 332 | 22 | ▶ | if (grep {!defined} ($hunk, $blame, $summary_for, $strict)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | croak 'missing argument'; | |||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | 22 | my $blame_indexes = blame_indexes($hunk); | |||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | 22 | my %blamed; | |||||||||||||||||||||||||||||||||||||||||
| 339 | 22 | my $diff = $hunk->{lines}; | |||||||||||||||||||||||||||||||||||||||||
| 340 | 22 | ▶ | for (my $di = 0; $di < @{$diff}; $di++) { # diff index | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 56 | my $bi = $blame_indexes->[$di]; | |||||||||||||||||||||||||||||||||||||||||
| 342 | 56 | my $line = $diff->[$di]; | |||||||||||||||||||||||||||||||||||||||||
| 343 | 56 | ▶ | if (startswith($line, '-')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | 17 | my $sha = $blame->{$bi}{sha}; | |||||||||||||||||||||||||||||||||||||||||
| 345 | 17 | $blamed{$sha} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 346 | } elsif (startswith($line, '+')) { | ||||||||||||||||||||||||||||||||||||||||||
| 347 | 18 | my @lines; | |||||||||||||||||||||||||||||||||||||||||
| 348 | 18 | ▶ | if ($di > 0 && defined $blame->{$bi-1}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$di > 0 and defined $$blame{$bi - 1}
MC/DC50%1/2
$di > 0 and defined $$blame{$bi - 1}
$di > 0
defined $$blame{$bi - 1}
Truth table66%2/3
A and B
A= $di > 0B= defined $$blame{$bi - 1}
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | 17 | push @lines, $bi-1; | |||||||||||||||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 18 | ▶ | if (defined $blame->{$bi}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | 5 | push @lines, $bi; | |||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||
| 354 | 18 | my @adjacent_shas = uniq(map {$_->{sha}} @{$blame}{@lines}); | |||||||||||||||||||||||||||||||||||||||||
| 355 | 18 | my @target_shas = grep {defined $summary_for->{$_}} @adjacent_shas; | |||||||||||||||||||||||||||||||||||||||||
| 356 | # Note that lines at the beginning or end of a file can be | ||||||||||||||||||||||||||||||||||||||||||
| 357 | # "surrounded" by a single line. | ||||||||||||||||||||||||||||||||||||||||||
| 358 | 18 | ▶ | my $is_surrounded = @target_shas > 0 | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
@target_shas > 0 && @target_shas == @adjacent_shas && $target_shas[0] eq $target_shas[-1]
@target_shas > 0 and @target_shas == @adjacent_shas
MC/DC100%3/3
@target_shas > 0 && @target_shas == @adjacent_shas && $target_shas[0] eq $target_shas[-1]
@target_shas > 0
@target_shas == @adjacent_shas
$target_shas[0] eq $target_shas[-1]
Truth table100%4/4
A and B && C
A= @target_shas > 0B= @target_shas == @adjacent_shasC= $target_shas[0] eq $target_shas[-1]
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | && @target_shas == @adjacent_shas | ||||||||||||||||||||||||||||||||||||||||||
| 360 | && $target_shas[0] eq $target_shas[-1]; | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 18 | my $is_adjacent = @target_shas == 1; | |||||||||||||||||||||||||||||||||||||||||
| 362 | 18 | ▶ | if ($is_surrounded || ($strict < $SURROUNDED && $is_adjacent)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$is_surrounded or $strict < $SURROUNDED and $is_adjacent
$strict < $SURROUNDED and $is_adjacent
MC/DC100%3/3
$is_surrounded or $strict < $SURROUNDED and $is_adjacent
$is_surrounded
$strict < $SURROUNDED
$is_adjacent
Truth table100%4/4
A or B and C
A= $is_surroundedB= $strict < $SURROUNDEDC= $is_adjacent
| |||||||||||||||||||||||||||||||||||||||||||
| 363 | 14 | $blamed{$target_shas[0]} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||||
| 365 | 18 | ▶ | while ($di < @$diff-1 && startswith($diff->[$di+1], '+')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$di < @$diff - 1 and startswith($$diff[$di + 1], "+")
MC/DC100%2/2
$di < @$diff - 1 and startswith($$diff[$di + 1], "+")
$di < @$diff - 1
startswith($$diff[$di + 1], "+")
Truth table100%3/3
A and B
A= $di < @$diff - 1B= startswith($$diff[$di + 1], "+")
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | 4 | $di++; | |||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||
| 370 | 22 | my @targets = keys %blamed; | |||||||||||||||||||||||||||||||||||||||||
| 371 | 22 | ▶ | return wantarray ? @targets : \@targets; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | 1187 | ▶ | sub startswith { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
startswith: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 1187 | my ($haystack, $needle) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 376 | 1187 | return index($haystack, $needle, 0) == 0; | |||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | # Map lines in a hunk's diff to the corresponding `git blame HEAD` output. | ||||||||||||||||||||||||||||||||||||||||||
| 380 | 22 | ▶ | sub blame_indexes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
blame_indexes: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | 22 | my $hunk = shift; | |||||||||||||||||||||||||||||||||||||||||
| 382 | 22 | my @indexes; | |||||||||||||||||||||||||||||||||||||||||
| 383 | 22 | my $bi = $hunk->{start}; | |||||||||||||||||||||||||||||||||||||||||
| 384 | 22 | ▶ | for (my $di = 0; $di < @{$hunk->{lines}}; $di++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | 60 | push @indexes, $bi; | |||||||||||||||||||||||||||||||||||||||||
| 386 | 60 | my $first = substr($hunk->{lines}[$di], 0, 1); | |||||||||||||||||||||||||||||||||||||||||
| 387 | 60 | ▶ | if ($first eq '-' or $first eq ' ') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$first eq "-" or $first eq " "
MC/DC100%2/2
$first eq "-" or $first eq " "
$first eq "-"
$first eq " "
Truth table100%3/3
A or B
A= $first eq "-"B= $first eq " "
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | 38 | $bi++; | |||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 390 | # Don't increment $bi for added lines. | ||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||
| 392 | 22 | return \@indexes; | |||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | ▶ | sub print_hunk_blamediff { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print_hunk_blamediff: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | my $args = shift; | |||||||||||||||||||||||||||||||||||||||||
| 397 | 0 | my $fh = $args->{fh}; | |||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | my $hunk = $args->{hunk}; | |||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | my $summary_for = $args->{summary_for}; | |||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | my $blame = $args->{blame}; | |||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | my $blame_indexes = $args->{blame_indexes}; | |||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | ▶ | if (grep {!defined} ($fh, $hunk, $summary_for, $blame, $blame_indexes)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | croak 'missing argument'; | |||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | my $format = "%-8.8s|%4.4s|%-30.30s|%-30.30s\n"; | |||||||||||||||||||||||||||||||||||||||||
| 407 | 0 | ▶ | for (my $i = 0; $i < @{$hunk->{lines}}; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | my $line_r = $hunk->{lines}[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | my $bi = $blame_indexes->[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | ▶ | my $sha = defined $blame->{$bi} ? $blame->{$bi}{sha} : undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | ▶ | my $display_sha = defined($sha) ? $sha : q{}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 413 | 0 | my $display_bi = $bi; | |||||||||||||||||||||||||||||||||||||||||
| 414 | 0 | ▶ | if (startswith($line_r, '+')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | $display_sha = q{}; # For added lines. | |||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | $display_bi = q{}; | |||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | ▶ | if (defined($sha) && !defined($summary_for->{$sha})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $sha and not defined $summary_for->{$sha}
MC/DC0%0/2
defined $sha and not defined $summary_for->{$sha}
defined $sha
not defined $summary_for->{$sha}
Truth table0%0/3
A and not(B)
A= defined $shaB= not defined $summary_for->{$sha}
| |||||||||||||||||||||||||||||||||||||||||||
| 419 | # For lines from before the given upstream revision. | ||||||||||||||||||||||||||||||||||||||||||
| 420 | 0 | $display_sha = '^'; | |||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | my $line_l = ''; | |||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | ▶ | if (defined $blame->{$bi} && !startswith($line_r, '+')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $blame->{$bi} and not startswith($line_r, "+")
MC/DC0%0/2
defined $blame->{$bi} and not startswith($line_r, "+")
defined $blame->{$bi}
not startswith($line_r, "+")
Truth table0%0/3
A and not(B)
A= defined $blame->{$bi}B= not startswith($line_r, "+")
| |||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | $line_l = $blame->{$bi}{text}; | |||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | for ($line_l, $line_r) { | |||||||||||||||||||||||||||||||||||||||||
| 429 | # For the table to line up, tabs need to be converted to a string of fixed width. | ||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | s/\t/^I/g; | |||||||||||||||||||||||||||||||||||||||||
| 431 | # Remove trailing newlines and carriage returns. If more trailing | ||||||||||||||||||||||||||||||||||||||||||
| 432 | # whitespace is removed, that's fine. | ||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | $_ = rtrim($_); | |||||||||||||||||||||||||||||||||||||||||
| 434 | } | ||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | printf {$fh} $format, $display_sha, $display_bi, $line_l, $line_r; | |||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | print {$fh} "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | sub rtrim { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rtrim: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | $s =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | return $s; | |||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | 60 | ▶ | sub blame { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
blame: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | 60 | my ($hunk, $alias_for, $grafts_file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 450 | 60 | ▶ | if ($hunk->{count} == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 451 | 1 | return {}; | |||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||
| 453 | 59 | my @cmd = git_cmd( | |||||||||||||||||||||||||||||||||||||||||
| 454 | 'blame', '--porcelain', | ||||||||||||||||||||||||||||||||||||||||||
| 455 | '-L' => "$hunk->{start},+$hunk->{count}", | ||||||||||||||||||||||||||||||||||||||||||
| 456 | '-S' => $grafts_file, 'HEAD', | ||||||||||||||||||||||||||||||||||||||||||
| 457 | '--', "$hunk->{file}"); | ||||||||||||||||||||||||||||||||||||||||||
| 458 | 59 | my %blame; | |||||||||||||||||||||||||||||||||||||||||
| 459 | 59 | my ($sha, $line_num); | |||||||||||||||||||||||||||||||||||||||||
| 460 | 59 | ▶ | open(my $fh, '-|', @cmd) or die "run git blame: $!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 461 | 59 | ▶ | while (my $line = <$fh>) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 462 | 955 | ▶ | if ($line =~ /^([0-9a-f]{40}) \d+ (\d+)/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 463 | 96 | ($sha, $line_num) = ($1, $2); | |||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||
| 465 | 955 | ▶ | if (startswith($line, "\t")) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 466 | 96 | ▶ | if (defined $alias_for->{$sha}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 467 | 3 | $sha = $alias_for->{$sha}; | |||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||
| 469 | 96 | $blame{$line_num} = {sha => $sha, text => substr($line, 1)}; | |||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||
| 472 | 59 | ▶ | close($fh) or die "git blame: " . child_error_desc($?) . "\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 473 | 59 | return \%blame; | |||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||
| 476 | 54 | ▶ | sub diff_hunks { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
diff_hunks: called CC=6 SCAR=18.1
| |||||||||||||||||||||||||||||||||||||||||||
| 477 | 54 | my $num_context_lines = shift; | |||||||||||||||||||||||||||||||||||||||||
| 478 | 54 | my @files = @_; | |||||||||||||||||||||||||||||||||||||||||
| 479 | 54 | my @cmd = git_cmd(qw(diff --no-prefix --no-ext-diff --ignore-submodules), "-U$num_context_lines"); | |||||||||||||||||||||||||||||||||||||||||
| 480 | 54 | ▶ | if (is_index_dirty()) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 481 | 3 | push @cmd, "--cached"; | |||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||
| 483 | 54 | ▶ | if (@files) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | 6 | push @cmd, '--', @files; | |||||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||||
| 486 | 54 | ▶ | open(my $fh, '-|', @cmd) or die "run git diff: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 487 | 54 | my @hunks = parse_hunks($fh, keep_lines => 1); | |||||||||||||||||||||||||||||||||||||||||
| 488 | 54 | ▶ | close($fh) or die "git diff: " . child_error_desc($?) . "\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 489 | 54 | ▶ | return wantarray ? @hunks : \@hunks; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||
| 492 | 43 | ▶ | sub commit_fixup { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
commit_fixup: called CC=5 SCAR=16.6
| |||||||||||||||||||||||||||||||||||||||||||
| 493 | 43 | my ($sha, $hunks) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 494 | 43 | ▶ | open my $fh, '|-', git_cmd(qw(apply --unidiff-zero --cached -)) or die "git apply: $!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 495 | 43 | for my $hunk (@{$hunks}) { | |||||||||||||||||||||||||||||||||||||||||
| 496 | 51 | print({$fh} | |||||||||||||||||||||||||||||||||||||||||
| 497 | "--- a/$hunk->{file}\n", | ||||||||||||||||||||||||||||||||||||||||||
| 498 | "+++ b/$hunk->{file}\n", | ||||||||||||||||||||||||||||||||||||||||||
| 499 | $hunk->{header}, | ||||||||||||||||||||||||||||||||||||||||||
| 500 | 51 | @{$hunk->{lines}}, | |||||||||||||||||||||||||||||||||||||||||
| 501 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||
| 503 | 43 | ▶ | close $fh or die "git apply: " . child_error_desc($?) . "\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 504 | 40 | my (undef, $err, $exit_code) = capture(git_cmd('commit', "--fixup=$sha")); | |||||||||||||||||||||||||||||||||||||||||
| 505 | 40 | ▶ | if ($exit_code != 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 506 | 0 | warn "git commit: $err\n"; | |||||||||||||||||||||||||||||||||||||||||
| 507 | 0 | die "git commit exited with $exit_code\n"; | |||||||||||||||||||||||||||||||||||||||||
| 508 | } | ||||||||||||||||||||||||||||||||||||||||||
| 509 | 40 | return; | |||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||
| 512 | 108 | ▶ | sub is_index_dirty { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_index_dirty: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 513 | 108 | return system(git_cmd(qw(diff-index --cached HEAD --quiet))) != 0; | |||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||
| 516 | 54 | ▶ | sub fixup_hunks_by_sha { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fixup_hunks_by_sha: called CC=7 SCAR=20.2
| |||||||||||||||||||||||||||||||||||||||||||
| 517 | 54 | my $args = shift; | |||||||||||||||||||||||||||||||||||||||||
| 518 | 54 | my $hunks = $args->{hunks}; | |||||||||||||||||||||||||||||||||||||||||
| 519 | 54 | my $blame_for = $args->{blame_for}; | |||||||||||||||||||||||||||||||||||||||||
| 520 | 54 | my $summary_for = $args->{summary_for}; | |||||||||||||||||||||||||||||||||||||||||
| 521 | 54 | my $strict = $args->{strict}; | |||||||||||||||||||||||||||||||||||||||||
| 522 | 54 | ▶ | if (grep {!defined} ($hunks, $blame_for, $summary_for, $strict)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | croak 'missing argument'; | |||||||||||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | 54 | my %hunks_for; | |||||||||||||||||||||||||||||||||||||||||
| 527 | 54 | for my $hunk (@{$hunks}) { | |||||||||||||||||||||||||||||||||||||||||
| 528 | 60 | my $blame = $blame_for->{$hunk}; | |||||||||||||||||||||||||||||||||||||||||
| 529 | 60 | my $sha = fixup_sha({ | |||||||||||||||||||||||||||||||||||||||||
| 530 | hunk => $hunk, | ||||||||||||||||||||||||||||||||||||||||||
| 531 | blame => $blame, | ||||||||||||||||||||||||||||||||||||||||||
| 532 | summary_for => $summary_for, | ||||||||||||||||||||||||||||||||||||||||||
| 533 | strict => $strict, | ||||||||||||||||||||||||||||||||||||||||||
| 534 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 535 | 60 | ▶ | if ($sha && $VERBOSE) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$sha and $VERBOSE
MC/DC0%0/2
$sha and $VERBOSE
$sha
$VERBOSE
Truth table66%2/3
A and B
A= $shaB= $VERBOSE
| |||||||||||||||||||||||||||||||||||||||||||
| 536 | printf "%s fixes %s %s\n", | ||||||||||||||||||||||||||||||||||||||||||
| 537 | hunk_desc($hunk), | ||||||||||||||||||||||||||||||||||||||||||
| 538 | substr($sha, 0, 8), | ||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | $summary_for->{$sha}; | |||||||||||||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||||||||||||
| 541 | 60 | ▶ | if ($VERBOSE > 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | print_hunk_blamediff({ | |||||||||||||||||||||||||||||||||||||||||
| 543 | fh => *STDOUT, | ||||||||||||||||||||||||||||||||||||||||||
| 544 | hunk => $hunk, | ||||||||||||||||||||||||||||||||||||||||||
| 545 | summary_for => $summary_for, | ||||||||||||||||||||||||||||||||||||||||||
| 546 | blame => $blame, | ||||||||||||||||||||||||||||||||||||||||||
| 547 | blame_indexes => blame_indexes($hunk) | ||||||||||||||||||||||||||||||||||||||||||
| 548 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||||||||||||
| 550 | 60 | ▶ | next if !$sha; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 551 | 51 | push @{$hunks_for{$sha}}, $hunk; | |||||||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||||||
| 553 | 54 | return \%hunks_for; | |||||||||||||||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||
| 556 | # Return SHAs in some consistent order. | ||||||||||||||||||||||||||||||||||||||||||
| 557 | # | ||||||||||||||||||||||||||||||||||||||||||
| 558 | # Currently they're ordered by how early their assigned hunks appear in the | ||||||||||||||||||||||||||||||||||||||||||
| 559 | # diff output. This assumes $hunks is in the order it was parsed from the diff. | ||||||||||||||||||||||||||||||||||||||||||
| 560 | # This ordering seems nice since it'd be similar to the order a human would | ||||||||||||||||||||||||||||||||||||||||||
| 561 | # make commits in if they were working their way down the diff. | ||||||||||||||||||||||||||||||||||||||||||
| 562 | 54 | ▶ | sub ordered_shas { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ordered_shas: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 563 | 54 | my $hunks = shift; | |||||||||||||||||||||||||||||||||||||||||
| 564 | 54 | my $sha_for = shift; | |||||||||||||||||||||||||||||||||||||||||
| 565 | 54 | my @ordered = (); | |||||||||||||||||||||||||||||||||||||||||
| 566 | 54 | for my $hunk (@{$hunks}) { | |||||||||||||||||||||||||||||||||||||||||
| 567 | 60 | ▶ | if (defined $sha_for->{$hunk}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 568 | 51 | push @ordered, $sha_for->{$hunk}; | |||||||||||||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||||||||||||||||
| 571 | 54 | return uniq(@ordered); | |||||||||||||||||||||||||||||||||||||||||
| 572 | } | ||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||
| 574 | # Reverse the sha->hunks hashef and return a hunk->sha hashref. | ||||||||||||||||||||||||||||||||||||||||||
| 575 | 54 | ▶ | sub sha_for_hunk_map { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sha_for_hunk_map: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||
| 576 | 54 | my $hunks_for = shift; | |||||||||||||||||||||||||||||||||||||||||
| 577 | 54 | my %sha_for; | |||||||||||||||||||||||||||||||||||||||||
| 578 | 54 | for my $sha (keys %{$hunks_for}) { | |||||||||||||||||||||||||||||||||||||||||
| 579 | 43 | for my $hunk (@{$hunks_for->{$sha}}) { | |||||||||||||||||||||||||||||||||||||||||
| 580 | 51 | ▶ | if (defined $sha_for{$hunk}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | die "multiple SHAs for hunk"; # This should never happen. | |||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||
| 583 | 51 | $sha_for{$hunk} = $sha; | |||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||||||||||||||||
| 586 | 54 | return \%sha_for; | |||||||||||||||||||||||||||||||||||||||||
| 587 | } | ||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||
| 589 | 47 | ▶ | sub exit_code { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exit_code: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 590 | 47 | my ($hunks, $hunks_for) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 591 | 47 | my $hunk_count = scalar @{$hunks}; | |||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||
| 593 | 47 | my $assigned_hunk_count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 594 | 47 | for (values %{$hunks_for}) { | |||||||||||||||||||||||||||||||||||||||||
| 595 | 36 | $assigned_hunk_count += @{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||
| 598 | 47 | my $rc; | |||||||||||||||||||||||||||||||||||||||||
| 599 | 47 | ▶ | if ($hunk_count == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 600 | 6 | $rc = 3; # no hunks to assign | |||||||||||||||||||||||||||||||||||||||||
| 601 | } elsif ($assigned_hunk_count == 0) { | ||||||||||||||||||||||||||||||||||||||||||
| 602 | 7 | $rc = 2; # hunks exist, but none assigned | |||||||||||||||||||||||||||||||||||||||||
| 603 | } elsif ($assigned_hunk_count < $hunk_count) { | ||||||||||||||||||||||||||||||||||||||||||
| 604 | 1 | $rc = 1; # not all hunks assigned | |||||||||||||||||||||||||||||||||||||||||
| 605 | } elsif ($hunk_count == $assigned_hunk_count) { | ||||||||||||||||||||||||||||||||||||||||||
| 606 | 33 | $rc = 0; # all hunks assigned | |||||||||||||||||||||||||||||||||||||||||
| 607 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | die "unexpected conditions when choosing exit code"; | |||||||||||||||||||||||||||||||||||||||||
| 609 | } | ||||||||||||||||||||||||||||||||||||||||||
| 610 | 47 | return $rc; | |||||||||||||||||||||||||||||||||||||||||
| 611 | } | ||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||
| 613 | # Create a temporary index so we can craft commits with already-staged hunks. | ||||||||||||||||||||||||||||||||||||||||||
| 614 | # Return a File::Temp object so the caller has control over its lifetime. | ||||||||||||||||||||||||||||||||||||||||||
| 615 | 3 | ▶ | sub create_temp_index { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_temp_index: called CC=7 SCAR=20.3
| |||||||||||||||||||||||||||||||||||||||||||
| 616 | 3 | my $old_index = shift; | |||||||||||||||||||||||||||||||||||||||||
| 617 | 3 | my $tempfile = File::Temp->new( | |||||||||||||||||||||||||||||||||||||||||
| 618 | TEMPLATE => 'git-autofixup_index.XXXXXX', | ||||||||||||||||||||||||||||||||||||||||||
| 619 | DIR => File::Spec->tmpdir()); | ||||||||||||||||||||||||||||||||||||||||||
| 620 | # The index ought to be equivalent to HEAD. The fastest way to create it | ||||||||||||||||||||||||||||||||||||||||||
| 621 | # is to start with the current index, and subtract the changes since HEAD. | ||||||||||||||||||||||||||||||||||||||||||
| 622 | 3 | ▶ | if (not defined($old_index)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 623 | 3 | my $gitdir = git_dir(); | |||||||||||||||||||||||||||||||||||||||||
| 624 | 3 | $old_index = "$gitdir/index"; | |||||||||||||||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||||||||||||||||
| 626 | 3 | ▶ | close $tempfile or die "close temp index: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 627 | 3 | ▶ | copy($old_index, $tempfile->filename()) or die "Can't copy Git index '$old_index' to '$tempfile': $!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 628 | |||||||||||||||||||||||||||||||||||||||||||
| 629 | 3 | $ENV{GIT_INDEX_FILE} = $tempfile->filename(); | |||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||
| 631 | # Remove any staged changes from the new index - we want to turn them into fixup commits. | ||||||||||||||||||||||||||||||||||||||||||
| 632 | 3 | my $index_changes = qx(git diff-index --patch --no-prefix --no-ext-diff --ignore-submodules --cached HEAD); | |||||||||||||||||||||||||||||||||||||||||
| 633 | 3 | ▶ | die "git diff-index: " . child_error_desc($?) if $?; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 634 | 3 | ▶ | open my $fh, '|-', git_cmd(qw(apply -p0 --cached --whitespace=nowarn --reverse -)) or die "run git apply: $!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 635 | 3 | print $fh $index_changes; | |||||||||||||||||||||||||||||||||||||||||
| 636 | 3 | ▶ | close $fh or die "git apply: " . child_error_desc($?) . "\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||||||||||||
| 638 | 3 | return $tempfile; | |||||||||||||||||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||
| 641 | # Create a grafts file for `git blame -S` that basically says the upstream | ||||||||||||||||||||||||||||||||||||||||||
| 642 | # commit doesn't have any parents, resulting in blame only searching back as | ||||||||||||||||||||||||||||||||||||||||||
| 643 | # far back as the upstream commit. | ||||||||||||||||||||||||||||||||||||||||||
| 644 | 54 | ▶ | sub create_grafts_file { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_grafts_file: called CC=4 SCAR=14.1
| |||||||||||||||||||||||||||||||||||||||||||
| 645 | 54 | my @upstreams = @_; | |||||||||||||||||||||||||||||||||||||||||
| 646 | 54 | my $grafts_file = File::Temp->new( | |||||||||||||||||||||||||||||||||||||||||
| 647 | TEMPLATE => 'git-autofixup_grafts.XXXXXX', | ||||||||||||||||||||||||||||||||||||||||||
| 648 | DIR => File::Spec->tmpdir()); | ||||||||||||||||||||||||||||||||||||||||||
| 649 | 54 | ▶ | open(my $fh, '>', $grafts_file) or die "Can't open $grafts_file: $!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 650 | 54 | for (@upstreams) { | |||||||||||||||||||||||||||||||||||||||||
| 651 | 55 | print $fh $_, "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 652 | } | ||||||||||||||||||||||||||||||||||||||||||
| 653 | 54 | ▶ | close($fh) or die "close grafts file: $!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 654 | 54 | return $grafts_file; | |||||||||||||||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||||||||||||||||
| 656 | |||||||||||||||||||||||||||||||||||||||||||
| 657 | 50 | ▶ | sub rev_parse { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rev_parse: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||
| 658 | 50 | my $rev = shift; | |||||||||||||||||||||||||||||||||||||||||
| 659 | 50 | my ($out, $err, $exit_code) = capture(qw(git rev-parse --verify --end-of-options), $rev); | |||||||||||||||||||||||||||||||||||||||||
| 660 | 50 | ▶ | if ($exit_code != 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 661 | 0 | warn "git rev-parse: $err\n"; | |||||||||||||||||||||||||||||||||||||||||
| 662 | 0 | die "Can't resolve given revision\n"; | |||||||||||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||||||||||||
| 664 | 50 | chomp $out; | |||||||||||||||||||||||||||||||||||||||||
| 665 | 50 | return $out; | |||||||||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||
| 668 | 54 | ▶ | sub main { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
main: called CC=23 SCAR=35.9
| |||||||||||||||||||||||||||||||||||||||||||
| 669 | 54 | $VERBOSE = 0; | |||||||||||||||||||||||||||||||||||||||||
| 670 | 54 | my $help; | |||||||||||||||||||||||||||||||||||||||||
| 671 | my $man; | ||||||||||||||||||||||||||||||||||||||||||
| 672 | 54 | my $show_version; | |||||||||||||||||||||||||||||||||||||||||
| 673 | 54 | my $strict = $CONTEXT; | |||||||||||||||||||||||||||||||||||||||||
| 674 | 54 | my $num_context_lines = 3; | |||||||||||||||||||||||||||||||||||||||||
| 675 | 54 | my $dryrun; | |||||||||||||||||||||||||||||||||||||||||
| 676 | my $use_detailed_exit_codes; | ||||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||
| 678 | 54 | my $raw_upstream; | |||||||||||||||||||||||||||||||||||||||||
| 679 | 54 | my @files = (); | |||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||
| 681 | 54 | my $found_option_terminator = 0; | |||||||||||||||||||||||||||||||||||||||||
| 682 | 54 | my @new_argv = (); | |||||||||||||||||||||||||||||||||||||||||
| 683 | 54 | for my $arg (@ARGV) { | |||||||||||||||||||||||||||||||||||||||||
| 684 | 168 | ▶ | if ($found_option_terminator) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 685 | 6 | push @files, $arg; | |||||||||||||||||||||||||||||||||||||||||
| 686 | } elsif ($arg eq '--') { | ||||||||||||||||||||||||||||||||||||||||||
| 687 | 5 | $found_option_terminator = 1; | |||||||||||||||||||||||||||||||||||||||||
| 688 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 689 | 157 | push @new_argv, $arg; | |||||||||||||||||||||||||||||||||||||||||
| 690 | } | ||||||||||||||||||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||||||||||||||||
| 692 | 54 | @ARGV = @new_argv; | |||||||||||||||||||||||||||||||||||||||||
| 693 | |||||||||||||||||||||||||||||||||||||||||||
| 694 | 54 | ▶ | GetOptions( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 695 | 'h' => \$help, | ||||||||||||||||||||||||||||||||||||||||||
| 696 | 'help' => \$man, | ||||||||||||||||||||||||||||||||||||||||||
| 697 | 'version' => \$show_version, | ||||||||||||||||||||||||||||||||||||||||||
| 698 | 'verbose|v+' => \$VERBOSE, | ||||||||||||||||||||||||||||||||||||||||||
| 699 | 'strict|s=i' => \$strict, | ||||||||||||||||||||||||||||||||||||||||||
| 700 | 'context|c=i' => \$num_context_lines, | ||||||||||||||||||||||||||||||||||||||||||
| 701 | 'dryrun|n' => \$dryrun, | ||||||||||||||||||||||||||||||||||||||||||
| 702 | 'gitopt|g=s' => \@GIT_OPTIONS, | ||||||||||||||||||||||||||||||||||||||||||
| 703 | 'exit-code' => \$use_detailed_exit_codes, | ||||||||||||||||||||||||||||||||||||||||||
| 704 | ) or return 1; | ||||||||||||||||||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||||||||||||||||
| 706 | 54 | ▶ | if (@ARGV) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 707 | 50 | $raw_upstream = shift @ARGV; | |||||||||||||||||||||||||||||||||||||||||
| 708 | 50 | @files = (@ARGV, @files); | |||||||||||||||||||||||||||||||||||||||||
| 709 | } | ||||||||||||||||||||||||||||||||||||||||||
| 710 | 54 | ▶ | if ($help) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 711 | 0 | print $usage; | |||||||||||||||||||||||||||||||||||||||||
| 712 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 713 | } | ||||||||||||||||||||||||||||||||||||||||||
| 714 | 54 | ▶ | if ($show_version) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 715 | 0 | print "$VERSION\n"; | |||||||||||||||||||||||||||||||||||||||||
| 716 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 717 | } | ||||||||||||||||||||||||||||||||||||||||||
| 718 | 54 | ▶ | if ($man) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 719 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||
| 720 | 0 | require Pod::Usage; | |||||||||||||||||||||||||||||||||||||||||
| 721 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 723 | 0 | die <<'EOF'; | |||||||||||||||||||||||||||||||||||||||||
| 724 | Pod::Usage unavailable for formatting the manual. The manual can be found at | ||||||||||||||||||||||||||||||||||||||||||
| 725 | the end of the git-autofixup script. | ||||||||||||||||||||||||||||||||||||||||||
| 726 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 727 | } | ||||||||||||||||||||||||||||||||||||||||||
| 728 | 0 | Pod::Usage::pod2usage(-exitval => 0, -verbose => 2); | |||||||||||||||||||||||||||||||||||||||||
| 729 | } | ||||||||||||||||||||||||||||||||||||||||||
| 730 | 54 | ▶ | if (@GIT_OPTIONS) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 731 | 0 | warn <<'EOF'; | |||||||||||||||||||||||||||||||||||||||||
| 732 | --gitopt|-g is deprecated and will be removed in a future release. Please use | ||||||||||||||||||||||||||||||||||||||||||
| 733 | the GIT_CONFIG_{COUNT,KEY,VALUE} environment variables instead; see `git help | ||||||||||||||||||||||||||||||||||||||||||
| 734 | config`. | ||||||||||||||||||||||||||||||||||||||||||
| 735 | EOF | ||||||||||||||||||||||||||||||||||||||||||
| 736 | } | ||||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||
| 738 | # "upstream" revisions as 40 byte SHA1 hex hashes. | ||||||||||||||||||||||||||||||||||||||||||
| 739 | 54 | my @upstreams = (); | |||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||
| 741 | 54 | ▶ | if ($raw_upstream) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 742 | 50 | my $upstream = rev_parse("${raw_upstream}^{commit}"); | |||||||||||||||||||||||||||||||||||||||||
| 743 | 50 | push @upstreams, $upstream; | |||||||||||||||||||||||||||||||||||||||||
| 744 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 745 | 4 | @upstreams = find_merge_bases(); | |||||||||||||||||||||||||||||||||||||||||
| 746 | 4 | ▶ | if (!@upstreams) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 747 | 0 | die "Can't find tracking branch. Please specify a revision.\n"; | |||||||||||||||||||||||||||||||||||||||||
| 748 | } | ||||||||||||||||||||||||||||||||||||||||||
| 749 | } | ||||||||||||||||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||||||||||||||||
| 751 | 54 | ▶ | if ($num_context_lines < 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 752 | 0 | die "number of context lines must be zero or greater\n"; | |||||||||||||||||||||||||||||||||||||||||
| 753 | } | ||||||||||||||||||||||||||||||||||||||||||
| 754 | |||||||||||||||||||||||||||||||||||||||||||
| 755 | 54 | ▶ | if (!grep { $strict == $_ } @STRICTNESS_LEVELS) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 756 | 0 | die "invalid strictness level: $strict\n"; | |||||||||||||||||||||||||||||||||||||||||
| 757 | ▶ | } elsif ($strict > 0 && $num_context_lines == 0) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$strict > 0 and $num_context_lines == 0
MC/DC0%0/2
$strict > 0 and $num_context_lines == 0
$strict > 0
$num_context_lines == 0
Truth table66%2/3
A and B
A= $strict > 0B= $num_context_lines == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | die "strict hunk assignment requires context\n"; | |||||||||||||||||||||||||||||||||||||||||
| 759 | } | ||||||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||||||||||||||||
| 762 | 54 | my $toplevel = toplevel_dir(); | |||||||||||||||||||||||||||||||||||||||||
| 763 | 54 | ▶ | chdir $toplevel or die "cd to toplevel: $!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 764 | |||||||||||||||||||||||||||||||||||||||||||
| 765 | 54 | my $hunks = diff_hunks($num_context_lines, @files); | |||||||||||||||||||||||||||||||||||||||||
| 766 | 54 | my $summary_for = summary_for_commits(@upstreams); | |||||||||||||||||||||||||||||||||||||||||
| 767 | 54 | my $alias_for = sha_aliases($summary_for); | |||||||||||||||||||||||||||||||||||||||||
| 768 | 54 | my $grafts_file = create_grafts_file(@upstreams); | |||||||||||||||||||||||||||||||||||||||||
| 769 | 54 | my %blame_for = map {$_ => blame($_, $alias_for, $grafts_file)} @{$hunks}; | |||||||||||||||||||||||||||||||||||||||||
| 770 | 54 | my $hunks_for = fixup_hunks_by_sha({ | |||||||||||||||||||||||||||||||||||||||||
| 771 | hunks => $hunks, | ||||||||||||||||||||||||||||||||||||||||||
| 772 | blame_for => \%blame_for, | ||||||||||||||||||||||||||||||||||||||||||
| 773 | summary_for => $summary_for, | ||||||||||||||||||||||||||||||||||||||||||
| 774 | strict => $strict, | ||||||||||||||||||||||||||||||||||||||||||
| 775 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 776 | 54 | my @ordered_shas = ordered_shas($hunks, sha_for_hunk_map($hunks_for)); | |||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||
| 778 | 54 | ▶ | if ($dryrun) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 779 | 0 | ▶ | if ($use_detailed_exit_codes) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 780 | 0 | return exit_code($hunks, $hunks_for); | |||||||||||||||||||||||||||||||||||||||||
| 781 | } | ||||||||||||||||||||||||||||||||||||||||||
| 782 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 783 | } | ||||||||||||||||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||||||||||||||||
| 785 | 54 | my $old_index = $ENV{GIT_INDEX_FILE}; | |||||||||||||||||||||||||||||||||||||||||
| 786 | 54 | local $ENV{GIT_INDEX_FILE}; # Throw away changes between main() calls. | |||||||||||||||||||||||||||||||||||||||||
| 787 | 54 | ▶ | if (is_index_dirty()) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 788 | # Limit the tempfile's lifetime to the execution of main(). | ||||||||||||||||||||||||||||||||||||||||||
| 789 | 3 | my $tempfile = create_temp_index($old_index); | |||||||||||||||||||||||||||||||||||||||||
| 790 | } | ||||||||||||||||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||||||||||||||||
| 792 | 54 | for my $sha (@ordered_shas) { | |||||||||||||||||||||||||||||||||||||||||
| 793 | 43 | my $fixup_hunks = $hunks_for->{$sha}; | |||||||||||||||||||||||||||||||||||||||||
| 794 | 43 | commit_fixup($sha, $fixup_hunks); | |||||||||||||||||||||||||||||||||||||||||
| 795 | } | ||||||||||||||||||||||||||||||||||||||||||
| 796 | 51 | ▶ | if ($use_detailed_exit_codes) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 797 | 47 | return exit_code($hunks, $hunks_for); | |||||||||||||||||||||||||||||||||||||||||
| 798 | } | ||||||||||||||||||||||||||||||||||||||||||
| 799 | 4 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 800 | } | ||||||||||||||||||||||||||||||||||||||||||
| 801 | |||||||||||||||||||||||||||||||||||||||||||
| 802 | 3 | ▶ | if (!caller()) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 803 | 0 | exit main(); | |||||||||||||||||||||||||||||||||||||||||
| 804 | } | ||||||||||||||||||||||||||||||||||||||||||
| 805 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||||||||||||||||
| 807 | __END__ | ||||||||||||||||||||||||||||||||||||||||||