#!/usr/bin/perl
our
@EXPORT_OK
=
qw(iso_time_with_dot gen_dot_patch)
;
sub
iso_time_with_dot {
strftime
"%Y-%m-%d.%H:%M:%S"
,
gmtime
(
shift
||
time
)
}
sub
gen_dot_patch {
my
$target
=
shift
||
'HEAD'
;
chomp
(
my
(
$git_dir
,
$is_bare
,
$sha1
)=`git rev-parse --git-dir --is-bare-repository
$target
`);
die
"Not in a git repository!"
if
!
$git_dir
;
$is_bare
=
""
if
$is_bare
and
$is_bare
eq
'false'
;
my
@branches
=(
'blead'
,
'maint-5.10'
,
'maint-5.8'
,
'maint-5.8-dor'
,
'maint-5.6'
,
'maint-5.005'
,
'maint-5.004'
,
'refs/heads/*'
,
'refs/remotes/*'
,
'refs/*'
,
);
my
$reftype
=
$is_bare
?
"heads"
:
"remotes/origin"
;
my
$branch
;
foreach
my
$name
(
@branches
) {
my
$refs
=
$name
=~m!^refs/! ?
$name
:
"refs/$reftype/$name"
;
my
$cmd
=
"git name-rev --name-only --refs=$refs $sha1"
;
chomp
(
$branch
= `
$cmd
`);
last
if
$branch
ne
'undefined'
;
}
for
(
$branch
) {
$_
||=
"error"
;
s!^\Q
$reftype
\E/!! ||
s!^refs/heads/!! ||
s!^refs/remotes/!! ||
s!^refs/!!;
s![~^].*\z!!;
}
my
$tstamp
= iso_time_with_dot(`git
log
-1 --pretty=
"format:%ct"
$sha1
`);
chomp
(
my
$describe
= `git describe
$sha1
`);
join
(
" "
,
$branch
,
$tstamp
,
$sha1
,
$describe
);
}
1;