Skip to content

Commit 7b78b80

Browse files
authored
Merge pull request #437 from timsong-cpp/fast-dates
A faster way to get modification dates
2 parents ebd1ae8 + b5111d5 commit 7b78b80

File tree

2 files changed

+57
-15
lines changed

2 files changed

+57
-15
lines changed

Makefile

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,33 +114,37 @@ meta-data/section.data: meta-data/annex-f meta-data/networking-section.data bin/
114114

115115
dates: meta-data/dates
116116

117+
optcmd = $(shell command -v $(1) || echo :)
118+
117119
# Generate file with issue number and unix timestamp of last change.
118-
meta-data/dates: xml/issue[0-9]*.xml
120+
python := $(call optcmd,python)
121+
meta-data/dates: xml/issue[0-9]*.xml bin/make_dates.py
119122
@echo "Refreshing 'Last modified' timestamps for issues..."
120-
@for i in xml/issue[0-9]*.xml ; do \
121-
n="$${i#xml/issue}" ; n="$${n%.xml}" ; \
122-
grep -s -q "^$$n " $@ && test $$i -ot $@ && continue ; \
123-
echo $$i >&2 ; \
124-
git log -1 --pretty="format:$$n %ct%n" $$i ; \
125-
done > $@.new
126-
@cat $@ $@.new | sort -n -r | sort -n -k 1 -u > $@.tmp
127-
@rm $@.new
128-
@$(call update,$@)
129-
123+
@if [ "$(python)" = ":" ]; then \
124+
for i in xml/issue[0-9]*.xml ; do \
125+
n="$${i#xml/issue}" ; n="$${n%.xml}" ; \
126+
grep -s -q "^$$n " $@ && test $$i -ot $@ && continue ; \
127+
echo $$i >&2 ; \
128+
git log -1 --pretty="format:$$n %ct%n" $$i ; \
129+
done > $@.new; \
130+
cat $@ $@.new | sort -n -r | sort -n -k 1 -u > $@.tmp; \
131+
rm $@.new; \
132+
$(call update,$@); \
133+
else \
134+
git whatchanged --no-show-signature --pretty=%ct | $(python) bin/make_dates.py > $@; \
135+
fi
130136

131137
new-papers:
132138
rm -f meta-data/index.json meta-data/paper_titles.txt
133139
$(MAKE) meta-data/paper_titles.txt
134140

135-
optcmd = $(shell command -v $(1) || echo :)
136-
137-
# If python is not installed then create an empty meta-data/paper_titles.txt
141+
# If curl is not installed then create an empty meta-data/paper_titles.txt
138142
meta-data/index.json:
139143
$(call optcmd,curl) https://wg21.link/index.json > $@
140144

141145
# If python is not installed then create an empty meta-data/paper_titles.txt
142146
meta-data/paper_titles.txt: | meta-data/index.json
143-
$(call optcmd,python) bin/make_paper_titles.py $| > $@
147+
$(python) bin/make_paper_titles.py $| > $@
144148

145149
.PRECIOUS: meta-data/dates
146150
.PRECIOUS: meta-data/paper_titles.txt

bin/make_dates.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/python
2+
3+
# usage: git whatchanged --no-show-signature --pretty=%ct | python bin/make_dates.py > dates
4+
5+
import sys
6+
import re
7+
8+
# The input looks like
9+
# 1728481670
10+
#
11+
# :100644 100644 02412851ac 9f5998ba82 M xml/issue4159.xml
12+
# :100644 100644 fa2274aa17 74485b30c1 M xml/issue4162.xml
13+
# :100644 100644 8023699cb9 d007f71c08 M xml/issue4164.xml
14+
15+
mtimes = {}
16+
current_mtime = ''
17+
for l in sys.stdin.readlines():
18+
l = l.rstrip()
19+
if not l:
20+
# blank line
21+
continue
22+
23+
# timestamp
24+
if l[0] != ':':
25+
current_mtime = l
26+
continue
27+
28+
# last piece of line is the file name
29+
file = l.split()[-1]
30+
m = re.match('xml/issue(\\d+).xml', file)
31+
32+
if m:
33+
num = int(m[1])
34+
if num not in mtimes:
35+
mtimes[num] = current_mtime
36+
37+
for (num, time) in sorted(list(mtimes.items())):
38+
print(f'{num:04} {time}')

0 commit comments

Comments
 (0)