[svk-commit] r2403 - in trunk: lib/SVK lib/SVK/Command t
nobody at bestpractical.com
nobody at bestpractical.com
Wed Jun 6 23:40:14 EDT 2007
Author: clkao
Date: Wed Jun 6 23:40:13 2007
New Revision: 2403
Modified:
trunk/ (props changed)
trunk/lib/SVK/Command/Commit.pm
trunk/lib/SVK/Util.pm
trunk/t/23commit.t
Log:
Commit message buffer enhancements.
Submitted by: sartak
r20323 at caladan: sartak | 2007-06-06 21:29:11 -0400
Local branch for commit enhancements
r20324 at caladan: sartak | 2007-06-06 21:31:26 -0400
Add verbose commits which will include ? files that you forgot to add :)
r20325 at caladan: sartak | 2007-06-06 21:35:43 -0400
Allow user to replace ? with A in the commit message to transparently svk add that file
r20326 at caladan: sartak | 2007-06-06 21:37:54 -0400
Add second header for unversioned items if there exist any
r20327 at caladan: sartak | 2007-06-06 22:03:11 -0400
Make -v the default!
Modified: trunk/lib/SVK/Command/Commit.pm
==============================================================================
--- trunk/lib/SVK/Command/Commit.pm (original)
+++ trunk/lib/SVK/Command/Commit.pm Wed Jun 6 23:40:13 2007
@@ -96,6 +96,10 @@
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 ===');
}
@@ -330,11 +334,8 @@
($fh, $file) = tmpfile ('commit', TEXT => 1, UNLINK => 0);
}
- if ($fh) {
- print $fh $self->{message} if $self->{template} and defined $self->{message};
- print $fh "\n", $self->target_prompt, "\n";
- }
-
+ my @targets;
+ my @unversioned;
my $targets = [];
my $encoder = get_encoder;
my ($status_editor, $commit_editor, $conflict_handler);
@@ -347,7 +348,7 @@
push @$targets, [$status->[0] || ($status->[1] ? 'P' : ''),
$copath];
no warnings 'uninitialized';
- print $fh sprintf ("%1s%1s%1s \%s\n", @{$status}[0..2], $copath) if $fh;
+ push @targets, sprintf ("%1s%1s%1s \%s\n", @{$status}[0..2], $copath);
}
);
@@ -385,6 +386,10 @@
absent_ignore => 1,
editor => $status_editor,
cb_conflict => sub { shift->conflict(@_) },
+ cb_unknown => sub {
+ my ($self, $path) = @_;
+ push @unversioned, "? $path\n";
+ },
);
my $conflicts = grep {$_->[0] eq 'C'} @$targets;
@@ -405,13 +410,23 @@
}
if ($fh) {
+ print $fh $self->{message} if $self->{template} and defined $self->{message};
+
+ my $header = $self->target_prompt;
+ $header .= "\n" . $self->unversioned_prompt
+ if @unversioned;
+ print $fh "\n", $header, "\n";
+
+ print $fh @targets;
+ print $fh @unversioned;
+
close $fh;
# get_buffer_from_editor may modify it, so it must be a ref first
$target->source->{targets} ||= [];
($self->{message}, $targets) =
- get_buffer_from_editor (loc('log message'), $self->target_prompt,
+ get_buffer_from_editor (loc('log message'), $header,
undef, $file, $target->copath, $target->source->{targets});
die loc("No targets to commit.\n") if $#{$targets} < 0;
$self->{save_message} = $$;
@@ -449,6 +464,25 @@
$self->decode_commit_message;
+ my @need_to_add = map {$target->copath($_->[1])}
+ grep {$_->[0] eq 'A'}
+ @$targets;
+ for (@need_to_add)
+ {
+ my $newprop;
+ my $autoprop = !-d $_;
+
+ $newprop = $self->{xd}->auto_prop($_)
+ if $autoprop;
+
+ # seems to work even if the file is already there (say the user changes
+ # an M to an A), but there really should be some kind of check
+ $self->{xd}{checkout}->store ($_,
+ { '.schedule' => 'add',
+ $autoprop ?
+ ('.newprop' => $newprop) : ()});
+ }
+
return ($commit_editor, [sort {$a->[1] cmp $b->[1]} @$targets]);
}
Modified: trunk/lib/SVK/Util.pm
==============================================================================
--- trunk/lib/SVK/Util.pm (original)
+++ trunk/lib/SVK/Util.pm Wed Jun 6 23:40:13 2007
@@ -314,8 +314,16 @@
# Compare targets in commit message
my $old_targets = (split (/\n\Q$sep\E\n/, $content, 2))[1];
- my @new_targets = map {s/^\s+//; # proponly change will have leading spacs
- [split(/[\s\+]+/, $_, 2)]} grep /\S/, split(/\n+/, $ret[1]);
+ $old_targets =~ s/^\?.*//mg; # remove unversioned files
+
+ my @new_targets =
+ map {
+ s/^\s+//; # proponly change will have leading spacs
+ [split(/[\s\+]+/, $_, 2)]}
+ grep {!/^\?/m} # remove unversioned fils
+ grep {/\S/}
+ split(/\n+/, $ret[1]);
+
if ($old_targets ne $ret[1]) {
# Assign new targets
@$targets_ref = map abs2rel($_->[1], $anchor, undef, '/'), @new_targets;
Modified: trunk/t/23commit.t
==============================================================================
--- trunk/t/23commit.t (original)
+++ trunk/t/23commit.t Wed Jun 6 23:40:13 2007
@@ -1,7 +1,7 @@
#!/usr/bin/perl -w
use strict;
use SVK::Test;
-plan tests => 56;
+plan tests => 69;
our $output;
my ($xd, $svk) = build_test();
@@ -10,6 +10,8 @@
our $answer = 'c';
+sub set_editor_foo
+{
set_editor(<< 'TMP');
$_ = shift;
open _ or die $!;
@@ -25,6 +27,54 @@
close _;
print @_;
TMP
+}
+
+sub set_editor_verbose
+{
+set_editor(<< 'TMP');
+$_ = shift;
+open _ or die $!;
+# remove foo from the targets
+ at _ = grep !/foo/, <_>;
+
+die "Doesn't include unversioned file"
+ unless grep {/verbose/} @_;
+
+# simulate some editing, for --template test
+s/monkey/gorilla/g for @_;
+s/birdie/parrot/g for @_;
+close _;
+unlink $_;
+open _, '>', $_ or die $!;
+print _ @_;
+close _;
+print @_;
+TMP
+}
+
+sub set_editor_verbose_add
+{
+set_editor(<< 'TMP');
+$_ = shift;
+open _ or die $!;
+# remove foo from the targets
+ at _ = grep !/foo/, <_>;
+
+# transparently add anything with verbose in the filename
+for (@_) { s/^\? (?= .* verbose $ )/A/mx }
+
+# simulate some editing, for --template test
+s/monkey/gorilla/g for @_;
+s/birdie/parrot/g for @_;
+close _;
+unlink $_;
+open _, '>', $_ or die $!;
+print _ @_;
+close _;
+print @_;
+TMP
+}
+set_editor_foo();
$svk->checkout ('//', $copath);
is_output_like ($svk, 'commit', [], qr'not a checkout path');
@@ -209,6 +259,84 @@
is_output ($svk, 'commit', [],
['Waiting for editor...',
'No targets to commit.'], 'target edited to empty');
+is_output ($svk, 'st', [],
+ [__('M A/foo')]);
+
+# test verbose with one unversioned file {{{
+set_editor_verbose();
+
+overwrite_file("A/verbose", "this is for testing that verbose commits (those including ? files) work");
+
+is_output ($svk, 'status', [],
+ [__('M A/foo'),
+ __('? A/verbose')]);
+
+is_output ($svk, 'commit', [],
+ ['Waiting for editor...',
+ 'No targets to commit.'], 'target edited to empty');
+
+overwrite_file("A/oof", "ouchies!");
+$svk->add("A/oof");
+is_output ($svk, 'commit', [],
+ ['Waiting for editor...',
+ 'Committed revision 16.'], 'commit message included unversioned A/verbose');
+is_output ($svk, 'status', [],
+ [__('M A/foo'),
+ __('? A/verbose')]);
+unlink "A/verbose";
+# }}}
+# test verbose with an unversioned subdirectory {{{
+mkdir ('A/deep/verbose');
+overwrite_file("A/deep/verbose/uno", "fun fun");
+overwrite_file("A/deep/verbose/dos", "fun *squared*");
+
+is_output ($svk, 'status', [],
+ [ __('? A/deep/verbose'),
+ __('M A/foo')]);
+
+is_output ($svk, 'commit', [],
+ ['Waiting for editor...',
+ 'No targets to commit.'], 'target edited to empty');
+
+overwrite_file("A/oof", "oh ok");
+is_output ($svk, 'commit', [],
+ ['Waiting for editor...',
+ 'Committed revision 17.'], 'commit message included unversioned subdir A/verbose/ and its two unversioned files');
+
+is_output ($svk, 'status', [],
+ [__('? A/deep/verbose'),
+ __('M A/foo')]);
+
+unlink "A/deep/verbose/uno";
+unlink "A/deep/verbose/dos";
+rmdir "A/deep/verbose/";
+# }}}
+
+# test transparent adds with verbose commits {{{
+set_editor_verbose_add();
+
+overwrite_file("A/verbose", "this is for testing that verbose commits (those including ? files) work");
+
+is_output ($svk, 'status', [],
+ [__('M A/foo'),
+ __('? A/verbose')]);
+
+is_output ($svk, 'commit', [],
+ ['Waiting for editor...',
+ 'Committed revision 18.'], 'we got a commit by replacing a ? with an A');
+
+is_output ($svk, 'status', [],
+ [__('M A/foo')]);
+
+overwrite_file("A/verbose", "you know the drill");
+
+is_output ($svk, 'status', [],
+ [__('M A/foo'),
+ __('M A/verbose')]);
+$svk->revert('A/verbose');
+# }}}
+
+set_editor_foo();
append_file ("A/foo", "foobar2");
is_output ($svk, 'status', [],
@@ -241,7 +369,7 @@
append_file ("A/bar", "foobar2");
is_output ($svk, 'commit', [],
['Waiting for editor...',
- 'Committed revision 18.'], 'buffer unmodified');
+ 'Committed revision 21.'], 'buffer unmodified');
$answer = 'a';
append_file ("A/bar", "foobar2");
is_output ($svk, 'commit', [],
@@ -254,20 +382,20 @@
["Can't use -F with -m."]);
is_output ($svk, 'commit', [-F => 'svk-commit'],
- ['Committed revision 19.'], 'commit with -F');
+ ['Committed revision 22.'], 'commit with -F');
-is_output_like ($svk, 'log', [-r => 19],
+is_output_like ($svk, 'log', [-r => 22],
qr/my log message/);
append_file ("A/bar", "please be changed");
is_output($svk, 'commit', [-m => "i like a monkey\nand a birdie", '--template'],
["Waiting for editor...",
- "Committed revision 20."], 'commit with -m and --template');
+ "Committed revision 23."], 'commit with -m and --template');
-is_output_like ($svk, 'log', [-r => 20],
+is_output_like ($svk, 'log', [-r => 23],
qr/i like a gorilla/, 'first line successfully edited from template');
-is_output_like ($svk, 'log', [-r => 20],
+is_output_like ($svk, 'log', [-r => 23],
qr/and a parrot/, 'second line successfully edited from template');
append_file ("A/bar", "changed some more");
@@ -275,23 +403,23 @@
is_output($svk, 'commit', [-F => 'svk-commit', '--template'],
["Waiting for editor...",
- "Committed revision 21."], 'commit with -F and --template');
+ "Committed revision 24."], 'commit with -F and --template');
-is_output_like ($svk, 'log', [-r => 21],
+is_output_like ($svk, 'log', [-r => 24],
qr/this time it's a parrot/, 'first line successfully edited from template');
-is_output_like ($svk, 'log', [-r => 21],
+is_output_like ($svk, 'log', [-r => 24],
qr/also a gorilla/, 'second line successfully edited from template');
overwrite_file("changeme", 'to be committed with revprop');
$svk->add("changeme");
is_output($svk, 'commit', [-m => 'with revprop', '--set-revprop', 'fnord=baz'],
- ["Committed revision 22."], 'fnord');
+ ["Committed revision 25."], 'fnord');
is_output(
- $svk, 'pl', ['-r' => 22, '--revprop'],
- ['Unversioned properties on revision 22:',
+ $svk, 'pl', ['-r' => 25, '--revprop'],
+ ['Unversioned properties on revision 25:',
' fnord',
' svn:author',
' svn:date',
More information about the svk-commit
mailing list