SVK

 view release on metacpan or  search on metacpan

lib/SVK/Command/Commit.pm  view on Meta::CPAN

# General Public License for more details.
# 
# CONTRIBUTION SUBMISSION POLICY:
# 
# (The following paragraph is not intended to limit the rights granted
# to you to modify and distribute this software under the terms of the
# GNU General Public License and is only of importance to you if you
# choose to contribute your changes and enhancements to the community
# by submitting them to Best Practical Solutions, LLC.)
# 
# By intentionally submitting any modifications, corrections or
# derivatives to this work, or any other work intended for use with SVK,
# to Best Practical Solutions, LLC, you confirm that you are the
# copyright holder for those contributions and you grant Best Practical
# Solutions, LLC a nonexclusive, worldwide, irrevocable, royalty-free,
# perpetual, license to use, copy, create derivative works based on
# those contributions, and sublicense and distribute those contributions
# and any derivatives thereof.
# 
# END BPS TAGGED BLOCK }}}
package SVK::Command::Commit;
use strict;
use SVK::Version;  our $VERSION = $SVK::VERSION;
use base qw( SVK::Command );
use constant opt_recursive => 1;
use SVK::XD;
use SVK::I18N;
use SVK::Logger;
use SVK::Editor::Status;
use SVK::Editor::Dynamic;
use SVK::Command::Sync;
use SVK::Editor::InteractiveCommitter;
use SVK::Editor::InteractiveStatus;

use SVK::Util qw( get_buffer_from_editor slurp_fh read_file
		  tmpfile abs2rel from_native to_native
		  get_encoder get_anchor );

use Class::Autouse qw( SVK::Editor::Rename SVK::Editor::Merge );

sub options {
    ('m|message=s'    => 'message',
     'F|file=s'       => 'message_file',
     'C|check-only'   => 'check_only',
     'P|patch=s'      => 'patch',
     'import'         => 'import',
     'direct'         => 'direct',
     'template'       => 'template',
     'i|interactive'  => 'interactive',
     'set-revprop=s@' => 'setrevprop',
    );
}

sub parse_arg {
    my ($self, @arg) = @_;
    @arg = ('') if $#arg < 0;

    return $self->arg_condensed (@arg);
}

sub lock { $_[0]->lock_coroot($_[1]) }

sub target_prompt {
    loc('=== Targets to commit (you may delete items from it) ===');
}

sub unversioned_prompt {
    loc("=== You may change '?' to 'A' to add unversioned items ===");
}

sub message_prompt {
    loc('=== Please enter your commit message above this line ===');
}

sub under_mirror {
    my ($self, $target) = @_;
    return if $self->{direct};
    return $target->is_mirrored;
}

sub fill_commit_message {
    my $self = shift;
    if ($self->{message_file}) {
	die loc ("Can't use -F with -m.\n")
	    if defined $self->{message};
	$self->{message} = read_file ($self->{message_file});
    }
}

sub get_commit_message {
    my ($self, $extra_message) = @_;
    # The existence of $extra_message (the logs from a sm -l, say) should *not*
    # prevent the editor from being opened, if there is no -m/-F
    
    $self->fill_commit_message; # from -F to -m

    # We have to decide whether or not to launch the editor *before* we append
    # $extra_message to the -m/-F message
    my $should_launch_editor = ($self->{template} or not defined $self->{message});

    if (defined $extra_message or defined $self->{message}) {
	$self->{message} = join "\n", grep { defined $_ and length $_ } ($self->{message}, $extra_message);
    } 

    if ($should_launch_editor) {
	$self->{message} = get_buffer_from_editor
	    (loc('log message'), $self->message_prompt,
	     join ("\n", $self->{message} || '', $self->message_prompt, ''), 'commit');
	$self->{save_message} = $$;
    }
    $self->decode_commit_message;
}

sub decode_commit_message {
    my $self = shift;
    eval { from_native ($self->{message}, 'commit message', $self->{encoding}); 1 }
	or die $@.loc("try --encoding.\n");
}

# XXX: This should just return Editor::Dynamic objects
sub get_dynamic_editor {



( run in 0.941 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )