3 # Extract information about recent git commits
5 # tridge@samba.org, November 2006
16 ####################################
17 # push an entry onto the array
25 unshift(@{$log}, $entry);
26 # printf("Adding entry\n");
27 # print Dumper $entry;
31 ####################################
32 # return an array of logfile entries given a git log file.
33 # Only return entries newer than $days old
44 $subdir = "" unless defined($subdir);
46 my $magicstart = "---GIT-COMMIT-MAGIC-START---";
47 my $magicmsg = "---GIT-COMMIT-MAGIC-MESSAGE---";
48 my $magicdiff = "---GIT-COMMIT-MAGIC-DIFF---";
49 my $magicbody = "---GIT-COMMIT-MAGIC-BODY---";
50 my $format = $magicstart."%n%H%n%ct%n%an%n".$magicmsg."%n%s%n".$magicbody."%b%n".$magicdiff;
52 $sincedays = "--since='$days days'" if defined($days);
53 # the number of entries is also being limited to a maximum number
54 # in the "git log" command. This is required because we
55 # checked in 11 years of samba development 1 days ago :-)
57 # git log --pretty=format:---GIT-COMMIT-MAGIC-START---%n%H%n%ct%n%an%n---GIT-COMMIT-MAGIC-MESSAGE---%n%s%b%n---GIT-COMMIT-MAGIC-DIFF--- --numstat --since='1 days'
58 open(FILE, "cd $git_path; git log --pretty=format:$format --numstat $sincedays -500 $tree -- $subdir |");
60 while (defined (my $line = <FILE>)) {
61 # printf("line=$line");
62 # separator line indicates new entry
63 if ($line =~ /^$magicstart$/ ) {
64 # only add entry if one exists
66 $log = push_entry($entry, $log, $days, $tree);
75 if ($line_count == 1) {
77 $entry->{REVISION} = $line;
79 } elsif ($line_count == 2) {
81 $entry->{DATE} = $line;
83 } elsif ($line_count == 3) {
85 $entry->{AUTHOR} = $line;
89 if ($line =~ /^$magicmsg$/) {
94 if ($line =~ /^$magicdiff$/) {
95 $addto = "DIFF_STUFF";
100 if ($addto eq "MESSAGE") {
101 if ($line =~ /^$magicbody(<unknown>$)?(.*)$/) {
104 $entry->{MESSAGE} .= $line."\n";
108 if ($addto eq "DIFF_STUFF") {
109 $line =~ m/^([0-9]*)[ \t]*([0-9]*)[ \t]*(.*)/;
113 $f =~ s/^$subdir\///;
114 if (($b eq "0") and ($a ne "0")) {
115 $entry->{ADDED} .= "$f ";
116 } elsif (($a eq "0") and ($b ne "0")) {
117 $entry->{REMOVED} .= "$f ";
119 $entry->{FILES} .= "$f ";
124 # the last log entry should be caught here:
125 if ($entry->{DATE}) {
126 $log = push_entry($entry, $log, $days, $tree);
131 # cleanup the messages
132 # for (my $line = $#{$log}; $line > 0; $line--) {
133 # $entry = $log->[$line];
134 # if ($entry->{MESSAGE}) {
135 # while (chomp($entry->{MESSAGE})) { }
143 ######################################
145 if ($#ARGV < 2 || $ARGV[0] eq '--help' || $ARGV[0] eq '-h') {
147 Usage: gitlog.pl <PATH> <DAYS> <DEST> [<subdir>]
149 Extract all commits git tree <PATH> in the last DAYS days. Store the
150 results in DEST in a format easily readable by the build farm web
151 scripts. "; exit(1); }
153 my $git_path_arg = $ARGV[0];
154 my $days_arg = $ARGV[1];
155 my $tree_arg = $ARGV[2];
156 my $dest_arg = $ARGV[3];
157 my $subdir_arg = $ARGV[4];
159 my $log_data = git_parse($git_path_arg, $days_arg, $tree_arg, $subdir_arg);
161 util::SaveStructure($dest_arg, $log_data);