2006-06-02 07:32:20 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
use IkiWiki;
|
2006-07-05 22:54:10 +02:00
|
|
|
use Encode;
|
|
|
|
use open qw{:utf8 :std};
|
2006-06-02 07:32:20 +02:00
|
|
|
|
|
|
|
package IkiWiki;
|
|
|
|
|
|
|
|
my $sha1_pattern = qr/[0-9a-fA-F]{40}/; # pattern to validate Git sha1sums
|
2006-06-03 20:03:41 +02:00
|
|
|
my $dummy_commit_msg = 'dummy commit'; # message to skip in recent changes
|
2006-06-02 07:32:20 +02:00
|
|
|
|
|
|
|
sub _safe_git (&@) { #{{{
|
|
|
|
# Start a child process safely without resorting /bin/sh.
|
|
|
|
# Return command output or success state (in scalar context).
|
|
|
|
|
|
|
|
my ($error_handler, @cmdline) = @_;
|
|
|
|
|
|
|
|
my $pid = open my $OUT, "-|";
|
|
|
|
|
|
|
|
error("Cannot fork: $!") if !defined $pid;
|
|
|
|
|
|
|
|
if (!$pid) {
|
|
|
|
# In child.
|
|
|
|
# Git commands want to be in wc.
|
|
|
|
chdir $config{srcdir}
|
|
|
|
or error("Cannot chdir to $config{srcdir}: $!");
|
|
|
|
exec @cmdline or error("Cannot exec '@cmdline': $!");
|
|
|
|
}
|
|
|
|
# In parent.
|
|
|
|
|
|
|
|
my @lines;
|
|
|
|
while (<$OUT>) {
|
|
|
|
chomp;
|
|
|
|
push @lines, $_;
|
|
|
|
}
|
|
|
|
|
|
|
|
close $OUT;
|
|
|
|
|
2007-10-11 01:27:11 +02:00
|
|
|
$error_handler->("'@cmdline' failed: $!") if $? && $error_handler;
|
2006-06-02 07:32:20 +02:00
|
|
|
|
|
|
|
return wantarray ? @lines : ($? == 0);
|
|
|
|
}
|
|
|
|
# Convenient wrappers.
|
2006-09-10 00:50:27 +02:00
|
|
|
sub run_or_die ($@) { _safe_git(\&error, @_) }
|
2006-06-02 07:32:20 +02:00
|
|
|
sub run_or_cry ($@) { _safe_git(sub { warn @_ }, @_) }
|
|
|
|
sub run_or_non ($@) { _safe_git(undef, @_) }
|
|
|
|
#}}}
|
|
|
|
|
|
|
|
sub _merge_past ($$$) { #{{{
|
|
|
|
# Unlike with Subversion, Git cannot make a 'svn merge -rN:M file'.
|
|
|
|
# Git merge commands work with the committed changes, except in the
|
2007-10-31 22:37:33 +01:00
|
|
|
# implicit case of '-m' of git checkout(1). So we should invent a
|
2006-06-02 07:32:20 +02:00
|
|
|
# kludge here. In principle, we need to create a throw-away branch
|
|
|
|
# in preparing for the merge itself. Since branches are cheap (and
|
|
|
|
# branching is fast), this shouldn't cost high.
|
|
|
|
#
|
|
|
|
# The main problem is the presence of _uncommitted_ local changes. One
|
|
|
|
# possible approach to get rid of this situation could be that we first
|
|
|
|
# make a temporary commit in the master branch and later restore the
|
|
|
|
# initial state (this is possible since Git has the ability to undo a
|
2007-10-31 22:37:33 +01:00
|
|
|
# commit, i.e. 'git reset --soft HEAD^'). The method can be summarized
|
2006-06-02 07:32:20 +02:00
|
|
|
# as follows:
|
|
|
|
#
|
|
|
|
# - create a diff of HEAD:current-sha1
|
|
|
|
# - dummy commit
|
|
|
|
# - create a dummy branch and switch to it
|
|
|
|
# - rewind to past (reset --hard to the current-sha1)
|
|
|
|
# - apply the diff and commit
|
|
|
|
# - switch to master and do the merge with the dummy branch
|
|
|
|
# - make a soft reset (undo the last commit of master)
|
|
|
|
#
|
|
|
|
# The above method has some drawbacks: (1) it needs a redundant commit
|
|
|
|
# just to get rid of local changes, (2) somewhat slow because of the
|
|
|
|
# required system forks. Until someone points a more straight method
|
|
|
|
# (which I would be grateful) I have implemented an alternative method.
|
|
|
|
# In this approach, we hide all the modified files from Git by renaming
|
|
|
|
# them (using the 'rename' builtin) and later restore those files in
|
|
|
|
# the throw-away branch (that is, we put the files themselves instead
|
|
|
|
# of applying a patch).
|
|
|
|
|
|
|
|
my ($sha1, $file, $message) = @_;
|
|
|
|
|
|
|
|
my @undo; # undo stack for cleanup in case of an error
|
|
|
|
my $conflict; # file content with conflict markers
|
|
|
|
|
|
|
|
eval {
|
|
|
|
# Hide local changes from Git by renaming the modified file.
|
|
|
|
# Relative paths must be converted to absolute for renaming.
|
|
|
|
my ($target, $hidden) = (
|
|
|
|
"$config{srcdir}/${file}", "$config{srcdir}/${file}.${sha1}"
|
|
|
|
);
|
|
|
|
rename($target, $hidden)
|
|
|
|
or error("rename '$target' to '$hidden' failed: $!");
|
|
|
|
# Ensure to restore the renamed file on error.
|
|
|
|
push @undo, sub {
|
|
|
|
return if ! -e "$hidden"; # already renamed
|
|
|
|
rename($hidden, $target)
|
2006-06-03 20:03:41 +02:00
|
|
|
or warn "rename '$hidden' to '$target' failed: $!";
|
2006-06-02 07:32:20 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
my $branch = "throw_away_${sha1}"; # supposed to be unique
|
|
|
|
|
|
|
|
# Create a throw-away branch and rewind backward.
|
2007-10-31 22:37:33 +01:00
|
|
|
push @undo, sub { run_or_cry('git', 'branch', '-D', $branch) };
|
|
|
|
run_or_die('git', 'branch', $branch, $sha1);
|
2006-06-02 07:32:20 +02:00
|
|
|
|
|
|
|
# Switch to throw-away branch for the merge operation.
|
|
|
|
push @undo, sub {
|
2007-10-31 22:37:33 +01:00
|
|
|
if (!run_or_cry('git', 'checkout', $config{gitmaster_branch})) {
|
|
|
|
run_or_cry('git', 'checkout','-f',$config{gitmaster_branch});
|
2006-06-02 07:32:20 +02:00
|
|
|
}
|
|
|
|
};
|
2007-10-31 22:37:33 +01:00
|
|
|
run_or_die('git', 'checkout', $branch);
|
2006-06-02 07:32:20 +02:00
|
|
|
|
|
|
|
# Put the modified file in _this_ branch.
|
|
|
|
rename($hidden, $target)
|
|
|
|
or error("rename '$hidden' to '$target' failed: $!");
|
|
|
|
|
|
|
|
# _Silently_ commit all modifications in the current branch.
|
2007-10-31 22:37:33 +01:00
|
|
|
run_or_non('git', 'commit', '-m', $message, '-a');
|
2006-06-02 07:32:20 +02:00
|
|
|
# ... and re-switch to master.
|
2007-10-31 22:37:33 +01:00
|
|
|
run_or_die('git', 'checkout', $config{gitmaster_branch});
|
2006-06-02 07:32:20 +02:00
|
|
|
|
|
|
|
# Attempt to merge without complaining.
|
2007-10-31 22:37:33 +01:00
|
|
|
if (!run_or_non('git', 'pull', '--no-commit', '.', $branch)) {
|
2006-06-02 07:32:20 +02:00
|
|
|
$conflict = readfile($target);
|
2007-10-31 22:37:33 +01:00
|
|
|
run_or_die('git', 'reset', '--hard');
|
2006-06-02 07:32:20 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
my $failure = $@;
|
|
|
|
|
|
|
|
# Process undo stack (in reverse order). By policy cleanup
|
|
|
|
# actions should normally print a warning on failure.
|
|
|
|
while (my $handle = pop @undo) {
|
|
|
|
$handle->();
|
|
|
|
}
|
|
|
|
|
|
|
|
error("Git merge failed!\n$failure\n") if $failure;
|
|
|
|
|
|
|
|
return $conflict;
|
|
|
|
} #}}}
|
|
|
|
|
2007-08-30 04:32:35 +02:00
|
|
|
sub _parse_diff_tree ($@) { #{{{
|
2006-06-02 07:32:20 +02:00
|
|
|
# Parse the raw diff tree chunk and return the info hash.
|
|
|
|
# See git-diff-tree(1) for the syntax.
|
|
|
|
|
2007-08-30 04:32:35 +02:00
|
|
|
my ($prefix, $dt_ref) = @_;
|
2006-06-02 07:32:20 +02:00
|
|
|
|
|
|
|
# End of stream?
|
2006-11-26 21:05:57 +01:00
|
|
|
return if !defined @{ $dt_ref } ||
|
|
|
|
!defined @{ $dt_ref }[0] || !length @{ $dt_ref }[0];
|
2006-06-02 07:32:20 +02:00
|
|
|
|
|
|
|
my %ci;
|
|
|
|
# Header line.
|
2007-08-24 20:07:15 +02:00
|
|
|
while (my $line = shift @{ $dt_ref }) {
|
2006-06-19 05:33:23 +02:00
|
|
|
return if $line !~ m/^(.+) ($sha1_pattern)/;
|
2006-06-02 07:32:20 +02:00
|
|
|
|
2006-11-26 21:05:57 +01:00
|
|
|
my $sha1 = $2;
|
2006-06-02 07:32:20 +02:00
|
|
|
$ci{'sha1'} = $sha1;
|
2007-08-24 20:07:15 +02:00
|
|
|
last;
|
2006-06-02 07:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Identification lines for the commit.
|
2007-08-24 20:07:15 +02:00
|
|
|
while (my $line = shift @{ $dt_ref }) {
|
2006-06-02 07:32:20 +02:00
|
|
|
# Regexps are semi-stolen from gitweb.cgi.
|
2007-10-31 23:42:14 +01:00
|
|
|
if ($line =~ m/^tree ([0-9a-fA-F]{40})$/) {
|
2006-06-02 07:32:20 +02:00
|
|
|
$ci{'tree'} = $1;
|
2006-11-26 21:07:00 +01:00
|
|
|
}
|
|
|
|
elsif ($line =~ m/^parent ([0-9a-fA-F]{40})$/) {
|
2006-06-02 07:32:20 +02:00
|
|
|
# XXX: collecting in reverse order
|
|
|
|
push @{ $ci{'parents'} }, $1;
|
2006-11-26 21:07:00 +01:00
|
|
|
}
|
|
|
|
elsif ($line =~ m/^(author|committer) (.*) ([0-9]+) (.*)$/) {
|
2006-06-02 07:32:20 +02:00
|
|
|
my ($who, $name, $epoch, $tz) =
|
|
|
|
($1, $2, $3, $4 );
|
|
|
|
|
|
|
|
$ci{ $who } = $name;
|
|
|
|
$ci{ "${who}_epoch" } = $epoch;
|
|
|
|
$ci{ "${who}_tz" } = $tz;
|
|
|
|
|
2007-10-21 02:27:11 +02:00
|
|
|
if ($name =~ m/^([^<]+) <([^@>]+)/) {
|
2006-06-02 07:32:20 +02:00
|
|
|
my ($fullname, $username) = ($1, $2);
|
|
|
|
$ci{"${who}_fullname"} = $fullname;
|
|
|
|
$ci{"${who}_username"} = $username;
|
2006-11-26 21:07:00 +01:00
|
|
|
}
|
|
|
|
else {
|
2006-06-02 07:32:20 +02:00
|
|
|
$ci{"${who}_fullname"} =
|
|
|
|
$ci{"${who}_username"} = $name;
|
|
|
|
}
|
2006-11-26 21:07:00 +01:00
|
|
|
}
|
|
|
|
elsif ($line =~ m/^$/) {
|
2006-06-02 07:32:20 +02:00
|
|
|
# Trailing empty line signals next section.
|
2007-08-24 20:07:15 +02:00
|
|
|
last;
|
2006-06-02 07:32:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-11-12 18:53:46 +01:00
|
|
|
debug("No 'tree' seen in diff-tree output") if !defined $ci{'tree'};
|
2006-06-02 07:32:20 +02:00
|
|
|
|
2007-11-12 18:53:46 +01:00
|
|
|
if (defined $ci{'parents'}) {
|
|
|
|
$ci{'parent'} = @{ $ci{'parents'} }[0];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$ci{'parent'} = 0 x 40;
|
|
|
|
}
|
2006-06-02 07:32:20 +02:00
|
|
|
|
|
|
|
# Commit message.
|
2007-08-24 20:07:15 +02:00
|
|
|
while (my $line = shift @{ $dt_ref }) {
|
2006-06-02 07:32:20 +02:00
|
|
|
if ($line =~ m/^$/) {
|
|
|
|
# Trailing empty line signals next section.
|
2007-08-24 20:07:15 +02:00
|
|
|
last;
|
2006-06-02 07:32:20 +02:00
|
|
|
};
|
|
|
|
$line =~ s/^ //;
|
|
|
|
push @{ $ci{'comment'} }, $line;
|
|
|
|
}
|
|
|
|
|
|
|
|
# Modified files.
|
2007-08-24 20:07:15 +02:00
|
|
|
while (my $line = shift @{ $dt_ref }) {
|
2008-01-17 13:42:34 +01:00
|
|
|
if ($line =~ m{^
|
|
|
|
(:+) # number of parents
|
|
|
|
([^\t]+)\t # modes, sha1, status
|
|
|
|
(.*) # file names
|
2006-06-02 07:32:20 +02:00
|
|
|
$}xo) {
|
2008-01-17 13:42:34 +01:00
|
|
|
my $num_parents = length $1;
|
|
|
|
my @tmp = split(" ", $2);
|
|
|
|
my ($file, $file_to) = split("\t", $3);
|
|
|
|
my @mode_from = splice(@tmp, 0, $num_parents);
|
|
|
|
my $mode_to = shift(@tmp);
|
|
|
|
my @sha1_from = splice(@tmp, 0, $num_parents);
|
|
|
|
my $sha1_to = shift(@tmp);
|
|
|
|
my $status = shift(@tmp);
|
2006-06-02 07:32:20 +02:00
|
|
|
|
|
|
|
if ($file =~ m/^"(.*)"$/) {
|
|
|
|
($file=$1) =~ s/\\([0-7]{1,3})/chr(oct($1))/eg;
|
|
|
|
}
|
2007-08-30 04:32:35 +02:00
|
|
|
$file =~ s/^\Q$prefix\E//;
|
2006-06-02 07:32:20 +02:00
|
|
|
if (length $file) {
|
|
|
|
push @{ $ci{'details'} }, {
|
2006-07-05 22:54:10 +02:00
|
|
|
'file' => decode_utf8($file),
|
2008-01-17 13:42:34 +01:00
|
|
|
'sha1_from' => $sha1_from[0],
|
2006-06-02 07:32:20 +02:00
|
|
|
'sha1_to' => $sha1_to,
|
|
|
|
};
|
|
|
|
}
|
2007-08-24 20:07:15 +02:00
|
|
|
next;
|
2006-06-02 07:32:20 +02:00
|
|
|
};
|
2007-08-24 20:07:15 +02:00
|
|
|
last;
|
2006-06-02 07:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return \%ci;
|
|
|
|
} #}}}
|
|
|
|
|
2006-11-26 21:05:57 +01:00
|
|
|
sub git_commit_info ($;$) { #{{{
|
2006-06-02 07:32:20 +02:00
|
|
|
# Return an array of commit info hashes of num commits (default: 1)
|
2006-11-26 21:05:57 +01:00
|
|
|
# starting from the given sha1sum.
|
2006-06-02 07:32:20 +02:00
|
|
|
|
|
|
|
my ($sha1, $num) = @_;
|
|
|
|
|
|
|
|
$num ||= 1;
|
|
|
|
|
2007-10-31 22:37:33 +01:00
|
|
|
my @raw_lines = run_or_die('git', 'log', "--max-count=$num",
|
2007-10-31 23:32:22 +01:00
|
|
|
'--pretty=raw', '--raw', '--abbrev=40', '--always', '-c',
|
2007-10-22 00:59:18 +02:00
|
|
|
'-r', $sha1, '--', '.');
|
2007-10-31 22:37:33 +01:00
|
|
|
my ($prefix) = run_or_die('git', 'rev-parse', '--show-prefix');
|
2006-06-02 07:32:20 +02:00
|
|
|
|
|
|
|
my @ci;
|
2007-08-30 04:32:35 +02:00
|
|
|
while (my $parsed = _parse_diff_tree(($prefix or ""), \@raw_lines)) {
|
2006-06-02 07:32:20 +02:00
|
|
|
push @ci, $parsed;
|
|
|
|
}
|
|
|
|
|
2006-06-19 05:33:23 +02:00
|
|
|
warn "Cannot parse commit info for '$sha1' commit" if !@ci;
|
|
|
|
|
2006-06-02 07:32:20 +02:00
|
|
|
return wantarray ? @ci : $ci[0];
|
|
|
|
} #}}}
|
|
|
|
|
|
|
|
sub git_sha1 (;$) { #{{{
|
|
|
|
# Return head sha1sum (of given file).
|
|
|
|
|
|
|
|
my $file = shift || q{--};
|
|
|
|
|
2006-06-03 20:03:41 +02:00
|
|
|
# Ignore error since a non-existing file might be given.
|
2008-05-02 19:03:42 +02:00
|
|
|
my ($sha1) = run_or_non('git', 'rev-list', '--max-count=1', 'HEAD',
|
|
|
|
'--', $file);
|
2006-06-03 20:03:41 +02:00
|
|
|
if ($sha1) {
|
|
|
|
($sha1) = $sha1 =~ m/($sha1_pattern)/; # sha1 is untainted now
|
|
|
|
} else { debug("Empty sha1sum for '$file'.") }
|
|
|
|
return defined $sha1 ? $sha1 : q{};
|
2006-06-02 07:32:20 +02:00
|
|
|
} #}}}
|
|
|
|
|
|
|
|
sub rcs_update () { #{{{
|
|
|
|
# Update working directory.
|
|
|
|
|
2007-10-22 03:47:30 +02:00
|
|
|
if (length $config{gitorigin_branch}) {
|
2007-10-31 22:37:33 +01:00
|
|
|
run_or_cry('git', 'pull', $config{gitorigin_branch});
|
2007-10-22 03:47:30 +02:00
|
|
|
}
|
2006-06-02 07:32:20 +02:00
|
|
|
} #}}}
|
|
|
|
|
|
|
|
sub rcs_prepedit ($) { #{{{
|
|
|
|
# Return the commit sha1sum of the file when editing begins.
|
|
|
|
# This will be later used in rcs_commit if a merge is required.
|
|
|
|
|
|
|
|
my ($file) = @_;
|
|
|
|
|
2006-06-03 20:03:41 +02:00
|
|
|
return git_sha1($file);
|
2006-06-02 07:32:20 +02:00
|
|
|
} #}}}
|
|
|
|
|
2006-11-22 15:28:38 +01:00
|
|
|
sub rcs_commit ($$$;$$) { #{{{
|
2006-06-02 07:32:20 +02:00
|
|
|
# Try to commit the page; returns undef on _success_ and
|
|
|
|
# a version of the page with the rcs's conflict markers on
|
|
|
|
# failure.
|
|
|
|
|
2006-11-22 15:28:38 +01:00
|
|
|
my ($file, $message, $rcstoken, $user, $ipaddr) = @_;
|
|
|
|
|
|
|
|
if (defined $user) {
|
2006-11-26 21:07:00 +01:00
|
|
|
$message = "web commit by $user" .
|
|
|
|
(length $message ? ": $message" : "");
|
2006-11-22 15:28:38 +01:00
|
|
|
}
|
|
|
|
elsif (defined $ipaddr) {
|
2006-11-26 21:07:00 +01:00
|
|
|
$message = "web commit from $ipaddr" .
|
|
|
|
(length $message ? ": $message" : "");
|
2006-11-22 15:28:38 +01:00
|
|
|
}
|
2006-06-02 07:32:20 +02:00
|
|
|
|
|
|
|
# Check to see if the page has been changed by someone else since
|
|
|
|
# rcs_prepedit was called.
|
|
|
|
my $cur = git_sha1($file);
|
2006-06-03 20:03:41 +02:00
|
|
|
my ($prev) = $rcstoken =~ /^($sha1_pattern)$/; # untaint
|
2006-06-02 07:32:20 +02:00
|
|
|
|
|
|
|
if (defined $cur && defined $prev && $cur ne $prev) {
|
|
|
|
my $conflict = _merge_past($prev, $file, $dummy_commit_msg);
|
|
|
|
return $conflict if defined $conflict;
|
|
|
|
}
|
|
|
|
|
2007-10-31 22:37:33 +01:00
|
|
|
# git commit returns non-zero if file has not been really changed.
|
2006-06-02 07:32:20 +02:00
|
|
|
# so we should ignore its exit status (hence run_or_non).
|
2006-06-03 20:03:41 +02:00
|
|
|
$message = possibly_foolish_untaint($message);
|
2007-10-31 22:37:33 +01:00
|
|
|
if (run_or_non('git', 'commit', '-q', '-m', $message, '-i', $file)) {
|
2007-10-22 03:47:30 +02:00
|
|
|
if (length $config{gitorigin_branch}) {
|
2007-10-31 22:37:33 +01:00
|
|
|
run_or_cry('git', 'push', $config{gitorigin_branch});
|
2007-10-22 03:47:30 +02:00
|
|
|
}
|
2006-06-02 07:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return undef; # success
|
|
|
|
} #}}}
|
|
|
|
|
|
|
|
sub rcs_add ($) { # {{{
|
|
|
|
# Add file to archive.
|
|
|
|
|
|
|
|
my ($file) = @_;
|
|
|
|
|
2007-10-31 22:37:33 +01:00
|
|
|
run_or_cry('git', 'add', $file);
|
2006-06-02 07:32:20 +02:00
|
|
|
} #}}}
|
|
|
|
|
|
|
|
sub rcs_recentchanges ($) { #{{{
|
|
|
|
# List of recent changes.
|
|
|
|
|
|
|
|
my ($num) = @_;
|
|
|
|
|
|
|
|
eval q{use Date::Parse};
|
2006-11-08 22:03:33 +01:00
|
|
|
error($@) if $@;
|
2006-06-02 07:32:20 +02:00
|
|
|
|
2006-11-26 21:05:57 +01:00
|
|
|
my @rets;
|
2007-08-24 20:07:15 +02:00
|
|
|
foreach my $ci (git_commit_info('HEAD', $num)) {
|
2006-06-02 07:32:20 +02:00
|
|
|
# Skip redundant commits.
|
2007-12-16 22:52:39 +01:00
|
|
|
next if (@{$ci->{'comment'}}[0] eq $dummy_commit_msg);
|
2006-06-02 07:32:20 +02:00
|
|
|
|
2006-11-26 21:05:57 +01:00
|
|
|
my ($sha1, $when) = (
|
|
|
|
$ci->{'sha1'},
|
2008-01-29 04:57:22 +01:00
|
|
|
$ci->{'author_epoch'}
|
2006-11-26 21:05:57 +01:00
|
|
|
);
|
2006-06-02 07:32:20 +02:00
|
|
|
|
2006-11-26 21:05:57 +01:00
|
|
|
my (@pages, @messages);
|
2007-08-24 20:07:15 +02:00
|
|
|
foreach my $detail (@{ $ci->{'details'} }) {
|
2007-10-22 00:59:18 +02:00
|
|
|
my $file = $detail->{'file'};
|
2006-06-02 07:32:20 +02:00
|
|
|
|
2007-10-22 00:59:18 +02:00
|
|
|
my $diffurl = $config{'diffurl'};
|
2006-06-02 07:32:20 +02:00
|
|
|
$diffurl =~ s/\[\[file\]\]/$file/go;
|
|
|
|
$diffurl =~ s/\[\[sha1_parent\]\]/$ci->{'parent'}/go;
|
2006-10-14 05:10:33 +02:00
|
|
|
$diffurl =~ s/\[\[sha1_from\]\]/$detail->{'sha1_from'}/go;
|
|
|
|
$diffurl =~ s/\[\[sha1_to\]\]/$detail->{'sha1_to'}/go;
|
2006-06-02 07:32:20 +02:00
|
|
|
|
|
|
|
push @pages, {
|
2006-09-03 21:53:23 +02:00
|
|
|
page => pagename($file),
|
2006-06-02 07:32:20 +02:00
|
|
|
diffurl => $diffurl,
|
2006-10-14 05:10:33 +02:00
|
|
|
};
|
2006-06-02 07:32:20 +02:00
|
|
|
}
|
2008-05-16 00:03:44 +02:00
|
|
|
|
|
|
|
push @messages, { line => $_ } foreach grep {
|
|
|
|
! m/^ *(signed[ \-]off[ \-]by[ :]|acked[ \-]by[ :]|cc[ :])/i
|
|
|
|
} @{$ci->{'comment'}};
|
2006-06-02 07:32:20 +02:00
|
|
|
|
2006-11-26 21:05:57 +01:00
|
|
|
my ($user, $type) = (q{}, "web");
|
2006-06-02 07:32:20 +02:00
|
|
|
|
2006-11-26 21:05:57 +01:00
|
|
|
if (defined $messages[0] &&
|
|
|
|
$messages[0]->{line} =~ m/$config{web_commit_regexp}/) {
|
2006-11-26 21:07:00 +01:00
|
|
|
$user = defined $2 ? "$2" : "$3";
|
|
|
|
$messages[0]->{line} = $4;
|
|
|
|
}
|
|
|
|
else {
|
2006-06-02 07:32:20 +02:00
|
|
|
$type ="git";
|
|
|
|
$user = $ci->{'author_username'};
|
|
|
|
}
|
|
|
|
|
|
|
|
push @rets, {
|
2008-01-29 03:23:56 +01:00
|
|
|
rev => $sha1,
|
2006-09-03 21:53:23 +02:00
|
|
|
user => $user,
|
2006-06-02 07:32:20 +02:00
|
|
|
committype => $type,
|
|
|
|
when => $when,
|
2006-11-26 21:05:57 +01:00
|
|
|
message => [@messages],
|
2006-06-02 07:32:20 +02:00
|
|
|
pages => [@pages],
|
2007-10-31 23:32:22 +01:00
|
|
|
} if @pages;
|
2006-06-02 07:32:20 +02:00
|
|
|
|
2007-08-24 20:07:15 +02:00
|
|
|
last if @rets >= $num;
|
2006-06-02 07:32:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return @rets;
|
|
|
|
} #}}}
|
|
|
|
|
2008-03-03 21:53:34 +01:00
|
|
|
sub rcs_diff ($) { #{{{
|
|
|
|
my $rev=shift;
|
|
|
|
my ($sha1) = $rev =~ /^($sha1_pattern)$/; # untaint
|
2008-03-12 20:45:10 +01:00
|
|
|
my @lines;
|
2008-03-12 19:44:20 +01:00
|
|
|
foreach my $line (run_or_non("git", "show", $sha1)) {
|
2008-03-12 20:45:10 +01:00
|
|
|
if (@lines || $line=~/^diff --git/) {
|
|
|
|
push @lines, $line."\n";
|
2008-03-12 19:44:20 +01:00
|
|
|
}
|
|
|
|
}
|
2008-03-12 20:45:10 +01:00
|
|
|
if (wantarray) {
|
|
|
|
return @lines;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return join("", @lines);
|
|
|
|
}
|
2008-03-03 21:53:34 +01:00
|
|
|
} #}}}
|
|
|
|
|
2006-06-02 07:32:20 +02:00
|
|
|
sub rcs_getctime ($) { #{{{
|
2007-10-10 20:15:15 +02:00
|
|
|
my $file=shift;
|
|
|
|
# Remove srcdir prefix
|
|
|
|
$file =~ s/^\Q$config{srcdir}\E\/?//;
|
2006-06-02 07:32:20 +02:00
|
|
|
|
|
|
|
my $sha1 = git_sha1($file);
|
|
|
|
my $ci = git_commit_info($sha1);
|
|
|
|
my $ctime = $ci->{'author_epoch'};
|
2007-10-04 11:00:08 +02:00
|
|
|
debug("ctime for '$file': ". localtime($ctime));
|
2006-06-02 07:32:20 +02:00
|
|
|
|
|
|
|
return $ctime;
|
|
|
|
} #}}}
|
|
|
|
|
|
|
|
1
|