DrTrigon has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/77555


Change subject: introduce keyword expansion (like svn:keywords) hooks (from 
compat)
......................................................................

introduce keyword expansion (like svn:keywords) hooks (from compat)

Change-Id: Ie063da01e238f02a863a114b07c4410bf3cb85d6
---
M .gitattributes
M pywikibot/__init__.py
A rcs-keywords
3 files changed, 34 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/55/77555/1

diff --git a/.gitattributes b/.gitattributes
index 274c91d..f7ec4e8 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1 +1,2 @@
 *.py ident
+*.py filter=rcs-keywords
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 73947ec..a602c9b 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -8,6 +8,7 @@
 # Distributed under the terms of the MIT license.
 #
 __version__ = '$Id$'
+__ver_git__ = '$pwbId$'
 
 import datetime
 import difflib
diff --git a/rcs-keywords b/rcs-keywords
new file mode 100755
index 0000000..a08531c
--- /dev/null
+++ b/rcs-keywords
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+""" Simple python script keyword expansion (like svn:keywords) in python files:
+* expands $pwbId$ keyword on checkout
+* (more keywords named like $pwbSomeKeyword$ or $pwb-some-keyword$ can be
+  added easily)
+"""
+#
+# (C) 2013 DrTrigon
+# (C) Pywikipedia bot team, 2013
+#
+# Distributed under the terms of the MIT license.
+#
+
+import sys, re, subprocess
+
+INPUT = sys.stdin.read()[:-1]
+
+if '--clean' in sys.argv:
+    print re.sub('(\$pwb[-\w]+)([^\n\r\$]*)\$', '\g<1>$', INPUT)
+else:
+    # executing 2 'git' shell commands PER file is VERY SLOW:
+    rev  = subprocess.Popen('git rev-list HEAD | wc -l',
+                            shell=True,
+                            stdout=subprocess.PIPE).stdout.read().strip()
+    info = subprocess.Popen("git log --pretty=format:'%ad %an %h%d'"
+                            " --abbrev-commit --date=iso -1 | cat -",
+                            shell=True,
+                            stdout=subprocess.PIPE).stdout.read().strip()
+
+    # $pwbId$
+    print re.sub('(\$pwbId)([^\n\r\$]*)\$', '\g<1>: %s %s %s $' %\
+                     ('(filename n/a)', rev, info), INPUT)

-- 
To view, visit https://gerrit.wikimedia.org/r/77555
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie063da01e238f02a863a114b07c4410bf3cb85d6
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: DrTrigon <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to