File: gime-json-commits.sh

package info (click to toggle)
libreswan 5.2-2.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 81,632 kB
  • sloc: ansic: 129,988; sh: 32,018; xml: 20,646; python: 10,303; makefile: 3,022; javascript: 1,506; sed: 574; yacc: 511; perl: 264; awk: 52
file content (73 lines) | stat: -rwxr-xr-x 1,978 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash


if test $# -lt 1; then
  cat >> /dev/stderr <<EOF

Usage:

    $0 <summarydir> [ <rutdir> [ <earliest_commit> ] ]

Iterate through [<earliest_commit>..HEAD] dumping minimal JSON on
each.
EOF
  exit 1
fi

bindir=$(cd $(dirname $0) && pwd)
summarydir=$(realpath $1) ; shift
rutdir=$(realpath $1) ; shift
earliest_commit=$1 ; shift

# HEAD may not be latest commit; figure out what it is
branch=$(${bindir}/gime-git-branch.sh ${rutdir}) # main master ...
remote=$(git -C ${rutdir} config --get branch.${branch}.remote) # origin/ libreswan/ ...
latest_commit=${remote}/${branch}


rank=0

{
    # start at latest; stop at one commit previous to commit after
    # earliest_commit, i.e., earliest_commit
    #
    # Dump both the author's and the committer's dates; the author's
    # date is used when showing the commit and the committer's date is
    # used when working out where to plot the commit on the progress
    # graph.  When an old commit is cherry-picked or merged, the two
    # can differ wildly.
    #
    # Also include the rank numbered in descending order.
    git -C ${rutdir} log \
	--format='%H,%h,%(decorate:prefix=,suffix=,separator= ,pointer=>,tag=tag:),%P,%aI,%cI,%s' \
	${latest_commit} ^${earliest_commit}^
} | {
    while IFS=, read hash abbrev_hash tags parents author_date committer_date subject ; do
	printf '{'
	printf ' '
	printf '"hash": "%s"' "${hash}"
	printf ', '
	printf '"abbrev_hash": "%s"' "${abbrev_hash}"
	printf ', '
	printf '"author_date": "%s"' "${author_date}"
	printf ', '
	printf '"committer_date": "%s"' "${committer_date}"
	printf ', '
	printf '"tags": "%s"' "${tags}"
	printf ', '
	printf '"rank": %d' "${rank}" # yes, integer!
	printf ', '
	printf '"parents": ['
	fs=' '
	for parent in ${parents} ; do
	    printf '%s"%s"' "${fs}" "${parent}"
	    fs=', '
	done
	printf ' ]'
	printf ', '
	printf ' "subject": "%s"' "$(echo ${subject} | sed -e 's;";\\";g')"
	printf ' '
	printf '}\n'
	rank=$((rank + 1))
    done
}