chiark / gitweb /
create works again
[topbloke.git] / tb-create.pl
index b01010b8333172c0af35bcf60b0ce0d910a3e83c..3a9afc311112826f9367c2c0e59358937702e995 100755 (executable)
@@ -1,16 +1,12 @@
 #!/usr/bin/perl
 # usage: tb-create <patch-spec>
 
-xxx needs updating for new metadata and new theory
-
 use warnings;
 use strict;
 
 use Getopt::Long;
 use Topbloke;
 
-fixme needs update to new metadata;
-
 Getopt::Long::Configure(qw(bundling));
 
 die "bad usage\n" unless @ARGV==1;
@@ -18,11 +14,8 @@ die "bad usage\n" unless @ARGV==1;
 our $spec = parse_patch_spec($ARGV[0]);
 our $current = current_branch();
 
-die "cannot make patch starting at base of another;".
-    " check out a real branch or patch\n" if $current->{Kind} eq 'base';
-
-die "strange branch ref $current->{Kind} $current->{Ref},\n".
-    " making new patch 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');
 
@@ -50,9 +43,6 @@ 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 patch with staged file(s)",
                       qw(diff --cached --name-only HEAD --));
 
@@ -63,9 +53,6 @@ run_git_check_nooutput("cannot create new patch with".
 # 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 $newpatch = "$spec->{Email}\@$spec->{Domain}/$spec->{Date}/$spec->{Nick}";
 
 $newpatch = run_git_1line(qw(check-ref-format --print), $newpatch);
@@ -99,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') {
@@ -107,23 +99,47 @@ if (lstat '.topbloke') {
     mkdir('.topbloke') or die "create .topbloke: $!\n";
 }
 
-my $baseref = "refs/topbloke-bases/$newpatch";
+my @meta_to_rm;
+
+if ($current->{Kind} eq 'foreign') {
+    check_no_metadata('HEAD');
+} else {
+    foreach_unknown_metadata('HEAD', 
+                            sub { push @meta_to_rm, $_ unless m/^\+/; });
+}
+
+my $baseref = "$baserefs/$newpatch";
+my $currentcommit = run_git_1line(qw(rev-parse), "HEAD");
 create_and_switch($baseref, 'base');
 
-meta_and_stage('msg', "# not applicable\n");
-meta_and_stage('deps', "");
-meta_and_stage('props', "patch $current->{Fullname}\n");
+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('pprops', '');
+    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), "tb-create $newpatch base");
+my $basecommit = run_git_1line(qw(rev-parse), "$baseref~0");
 
 #----- create the tip branch
 
-my $tipref = "refs/topbloke-tips/$newpatch";
+my $tipref = "$tiprefs/$newpatch";
 create_and_switch($tipref, 'tip');
 
 my $nm = wf_start('.topbloke/msg');
@@ -144,10 +160,9 @@ END
 wf_done($nm);
 stage_meta('msg');
 
-meta_and_stage('deps', "$current->{DepSpec}\n");
-# we inherit correct props and pprops from the base branch
-
-depsfile_add_dep('included','tb',$newpatch);
-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), "tb-create $newpatch tip");