much much quicker solution
[p5sagit/p5-mst-13.2.git] / Porting / make_dot_patch.pl
CommitLineData
919d72bf 1#!/usr/bin/perl
031cefa0 2use strict;
3use warnings;
4
5# This is a quickie script which I wrote to generate the .patch file for
6# an arbitrary commit. It takes on sha1 as an argument, or saving that
7# uses the sha1 associated to HEAD.
8# It tries to find which of our primary branches the sha1 can be found on,
9# and then prints to standard out something similar to what our rsync feed
10# would produce for that situation. The main difference being, in that case
11# we KNOW what branch we are on, and in this one we dont, and in that case
12# the $tstamp field holds the time the snapshot was generated (so that multiple
13# fetches will always have an increasing tstamp field), however in this case
14# we use the commit date of the sha1.
15#
16# This is more or less intended to be used as a utility to generated .patch
17# files for other processes, like gitweb and snapshots.
18#
19# The script assumes it is being run from a git WD.
20#
21# Yves
22
23use POSIX qw(strftime);
24sub isotime { strftime "%Y-%m-%d.%H:%M:%S",gmtime(shift||time) }
25
b20f2637 26my $target= shift || 'HEAD';
27chomp(my ($git_dir, $is_bare, $sha1)=`git rev-parse --git-dir --is-bare-repository $target`);
28die "Not in a git repository!" if !$git_dir;
29$is_bare= "" if $is_bare and $is_bare eq 'false';
031cefa0 30my @branches=(
b20f2637 31 'blead',
32 'maint-5.10',
33 'maint-5.8',
34 'maint-5.8-dor',
35 'maint-5.6',
36 'maint-5.005',
37 'maint-5.004',
031cefa0 38);
b20f2637 39my $reftype= $is_bare ? "heads" : "remotes/origin";
031cefa0 40my $branch;
b20f2637 41foreach my $name (@branches) {
42 my $cmd= "git name-rev --name-only --refs=refs/$reftype/$name $sha1";
43 chomp($branch= `$cmd`);
44 last if $branch ne 'undefined';
031cefa0 45}
b20f2637 46$branch ||= "error";
47$branch =~ s!^\Q$reftype\E/!!;
48$branch =~ s![~^].*\z!!;
031cefa0 49my $tstamp= isotime(`git log -1 --pretty="format:%ct" $sha1`);
50chomp(my $describe= `git describe`);
51print join(" ", $branch, $tstamp, $sha1, $describe) . "\n";
52