summaryrefslogtreecommitdiff
path: root/macro.py
diff options
context:
space:
mode:
authorPeter Simons <simons@cryp.to>2011-01-06 21:53:19 +0100
committerPeter Simons <simons@cryp.to>2011-01-06 21:59:31 +0100
commit76ca2be8f29d1814fa698a68cae35d905ce63020 (patch)
tree17cdc194f35242e887b0112977854e9a17b059e6 /macro.py
parent7bc90c7f30048d79f60587a1f831a465f56e8049 (diff)
downloadautoconf-archive-76ca2be8f29d1814fa698a68cae35d905ce63020.tar.gz
Merge functionality of 'set-serial.sh' into the 'maintainer-all' target.
Running 'maintainer-all' will now automatically ensure that the #serial number of every macro corresponds to the number of commits that have modified that macro in the Git repository.
Diffstat (limited to 'macro.py')
-rwxr-xr-xmacro.py28
1 files changed, 21 insertions, 7 deletions
diff --git a/macro.py b/macro.py
index 36dabc8..91b2dfa 100755
--- a/macro.py
+++ b/macro.py
@@ -1,11 +1,7 @@
#! /usr/bin/env python
-
from contextlib import closing
-import re
-import os.path as path
-import sys
-import textwrap
+import os, sys, subprocess, re, textwrap
def loadFile(path):
with closing( open(path) ) as fd:
@@ -60,8 +56,8 @@ def collapseText(lines, width = 72):
return body
class Macro:
- def __init__(self, filePath):
- self.name = path.splitext(path.basename(filePath))[0]
+ def __init__(self, filePath, computeSerialNumber=False):
+ self.name = os.path.splitext(os.path.basename(filePath))[0]
# header and body are separated by an empty line.
(header,body) = loadFile(filePath).split("\n\n", 1)
self.body = body.split('\n')
@@ -110,6 +106,24 @@ class Macro:
else:
raise Exception("%s: unknown section %r in macro" % (filePath, key))
self.__dict__[key] = body
+ # determine the macro's serial number
+ if computeSerialNumber: # compute the number from git
+ logMessages = subprocess.check_output(["git", "log", "--oneline", "--", filePath], bufsize=1)
+ logLines = logMessages.rstrip(b'\n').split(b"\n")
+ self.serial = len(logLines)
+ modified = subprocess.call(["git", "diff", "--quiet", "--exit-code", "HEAD", "--", filePath])
+ if modified:
+ self.serial += 1
+ else: # trust the m4 file
+ assert self.body[0].startswith("#serial")
+ self.serial = int(self.body[0].split()[1])
+ # drop the original serial number from the body
+ self.body = [ l for l in self.body if not l.startswith("#serial") ]
+ # drop whitespace from begining and end of body
+ while self.body[0] == "":
+ self.body.pop(0)
+ while self.body[-1] == "":
+ self.body.pop(-1)
def __repr__(self):
return repr(self.__dict__)