chiark / gitweb /
wip, can do attribs setup
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 21 Jan 2012 11:06:46 +0000 (11:06 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 21 Jan 2012 11:06:46 +0000 (11:06 +0000)
FORMAT
Topbloke.pm
tb-create.pl
tg-create.pl [deleted file]

diff --git a/FORMAT b/FORMAT
index 5c22cc6f9104e74027f89442c22b0380c52ececd..258e073205cb39874e446435c7eceb06fd19902e 100644 (file)
--- a/FORMAT
+++ b/FORMAT
@@ -22,8 +22,6 @@ In-tree, there are metadata files in .topbloke
                         otherwise fatal.  Currently defined flags:
                                Deleted         branch is deleted
 
-       .gitattributes  Sets the attributes
-
 
 <full-name> has the format:
        <email>@<domain.name>/<yyyy>-<mm>-<dd>T<hh><mm><ss>Z/<nickname-path>
index 8979a6ed851d41171acecdc626d5b7577a55a7e2..79c47b87ad5d522004c289499284a77164fb730b 100644 (file)
@@ -3,6 +3,9 @@
 use strict;
 use warnings;
 
+use POSIX;
+use IO::File;
+
 package Topbloke;
 
 BEGIN {
@@ -11,11 +14,16 @@ BEGIN {
 
     $VERSION     = 1.00;
     @ISA         = qw(Exporter);
-    @EXPORT      = qw(parse_branch_spec current_tb_branch run_git_1line);
+    @EXPORT      = qw(parse_branch_spec current_tb_branch run_git_1line
+                      setup_config);
     %EXPORT_TAGS = ( );
     @EXPORT_OK   = qw();
 }
 
+sub debug ($) {
+    my ($msg) = @_;
+    print STDERR "DEBUG: $msg\n" or die $!;
+}
 
 sub run_git_1line {
     open GIT, "-|", 'git', @_ or die $!;
@@ -26,6 +34,24 @@ sub run_git_1line {
     return $l;
 }
 
+sub run_git_1line_estatus {
+    open GIT, "-|", 'git', @_ or die $!;
+    my $l = <GIT>;
+    $?=0;
+    if (close GIT) {
+       chomp $l or die "@_ ?";
+       return (0,$l);
+    } else {
+       die unless $?;
+       return ($?,undef);
+    }
+}
+
+sub run_git_nooutput {
+    my $rc = system('git', @_);
+    die "git @_ failed ($rc)" if $rc;
+}
+
 sub git_dir () {
     our $git_dir;
     if (!defined $git_dir) {
@@ -122,17 +148,53 @@ sub parse_branch_spec ($) {
 }
 
 sub setup_config () {
-    my ($files) = (qw(msg deps included flags gitattributes));
+    my (@files) = (qw(msg deps included flags));
     my $version = 1;
-    foreach my $file ($files) {
-       my $cfgname = "merge.topbloke-$file.";
-       my $current = run_git_1line(qw(config), "$cfgname.driver");
-       next if $current =~ m/^topbloke-merge-driver --v$version /o;
-       debug("setting merge driver $file");
-       run_git_1line(qw(config), "$cfgname.name",
-                     "topbloke merge driver for $file");
-       run_git_1line(qw(config), "$cfgname.driver",
-                     "topbloke-merge-driver --v$version $file %O %A %B %L");
+    foreach my $iteration (qw(0 1)) {
+       foreach my $file (@files) {
+           my $cfgname = "merge.topbloke-$file";
+           my ($current_estatus, $current) =
+               run_git_1line_estatus(qw(config), "$cfgname.driver");
+           $current = "## failed $current_estatus" if $current_estatus;
+           next if $current =~ m/^topbloke-merge-driver --v$version /o;
+           die "$file $current ?" if $iteration;
+           debug("setting merge driver $file");
+           run_git_nooutput(qw(config), "$cfgname.name",
+                            "topbloke merge driver for $file");
+           run_git_nooutput(qw(config), "$cfgname.driver",
+                            "topbloke-merge-driver --v$version".
+                            " $file %O %A %B %L");
+       }
+       my ($newattrs, $attrsfile);
+       foreach my $file (@files) {
+           my $path = ".topbloke/$file";
+           my $current = run_git_1line(qw(check-attr merge), $path);
+           $current =~ s#^\Q$path\E: merge: ## or die "$file $current ?";
+           my $want = "topbloke-$file";
+           next if $current eq $want;
+           die "$file $current ?" unless $current eq 'unspecified';
+           die "$file $current ?" if $iteration;
+           if (!$newattrs) {
+               $attrsfile = git_dir()."/info/attributes";
+               $newattrs = new IO::File "$attrsfile.tmp", 'w'
+                   or die "$attrsfile.tmp: $!";
+               if (!open OA, '<', "$attrsfile") {
+                   die "$attrsfile $!" unless $!==&ENOENT;
+               } else {
+                   while (<OA>) {
+                       print $newattrs $_ or die $!;
+                       print "\n" or die $! unless chomp;
+                   }
+                   die $! if OA->error;
+                   die $! unless close OA;
+               }
+                       
+           }
+           print $newattrs "$path\tmerge=$want\n" or die $!;
+       }
+       last if !$newattrs;
+       close $newattrs or die $!;
+       rename "$attrsfile.tmp", "$attrsfile" or die $!;
     }
 }
 
index d4c9a7e9751c691abf4165e909c85fdb22b9b0d1..f0bd5635128f1a79cc3cfda8fe185770610579a3 100755 (executable)
@@ -46,3 +46,5 @@ my $newbranch = "$spec->{Email}\@$spec->{Domain}/$spec->{Date}/$spec->{Nick}";
 $newbranch = run_git_1line(qw(check-ref-format --print), $newbranch);
 
 printf "creating %s\n", $newbranch;
+
+setup_config();
diff --git a/tg-create.pl b/tg-create.pl
deleted file mode 100644 (file)
index f0bd563..0000000
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/usr/bin/perl
-
-use warnings;
-use strict;
-
-use Getopt::Long;
-use Topbloke;
-
-Getopt::Long::Configure(qw(bundling));
-
-die "bad usage\n" unless @ARGV==1;
-
-our $spec = parse_branch_spec($ARGV[0]);
-our $current = current_tb_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"
-    unless ($current->{Kind} eq 'foreign' ||
-           $current->{Kind} eq 'tip');
-
-sub fillin ($$$) {
-    my ($key, $newval, $what) = @_;
-    return if defined $spec->{$key};
-    $spec->{$key} = $newval;
-}
-
-if (!defined $spec->{Email} || !defined $spec->{Domain}) {
-    my $eaddr = run_git_1line(qw(config user.email));
-    $eaddr =~ m/^(.*)\@/ or die "$eaddr ?";
-    fillin('Email',$1,'email domain');
-    fillin('Domain',$','email domain'); #');
-}
-
-if (!defined $spec->{Date}) {
-    $spec->{Date} = `LC_TIME=C date -u +%Y-%m-%dT%H%M%SZ`;
-    chomp $spec->{Date} or die $!;
-}
-
-length($spec->{Date})==18 or die "partial date specified, not supported\n";
-
-my $newbranch = "$spec->{Email}\@$spec->{Domain}/$spec->{Date}/$spec->{Nick}";
-
-$newbranch = run_git_1line(qw(check-ref-format --print), $newbranch);
-
-printf "creating %s\n", $newbranch;
-
-setup_config();