X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=topbloke.git;a=blobdiff_plain;f=tb-create.pl;h=3a9afc311112826f9367c2c0e59358937702e995;hp=2b456807d23fc2633925d04d169476b2568cc46e;hb=1a6262c839e4ed26b66cbbeb68910d89be52ac03;hpb=faf0b5afe4a557285034a0230bb294ee49b34cdb diff --git a/tb-create.pl b/tb-create.pl index 2b45680..3a9afc3 100755 --- a/tb-create.pl +++ b/tb-create.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl -# usage: tb-create +# usage: tb-create use warnings; use strict; @@ -11,14 +11,11 @@ Getopt::Long::Configure(qw(bundling)); die "bad usage\n" unless @ARGV==1; -our $spec = parse_branch_spec($ARGV[0]); +our $spec = parse_patch_spec($ARGV[0]); our $current = current_branch(); -die "cannot make branch starting at base of another;". - " check out a real branch\n" if $current->{Kind} eq 'base'; - -die "strange branch ref $current->{Kind} $current->{Ref},\n". - " making new branch with this as dep is unwise\n" +die "strange branch ref $current->{Ref} is of kind $current->{Kind},\n". + " making new patch with this as dep is not supported\n" unless ($current->{Kind} eq 'foreign' || $current->{Kind} eq 'tip'); @@ -40,44 +37,41 @@ if (!defined $spec->{Date}) { chomp $spec->{Date} or die $!; } +defined $spec->{Nick} or die "no patch nickname specified\n"; + length($spec->{Date})==18 or die "partial date specified, not supported\n"; chdir_toplevel(); -check_no_unwanted_metadata('HEAD') - if $current->{Kind} ne 'tip'; - -run_git_check_nooutput("cannot create new topbloke branch with staged file(s)", +run_git_check_nooutput("cannot create new patch with staged file(s)", qw(diff --cached --name-only HEAD --)); -run_git_check_nooutput("cannot create new topbloke branch with". +run_git_check_nooutput("cannot create new patch with". " modified metadata file(s)", qw(diff --name-only HEAD -- .topbloke)); # For the metadata files in .topbloke, we hope that the user # doesn't modify them. If they do then they get to keep all the pieces. # -# For .topbloke/msg, if it's modified by the user (ie, if working -# version differs from HEAD) we keep that and stage it. - -my $newbranch = "$spec->{Email}\@$spec->{Domain}/$spec->{Date}/$spec->{Nick}"; +my $newpatch = "$spec->{Email}\@$spec->{Domain}/$spec->{Date}/$spec->{Nick}"; -$newbranch = run_git_1line(qw(check-ref-format --print), $newbranch); +$newpatch = run_git_1line(qw(check-ref-format --print), $newpatch); my $author = run_git_1line(qw(var GIT_AUTHOR_IDENT)); $author =~ s/ \d+ [-+]\d+$// or die $!; my $subjprefix = git_config('topbloke.subjectprefix', ''); -printf "creating %s\n", $newbranch; +printf "creating %s\n", $newpatch; setup_config(); #----- subroutines for setup -sub create_and_switch ($) { - my ($branchref) = @_; - run_git(qw(update-ref -m), "tb-create base", $branchref, 'HEAD'); +sub create_and_switch ($$) { + my ($branchref, $what) = @_; + enable_reflog($branchref); + run_git(qw(update-ref -m), "tb-create $newpatch $what", $branchref, 'HEAD'); run_git(qw(symbolic-ref HEAD), $branchref); } @@ -92,6 +86,11 @@ sub meta_and_stage ($$) { stage_meta($file); } +sub meta_rm_stage ($) { + my ($file) = @_; + run_git(qw(rm --ignore-unmatch -q --), ".topbloke/$file"); +} + #----- create the base branch if (lstat '.topbloke') { @@ -100,27 +99,48 @@ if (lstat '.topbloke') { mkdir('.topbloke') or die "create .topbloke: $!\n"; } -my $baseref = "refs/topbloke-bases/$newbranch"; -create_and_switch($baseref); +my @meta_to_rm; -run_git(qw(update-ref -m), "tb-create base $newbranch", $baseref, 'HEAD'); -run_git(qw(symbolic-ref HEAD), $baseref); +if ($current->{Kind} eq 'foreign') { + check_no_metadata('HEAD'); +} else { + foreach_unknown_metadata('HEAD', + sub { push @meta_to_rm, $_ unless m/^\+/; }); +} -meta_and_stage('msg', "# not applicable\n"); -meta_and_stage('deps', "# not applicable\n"); -meta_and_stage('flags', ''); +my $baseref = "$baserefs/$newpatch"; +my $currentcommit = run_git_1line(qw(rev-parse), "HEAD"); +create_and_switch($baseref, 'base'); + +meta_rm_stage('msg'); +meta_and_stage('patch', "$newpatch\n"); +meta_rm_stage('base'); +meta_and_stage('deps', "$current->{DepSpec}\n"); +meta_rm_stage('deleted'); +meta_rm_stage($_) foreach @meta_to_rm; if ($current->{Kind} eq 'foreign') { - meta_and_stage('included', $current->{DepSpec}."\n"); - meta_and_stage('pflags', ''); + meta_and_stage('+included', ""); + meta_and_stage('+ends', ""); +} else { + # we inherit correct contents for +included + if ($current->{Kind} eq 'tip') { + metafile_process('+ends', undef, sub { + die if m/^\Q$current->{Fullname}\E /; + }, sub { + wf($_->[0], "$current->{Fullname} $currentcommit\n"); + }, undef); + stage_meta('+ends'); + } } -run_git(qw(commit -q -m), "create base branch $newbranch"); +run_git(qw(commit -q -m), "tb-create $newpatch base"); +my $basecommit = run_git_1line(qw(rev-parse), "$baseref~0"); #----- create the tip branch -my $tipref = "refs/topbloke-tips/$newbranch"; -create_and_switch($tipref); +my $tipref = "$tiprefs/$newpatch"; +create_and_switch($tipref, 'tip'); my $nm = wf_start('.topbloke/msg'); wf($nm, "From: $author\n"); @@ -140,10 +160,9 @@ END wf_done($nm); stage_meta('msg'); -meta_and_stage('deps', "$current->{DepSpec}\n"); -# we inherit empty flags from the base branch - -flagsfile_add_flag('included',$newbranch); -stage_meta('included'); +meta_and_stage('base', "$basecommit\n"); +meta_rm_stage('deps'); +depsfile_add_dep('+included',$newpatch); +stage_meta('+included'); -run_git(qw(commit -q -m), "create branch $spec->{Nick}\n$newbranch\n"); +run_git(qw(commit -q -m), "tb-create $newpatch tip");