View | Details | Raw Unified | Return to bug 6473
Collapse All | Expand All

(-)a/lib/GitBz/Commands.pm (+2 lines)
Lines 16-22 package GitBz::Commands; Link Here
16
# along with git-bz; if not, see <https://www.gnu.org/licenses>.
16
# along with git-bz; if not, see <https://www.gnu.org/licenses>.
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
use Try::Tiny qw(catch try);
20
use Try::Tiny qw(catch try);
21
20
use GitBz::Exception;
22
use GitBz::Exception;
21
use GitBz::Config;
23
use GitBz::Config;
22
use GitBz::RestClient;
24
use GitBz::RestClient;
(-)a/lib/GitBz/Commands/Attach.pm (-28 / +27 lines)
Lines 22-27 use utf8; Link Here
22
use Getopt::Long qw(GetOptionsFromArray);
22
use Getopt::Long qw(GetOptionsFromArray);
23
use Try::Tiny    qw(catch try);
23
use Try::Tiny    qw(catch try);
24
use File::Temp;
24
use File::Temp;
25
25
use GitBz::Git;
26
use GitBz::Git;
26
use GitBz::Exception;
27
use GitBz::Exception;
27
use GitBz::StatusWorkflow;
28
use GitBz::StatusWorkflow;
Lines 90-106 sub attach_patches { Link Here
90
    my ( $self, $bug_ref, $commits, $opts ) = @_;
91
    my ( $self, $bug_ref, $commits, $opts ) = @_;
91
92
92
    my $client = $self->{commands}->{client};
93
    my $client = $self->{commands}->{client};
93
    my $bug = $client->get_bug($bug_ref);
94
    my $bug    = $client->get_bug($bug_ref);
94
    
95
95
    my $is_first = 1;
96
    my $is_first = 1;
96
    for my $commit (@$commits) {
97
    for my $commit (@$commits) {
97
        my $patch    = GitBz::Git->format_patch( $commit->{id} . '^..' . $commit->{id} );
98
        my $patch       = GitBz::Git->format_patch( $commit->{id} . '^..' . $commit->{id} );
98
        my $filename = sprintf( "%s.patch", substr( $commit->{id}, 0, 7 ) );
99
        my $filename    = sprintf( "%s.patch", substr( $commit->{id}, 0, 7 ) );
99
        my $description = $commit->{subject};
100
        my $description = $commit->{subject};
100
        my $body = GitBz::Git->run( 'log', '--format=%b', '-1', $commit->{id} );
101
        my $body        = GitBz::Git->run( 'log', '--format=%b', '-1', $commit->{id} );
101
        my $comment = $body || "Patch from commit " . substr( $commit->{id}, 0, 7 );
102
        my $comment     = $body || "Patch from commit " . substr( $commit->{id}, 0, 7 );
102
        my @obsoletes;
103
        my @obsoletes;
103
        
104
104
        if ( $opts->{edit} && $is_first ) {
105
        if ( $opts->{edit} && $is_first ) {
105
            ( $description, $comment, my $obsoletes_ref ) = $self->edit_attachment_comment( $bug, $commit );
106
            ( $description, $comment, my $obsoletes_ref ) = $self->edit_attachment_comment( $bug, $commit );
106
            @obsoletes = @$obsoletes_ref if $obsoletes_ref;
107
            @obsoletes = @$obsoletes_ref if $obsoletes_ref;
Lines 111-117 sub attach_patches { Link Here
111
            $patch,
112
            $patch,
112
            $filename,
113
            $filename,
113
            $description,
114
            $description,
114
            comment => $comment,
115
            comment   => $comment,
115
            obsoletes => \@obsoletes
116
            obsoletes => \@obsoletes
116
        );
117
        );
117
118
Lines 126-136 sub edit_attachment_comment { Link Here
126
    my $template = "";
127
    my $template = "";
127
    $template .= "# Attachment to Bug $bug->{id} - $bug->{summary}\n\n";
128
    $template .= "# Attachment to Bug $bug->{id} - $bug->{summary}\n\n";
128
    $template .= $commit->{subject} . "\n\n";
129
    $template .= $commit->{subject} . "\n\n";
129
    
130
130
    # Add commit body as initial comment
131
    # Add commit body as initial comment
131
    my $body = GitBz::Git->run( 'log', '--format=%b', '-1', $commit->{id} );
132
    my $body = GitBz::Git->run( 'log', '--format=%b', '-1', $commit->{id} );
132
    $template .= $body . "\n\n" if $body;
133
    $template .= $body . "\n\n" if $body;
133
    
134
134
    # Show existing patches for obsoleting
135
    # Show existing patches for obsoleting
135
    if ( $bug->{attachments} && @{ $bug->{attachments} } ) {
136
    if ( $bug->{attachments} && @{ $bug->{attachments} } ) {
136
        for my $patch ( @{ $bug->{attachments} } ) {
137
        for my $patch ( @{ $bug->{attachments} } ) {
Lines 140-156 sub edit_attachment_comment { Link Here
140
        }
141
        }
141
        $template .= "\n";
142
        $template .= "\n";
142
    }
143
    }
143
    
144
144
    # Add status options
145
    # Add status options
145
    my $client = $self->{commands}->{client};
146
    my $client   = $self->{commands}->{client};
146
    my $workflow = GitBz::StatusWorkflow->new($client);
147
    my $workflow = GitBz::StatusWorkflow->new($client);
147
    $template .= "# Current status: $bug->{status}\n";
148
    $template .= "# Current status: $bug->{status}\n";
148
    my $status_values = $workflow->get_next_status_values($bug->{status});
149
    my $status_values = $workflow->get_next_status_values( $bug->{status} );
149
    for my $status (@$status_values) {
150
    for my $status (@$status_values) {
150
        $template .= "# Status: $status\n";
151
        $template .= "# Status: $status\n";
151
    }
152
    }
152
    $template .= "\n";
153
    $template .= "\n";
153
    
154
154
    # Add patch complexity options
155
    # Add patch complexity options
155
    my $complexity = $bug->{cf_patch_complexity} || "";
156
    my $complexity = $bug->{cf_patch_complexity} || "";
156
    $template .= "# Current patch-complexity: $complexity\n";
157
    $template .= "# Current patch-complexity: $complexity\n";
Lines 161-179 sub edit_attachment_comment { Link Here
161
        }
162
        }
162
    }
163
    }
163
    $template .= "\n";
164
    $template .= "\n";
164
    
165
165
    # Add depends options
166
    # Add depends options
166
    my $depends = $bug->{depends_on} || [];
167
    my $depends     = $bug->{depends_on} || [];
167
    my $depends_str = ref($depends) eq 'ARRAY' ? join(' ', @$depends) : $depends;
168
    my $depends_str = ref($depends) eq 'ARRAY' ? join( ' ', @$depends ) : $depends;
168
    $template .= "# Current depends: $depends_str\n";
169
    $template .= "# Current depends: $depends_str\n";
169
    $template .= "# Depends: bug xxxx\n";
170
    $template .= "# Depends: bug xxxx\n";
170
    $template .= "# Depends: bug yyyy\n";
171
    $template .= "# Depends: bug yyyy\n";
171
    $template .= "\n";
172
    $template .= "\n";
172
    
173
173
    $template .= "# Please edit the description (first line) and comment (other lines).\n";
174
    $template .= "# Please edit the description (first line) and comment (other lines).\n";
174
    $template .= "# Lines starting with '#' will be ignored. Delete everything to abort.\n";
175
    $template .= "# Lines starting with '#' will be ignored. Delete everything to abort.\n";
175
    $template .= "# To obsolete existing patches, uncomment the appropriate lines.\n";
176
    $template .= "# To obsolete existing patches, uncomment the appropriate lines.\n";
176
    
177
177
    my $edited = $self->edit_template($template);
178
    my $edited = $self->edit_template($template);
178
    return $self->parse_edited_content($edited);
179
    return $self->parse_edited_content($edited);
179
}
180
}
Lines 198-215 sub edit_template { Link Here
198
199
199
sub parse_edited_content {
200
sub parse_edited_content {
200
    my ( $self, $content ) = @_;
201
    my ( $self, $content ) = @_;
201
    
202
202
    my @lines = split /\n/, $content;
203
    my @lines = split /\n/, $content;
203
    my @non_comment_lines = grep { !/^#/ && /\S/ } @lines;  # Also filter empty lines
204
    my @non_comment_lines = grep { !/^#/ && /\S/ } @lines;    # Also filter empty lines
204
    
205
205
    my $description = shift @non_comment_lines || "";
206
    my $description = shift @non_comment_lines || "";
206
    $description =~ s/^\s+|\s+$//g;
207
    $description =~ s/^\s+|\s+$//g;
207
    
208
208
209
    
210
    my @obsoletes;
209
    my @obsoletes;
211
    my @comment_lines;
210
    my @comment_lines;
212
    
211
213
    for my $line (@non_comment_lines) {
212
    for my $line (@non_comment_lines) {
214
        if ( $line =~ /^\s*Obsoletes\s*:\s*(\d+)/ ) {
213
        if ( $line =~ /^\s*Obsoletes\s*:\s*(\d+)/ ) {
215
            push @obsoletes, $1;
214
            push @obsoletes, $1;
Lines 217-228 sub parse_edited_content { Link Here
217
            push @comment_lines, $line;
216
            push @comment_lines, $line;
218
        }
217
        }
219
    }
218
    }
220
    
219
221
    my $comment = join( "\n", @comment_lines );
220
    my $comment = join( "\n", @comment_lines );
222
    $comment =~ s/^\s+|\s+$//g;
221
    $comment =~ s/^\s+|\s+$//g;
223
    
222
224
    GitBz::Exception->throw("Empty description, aborting\n") unless $description;
223
    GitBz::Exception->throw("Empty description, aborting\n") unless $description;
225
    
224
226
    return ( $description, $comment, \@obsoletes );
225
    return ( $description, $comment, \@obsoletes );
227
}
226
}
228
227
(-)a/lib/GitBz/Config.pm (+2 lines)
Lines 16-23 package GitBz::Config; Link Here
16
# along with git-bz; if not, see <https://www.gnu.org/licenses>.
16
# along with git-bz; if not, see <https://www.gnu.org/licenses>.
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
use Config::Tiny;
20
use Config::Tiny;
20
use File::HomeDir;
21
use File::HomeDir;
22
21
use GitBz::Git;
23
use GitBz::Git;
22
24
23
my $DEFAULT_CONFIG = {
25
my $DEFAULT_CONFIG = {
(-)a/lib/GitBz/Git.pm (-5 / +11 lines)
Lines 40-46 sub run { Link Here
40
40
41
sub rev_list {
41
sub rev_list {
42
    my ( $class, @args ) = @_;
42
    my ( $class, @args ) = @_;
43
    my $output = $class->run( 'rev-list', '--pretty=format:%s', @args );
43
44
    unshift( @args, '--pretty=format:%s' );
45
    unshift( @args, '--max-count=1' )
46
        if $args[1] eq 'HEAD';
47
48
    my $output = $class->run( 'rev-list', @args );
44
49
45
    my @commits;
50
    my @commits;
46
    my @lines = split /\n/, $output;
51
    my @lines = split /\n/, $output;
Lines 64-79 sub get_commits { Link Here
64
    my ( $class, $range ) = @_;
69
    my ( $class, $range ) = @_;
65
70
66
    # Try as single commit first - exactly like original git-bz
71
    # Try as single commit first - exactly like original git-bz
67
    my $rev = try { 
72
    my $rev = try {
68
        $class->run( 'rev-parse', $range, '--verify' );
73
        $class->run( 'rev-parse', $range, '--verify' );
69
    } catch { 
74
    } catch {
70
        undef 
75
        undef
71
    };
76
    };
72
77
73
    if ($rev) {
78
    if ($rev) {
79
74
        # Single commit - return just that one commit
80
        # Single commit - return just that one commit
75
        return $class->rev_list( '--max-count=1', $rev );
81
        return $class->rev_list( '--max-count=1', $rev );
76
    } else {
82
    } else {
83
77
        # Not a single commit, treat as range
84
        # Not a single commit, treat as range
78
        return $class->rev_list($range);
85
        return $class->rev_list($range);
79
    }
86
    }
80
- 

Return to bug 6473