use strict;
use warnings;
+use POSIX;
+use IO::File;
+
package Topbloke;
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 $!;
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) {
}
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 $!;
}
}
+++ /dev/null
-#!/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();