Generate a log file from Perforce to use with Gourse

757 Views Asked by At

I am trying to generate a perforce log file using awk, which can then in turn be used with Gource.

Gource allows you to generate an animation of a file/project revision history.

I tried following the examples here but they will not work for my depot (although they work for the adobe one!)

I also tried the script on the page here which says,

p4 changes //depot/path_to_files/|awk '{print $2}'|p4 -x - describe -s|awk '(/^Change / || /^... /) {if ($1 == "Change") {u=substr($4,1,index($4,"@")-1); t = $(NF-1) " " $NF; gsub("/"," ",t); gsub(":"," ",t);mktime(t);} else {if ($NF=="add") {c="A";} else if ($NF=="delete") {c="D";} else {c="M";};f=substr($2,3,index($2,"#")-3);print time "|" u "|" c "|" f;}}'|sort -n

but I get an

"awk: line 0(NR=1): variable "mktime" cannot be used as a function"

error.

If anybody has an idea what's going wrong I'd like to hear from you !

2

There are 2 best solutions below

2
On

mktime is a GNU Awk extensions:

In order to make it easier to process such log files and to produce useful reports, gawk provides the following functions for working with timestamps. They are gawk extensions; they are not specified in the POSIX standard, nor are they in any other known version of awk

https://www.gnu.org/software/gawk/manual/html_node/Time-Functions.html

Just replace awk with gawk if it is available on your system:

p4 changes //depot/path_to_files/             \
  | awk '{print $2}'                          \
  | p4 -x - describe -s                       \
  | gawk '(/^Change / || /^... /) {           \
      if ($1 == "Change") {                   \
          u=substr($4,1,index($4,"@")-1);     \
          t = $(NF-1) " " $NF;                \
          gsub("/"," ",t);                    \
          gsub(":"," ",t);                    \
          time = mktime(t);                   \
      } else {                                \
          if ($NF=="add") {                   \
            c="A";                            \
          } else if ($NF=="delete") {         \
            c="D";                            \
          } else {                            \
            c="M";                            \
          };                                  \
          f=substr($2, 3, index($2,"#")-3);   \
          print time "|" u "|" c "|" f;       \
      }                                       \
  }'                                          \
  | sort -n
0
On

I've made a python script to convert Perforce's history to a Gource-compatible log file. It also can fetch the latest changes and append them since the last sync.

Perforce to Gource Python script