From: Ian Jackson Date: Sun, 22 Jan 2012 16:00:30 +0000 (+0000) Subject: wip; before reject dirty cache in create X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=topbloke.git;a=commitdiff_plain;h=a3fbf256b38bbd9c45347be9d2ab0ef2fc707129 wip; before reject dirty cache in create --- diff --git a/Topbloke.pm b/Topbloke.pm index f1c0615..4815b55 100644 --- a/Topbloke.pm +++ b/Topbloke.pm @@ -250,4 +250,35 @@ sub check_no_unwanted_metadata ($) { qw(.topbloke)); } +sub wf_start ($) { + my ($path) = @_; + my $fh = new IO::File '>', "$path.tmp" or die "$path.tmp: $!"; + $writing{$fh} = $path; + return [ $fh, $path ]; +} + +sub wf ($$) { + my ($wf, $data) = @_; + print $wf->[0] $data or die "$wf->[1]: $!"; +} + +sub wf_abort ($) { + my ($wf) = @_; + close $wf->[0]; + unlink $wf->[1] or die "$wf->[1]: $!"; +} + +sub wf_done ($) { + my ($wf) = @_; + close $wf->[0] or die "$wf->[1]: $!"; + rename $wf->[1].'.tmp', $wf->[1] or die "$wf->[1]: $!"; +} + +sub wf_contents ($$) { + my ($path,$contents) = @_; + my $wf = wf_start($path); + wf($wf, $contents); + wf_done($wf); +} + 1; diff --git a/tb-create.pl b/tb-create.pl index 591a72e..fcacc6f 100755 --- a/tb-create.pl +++ b/tb-create.pl @@ -59,30 +59,32 @@ printf "creating %s\n", $newbranch; setup_config(); +run_git__anyoutput(qw(diff --cached --name-only HEAD -- + if (!run_git_test_anyoutput(qw(diff --name-only HEAD -- .topbloke/msg)) { - open NM, '>', ".topbloke/msg.tmp" or die $!; + my $nm = wf_start('.topbloke/msg'); my $author = run_git_1line(qw(var GIT_AUTHOR_IDENT)); $author =~ s/ \d+ [-+]\d+$//; - print NM "From: $author\n" or die $!; + wf($nm, "From: $author\n"); foreach my $h (qw(To CC BCC)) { my $estatus; - run_git(\$estatus, sub { print NM "$h: $_" or die $!; }, + run_git(\$estatus, sub { wf($nm, "$h: $_") or die $!; }, qw(config), "topbloke.".lc $h); die "$h $estatus" unless $estatus==0 || $estatus==256; } $subjprefix = git_config('topbloke.subjectprefix', ''); - print NM {Nick} Signed-off-by: $author END + wf_done($nm); run_git(qw(add .topbloke/msg)); print " created and staged new .topbloke/msg\n"; } else { - if (!run_git_test_anyoutput(qw(diff --cached --name-only HEAD -- - .topblokemsg))) { + if (! print " staged your modified .topbloke/msg\n"; run_git(qw(add .topbloke/msg)); } else { @@ -90,3 +92,15 @@ END } } +sub meta_and_stage ($$) { + my ($file, $contents) = @_; + wf_contents(".topbloke/$file", $contents); + run_git(qw(add), ".topbloke/$file"); +} + +meta_and_stage("deps", $current->{DepSpec}."\n"); +meta_and_stage("flags", ''); + +if ($current->{Kind} eq 'foreign') { + meta_and_stage('included', $current->{DepSpec}); +