From f46e6d667ede41cc57cf55cff505b91835d47da9 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 23 Jan 2012 01:18:49 +0000 Subject: [PATCH] fixes, including reflog --- BUGS | 1 - Topbloke.pm | 21 ++++++++++++++++----- tb-create.pl | 18 ++++++++---------- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/BUGS b/BUGS index 819bc52..e69de29 100644 --- a/BUGS +++ b/BUGS @@ -1 +0,0 @@ -enable reflog ?! diff --git a/Topbloke.pm b/Topbloke.pm index b6de690..215ae6b 100644 --- a/Topbloke.pm +++ b/Topbloke.pm @@ -1,13 +1,15 @@ # -*- perl -*- +package Topbloke; + use strict; use warnings; use POSIX; use IO::File; use IPC::Open2; - -package Topbloke; +use File::Path qw(make_path remove_tree); +use File::Basename; BEGIN { use Exporter (); @@ -18,7 +20,7 @@ BEGIN { @EXPORT = qw(debug run_git run_git_1line run_git_check_nooutput run_git_test_anyoutput git_get_object - git_config git_dir chdir_toplevel + git_config git_dir chdir_toplevel enable_reflog current_branch parse_patch_spec parse_patch_name setup_config check_no_unwanted_metadata patch_matches_spec @@ -95,8 +97,7 @@ sub git_get_object ($) { my ($objname) = @_; our ($gro_pid, $gro_out, $gro_in); if (!$gro_pid) { - $gro_pid = IPC::Open2::open2($gro_out, $gro_in, - $git_command, qw(cat-file --batch)) + $gro_pid = open2($gro_out, $gro_in, $git_command, qw(cat-file --batch)) or die $!; } #debug("git_get_object $objname"); @@ -155,6 +156,16 @@ sub chdir_toplevel () { chdir $toplevel or die "chdir toplevel $toplevel: $!\n"; } +sub enable_reflog ($) { + my ($branchref) = @_; + $branchref =~ m#^refs/# or die; + my $logsdir = git_dir().'/logs/'; + my $dirname = $logsdir.dirname($branchref); + make_path($dirname) or die "$dirname $!"; + open REFLOG, '>>', $logsdir.$branchref or die "$logsdir$branchref $!"; + close REFLOG or die $!; +} + sub current_branch () { open R, git_dir().'/HEAD' or die "open HEAD $!"; my $ref = ; defined $ref or die $!; diff --git a/tb-create.pl b/tb-create.pl index a3fd1b3..5c620f3 100755 --- a/tb-create.pl +++ b/tb-create.pl @@ -77,9 +77,10 @@ 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); } @@ -103,10 +104,7 @@ if (lstat '.topbloke') { } my $baseref = "refs/topbloke-bases/$newpatch"; -create_and_switch($baseref); - -run_git(qw(update-ref -m), "tb-create base $newpatch", $baseref, 'HEAD'); -run_git(qw(symbolic-ref HEAD), $baseref); +create_and_switch($baseref, 'base'); meta_and_stage('msg', "# not applicable\n"); meta_and_stage('deps', "# not applicable\n"); @@ -117,12 +115,12 @@ if ($current->{Kind} eq 'foreign') { meta_and_stage('pflags', ''); } -run_git(qw(commit -q -m), "tb-create base $newpatch"); +run_git(qw(commit -q -m), "tb-create $newpatch base"); #----- create the tip branch my $tipref = "refs/topbloke-tips/$newpatch"; -create_and_switch($tipref); +create_and_switch($tipref, 'tip'); my $nm = wf_start('.topbloke/msg'); wf($nm, "From: $author\n"); @@ -148,4 +146,4 @@ meta_and_stage('deps', "$current->{DepSpec}\n"); flagsfile_add_flag('included',$newpatch); stage_meta('included'); -run_git(qw(commit -q -m), "tb-create tip $spec->{Nick}\n$newpatch\n"); +run_git(qw(commit -q -m), "tb-create $newpatch tip"); -- 2.30.2