From 93236c0455ded01f1af5d28f8be0801120a18ff2 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Wed, 2 Dec 2015 14:28:35 +0100 Subject: qt: Final translation update before 0.12 fork - Add new translations (finally, after a long time) - update-translation script was not considering new translations - oops - fixed this, also remove (nearly) empty translations - Update translation process, it was still describing the old repository structure --- contrib/devtools/update-translations.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'contrib/devtools') diff --git a/contrib/devtools/update-translations.py b/contrib/devtools/update-translations.py index f955e4a1f2..ea209eec7e 100755 --- a/contrib/devtools/update-translations.py +++ b/contrib/devtools/update-translations.py @@ -29,6 +29,8 @@ TX = 'tx' SOURCE_LANG = 'bitcoin_en.ts' # Directory with locale files LOCALE_DIR = 'src/qt/locale' +# Minimum number of messages for translation to be considered at all +MIN_NUM_MESSAGES = 10 def check_at_repository_root(): if not os.path.exists('.git'): @@ -37,7 +39,7 @@ def check_at_repository_root(): exit(1) def fetch_all_translations(): - if subprocess.call([TX, 'pull', '-f']): + if subprocess.call([TX, 'pull', '-f', '-a']): print('Error while fetching translations', file=sys.stderr) exit(1) @@ -166,6 +168,15 @@ def postprocess_translations(reduce_diff_hacks=False): if translation_node.get('type') == 'unfinished': context.remove(message) + # check if document is (virtually) empty, and remove it if so + num_messages = 0 + for context in root.findall('context'): + for message in context.findall('message'): + num_messages += 1 + if num_messages < MIN_NUM_MESSAGES: + print('Removing %s, as it contains only %i messages' % (filepath, num_messages)) + continue + # write fixed-up tree # if diff reduction requested, replace some XML to 'sanitize' to qt formatting if reduce_diff_hacks: -- cgit v1.2.3 From fad246037f85067275a7bbfa12371744b5fc679d Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Wed, 2 Dec 2015 14:41:07 +0100 Subject: Update contrib/devtools/README.md * Fix order * Update subtree check --- contrib/devtools/README.md | 61 +++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 30 deletions(-) (limited to 'contrib/devtools') diff --git a/contrib/devtools/README.md b/contrib/devtools/README.md index 2e70c5adcc..a58b8733a6 100644 --- a/contrib/devtools/README.md +++ b/contrib/devtools/README.md @@ -7,6 +7,37 @@ clang-format.py A script to format cpp source code according to [.clang-format](../../src/.clang-format). This should only be applied to new files or files which are currently not actively developed on. Also, git subtrees are not subject to formatting. +fix-copyright-headers.py +======================== + +Every year newly updated files need to have its copyright headers updated to reflect the current year. +If you run this script from src/ it will automatically update the year on the copyright header for all +.cpp and .h files if these have a git commit from the current year. + +For example a file changed in 2014 (with 2014 being the current year): + +```// Copyright (c) 2009-2013 The Bitcoin Core developers``` + +would be changed to: + +```// Copyright (c) 2009-2014 The Bitcoin Core developers``` + +git-subtree-check.sh +==================== + +Run this script from the root of the repository to verify that a subtree matches the contents of +the commit it claims to have been updated to. + +To use, make sure that you have fetched the upstream repository branch in which the subtree is +maintained: +* for `src/secp256k1`: https://github.com/bitcoin/secp256k1.git (branch master) +* for `src/leveldb`: https://github.com/bitcoin/leveldb.git (branch bitcoin-fork) +* for `src/univalue`: https://github.com/bitcoin/univalue.git (branch master) + +Usage: `git-subtree-check.sh DIR COMMIT` + +`COMMIT` may be omitted, in which case `HEAD` is used. + github-merge.sh =============== @@ -41,21 +72,6 @@ Configuring the github-merge tool for the bitcoin repository is done in the foll git config githubmerge.testcmd "make -j4 check" (adapt to whatever you want to use for testing) git config --global user.signingkey mykeyid (if you want to GPG sign) -fix-copyright-headers.py -======================== - -Every year newly updated files need to have its copyright headers updated to reflect the current year. -If you run this script from src/ it will automatically update the year on the copyright header for all -.cpp and .h files if these have a git commit from the current year. - -For example a file changed in 2014 (with 2014 being the current year): - -```// Copyright (c) 2009-2013 The Bitcoin Core developers``` - -would be changed to: - -```// Copyright (c) 2009-2014 The Bitcoin Core developers``` - optimize-pngs.py ================ @@ -98,18 +114,3 @@ It will do the following automatically: - add missing translations to the build system (TODO) See doc/translation-process.md for more information. - -git-subtree-check.sh -==================== - -Run this script from the root of the repository to verify that a subtree matches the contents of -the commit it claims to have been updated to. - -To use, make sure that you have fetched the upstream repository branch in which the subtree is -maintained: -* for src/secp256k1: https://github.com/bitcoin/secp256k1.git (branch master) -* for sec/leveldb: https://github.com/bitcoin/leveldb.git (branch bitcoin-fork) - -Usage: git-subtree-check.sh DIR COMMIT - -COMMIT may be omitted, in which case HEAD is used. -- cgit v1.2.3 From fa6ad855e9159b2247da4fa0054f32fa181499ab Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Sun, 13 Dec 2015 14:51:43 +0100 Subject: [devtools] Rewrite fix-copyright-headers.py --- contrib/devtools/README.md | 8 ++-- contrib/devtools/fix-copyright-headers.py | 69 ++++++++++++++----------------- 2 files changed, 35 insertions(+), 42 deletions(-) (limited to 'contrib/devtools') diff --git a/contrib/devtools/README.md b/contrib/devtools/README.md index a58b8733a6..240ab6d9e0 100644 --- a/contrib/devtools/README.md +++ b/contrib/devtools/README.md @@ -11,16 +11,16 @@ fix-copyright-headers.py ======================== Every year newly updated files need to have its copyright headers updated to reflect the current year. -If you run this script from src/ it will automatically update the year on the copyright header for all -.cpp and .h files if these have a git commit from the current year. +If you run this script from the root folder it will automatically update the year on the copyright header for all +source files if these have a git commit from the current year. -For example a file changed in 2014 (with 2014 being the current year): +For example a file changed in 2015 (with 2015 being the current year): ```// Copyright (c) 2009-2013 The Bitcoin Core developers``` would be changed to: -```// Copyright (c) 2009-2014 The Bitcoin Core developers``` +```// Copyright (c) 2009-2015 The Bitcoin Core developers``` git-subtree-check.sh ==================== diff --git a/contrib/devtools/fix-copyright-headers.py b/contrib/devtools/fix-copyright-headers.py index 5e84952548..1262e29acb 100755 --- a/contrib/devtools/fix-copyright-headers.py +++ b/contrib/devtools/fix-copyright-headers.py @@ -1,53 +1,46 @@ #!/usr/bin/env python ''' -Run this script inside of src/ and it will look for all the files -that were changed this year that still have the last year in the -copyright headers, and it will fix the headers on that file using -a perl regex one liner. +Run this script to update all the copyright headers of files +that were changed this year. -For example: if it finds something like this and we're in 2014 +For example: -// Copyright (c) 2009-2013 The Bitcoin Core developers +// Copyright (c) 2009-2012 The Bitcoin Core developers it will change it to -// Copyright (c) 2009-2014 The Bitcoin Core developers - -It will do this for all the files in the folder and its children. - -Author: @gubatron +// Copyright (c) 2009-2015 The Bitcoin Core developers ''' import os import time +import re year = time.gmtime()[0] -last_year = year - 1 -command = "perl -pi -e 's/%s The Bitcoin/%s The Bitcoin/' %s" -listFilesCommand = "find . | grep %s" - -extensions = [".cpp",".h"] - -def getLastGitModifiedDate(filePath): - gitGetLastCommitDateCommand = "git log " + filePath +" | grep Date | head -n 1" - p = os.popen(gitGetLastCommitDateCommand) - result = "" - for l in p: - result = l - break - result = result.replace("\n","") - return result +CMD_GIT_DATE = "git log %s | grep Date | head -n 1" +CMD_REGEX= "perl -pi -e 's/(20\d\d)(?:-20\d\d)? The Bitcoin/$1-%s The Bitcoin/' %s" +REGEX_CURRENT= re.compile("%s The Bitcoin" % year) +CMD_LIST_FILES= "find %s | grep %s" -n=1 -for extension in extensions: - foundFiles = os.popen(listFilesCommand % extension) - for filePath in foundFiles: - filePath = filePath[1:-1] - if filePath.endswith(extension): - filePath = os.getcwd() + filePath - modifiedTime = getLastGitModifiedDate(filePath) - if len(modifiedTime) > 0 and str(year) in modifiedTime: - print n,"Last Git Modified: ", modifiedTime, " - ", filePath - os.popen(command % (last_year,year,filePath)) - n = n + 1 +FOLDERS = ["./qa", "./src"] +EXTENSIONS = [".cpp",".h", ".py"] +def get_git_date(file_path): + r = os.popen(CMD_GIT_DATE % file_path) + for l in r: + # Result is one line, so just return + return l.replace("\n","") + return "" +n=1 +for folder in FOLDERS: + for extension in EXTENSIONS: + for file_path in os.popen(CMD_LIST_FILES % (folder, extension)): + file_path = os.getcwd() + file_path[1:-1] + if file_path.endswith(extension): + git_date = get_git_date(file_path) + if len(git_date) > 0 and str(year) in git_date: + # Only update if current year is not found + if REGEX_CURRENT.search(open(file_path, "r").read()) is None: + print n,"Last git edit", git_date, "-", file_path + os.popen(CMD_REGEX % (year,file_path)) + n = n + 1 -- cgit v1.2.3 From 0d595894f028248a1a1b00491dad95320844c685 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Fri, 25 Dec 2015 13:12:37 +0000 Subject: Bugfix: update-translations: Allow numerus translations to omit %n specifier (usually when it only has one possible value) --- contrib/devtools/update-translations.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'contrib/devtools') diff --git a/contrib/devtools/update-translations.py b/contrib/devtools/update-translations.py index 0be632069a..3e34b33971 100755 --- a/contrib/devtools/update-translations.py +++ b/contrib/devtools/update-translations.py @@ -70,7 +70,7 @@ def sanitize_string(s): '''Sanitize string for printing''' return s.replace('\n',' ') -def check_format_specifiers(source, translation, errors): +def check_format_specifiers(source, translation, errors, numerus): source_f = split_format_specifiers(find_format_specifiers(source)) # assert that no source messages contain both Qt and strprintf format specifiers # if this fails, go change the source as this is hacky and confusing! @@ -78,10 +78,13 @@ def check_format_specifiers(source, translation, errors): try: translation_f = split_format_specifiers(find_format_specifiers(translation)) except IndexError: - errors.append("Parse error in translation '%s'" % sanitize_string(translation)) + errors.append("Parse error in translation for '%s': '%s'" % (sanitize_string(source), sanitize_string(translation))) return False else: if source_f != translation_f: + if numerus and source_f == (set(), ['n']) and translation_f == (set(), []) and translation.find('%') == -1: + # Allow numerus translations to omit %n specifier (usually when it only has one possible value) + return True errors.append("Mismatch between '%s' and '%s'" % (sanitize_string(source), sanitize_string(translation))) return False return True @@ -148,7 +151,7 @@ def postprocess_translations(reduce_diff_hacks=False): if translation is None: continue errors = [] - valid = check_format_specifiers(source, translation, errors) + valid = check_format_specifiers(source, translation, errors, numerus) for error in errors: print('%s: %s' % (filename, error)) -- cgit v1.2.3 From fa71669452e57039e4270fd2b33a0e0e1635b813 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Sat, 26 Dec 2015 17:18:35 +0100 Subject: [devtools] Use git pretty-format for year parsing --- contrib/devtools/fix-copyright-headers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'contrib/devtools') diff --git a/contrib/devtools/fix-copyright-headers.py b/contrib/devtools/fix-copyright-headers.py index 1262e29acb..b6414a551f 100755 --- a/contrib/devtools/fix-copyright-headers.py +++ b/contrib/devtools/fix-copyright-headers.py @@ -16,7 +16,7 @@ import time import re year = time.gmtime()[0] -CMD_GIT_DATE = "git log %s | grep Date | head -n 1" +CMD_GIT_DATE = 'git log --format=@%%at -1 %s | date +"%%Y" -u -f -' CMD_REGEX= "perl -pi -e 's/(20\d\d)(?:-20\d\d)? The Bitcoin/$1-%s The Bitcoin/' %s" REGEX_CURRENT= re.compile("%s The Bitcoin" % year) CMD_LIST_FILES= "find %s | grep %s" @@ -38,7 +38,7 @@ for folder in FOLDERS: file_path = os.getcwd() + file_path[1:-1] if file_path.endswith(extension): git_date = get_git_date(file_path) - if len(git_date) > 0 and str(year) in git_date: + if str(year) == git_date: # Only update if current year is not found if REGEX_CURRENT.search(open(file_path, "r").read()) is None: print n,"Last git edit", git_date, "-", file_path -- cgit v1.2.3 From fada0c90b655226ddf79cd49dadb0d193f76edad Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Mon, 4 Jan 2016 02:06:04 +0100 Subject: [travis] Fail when documentation is outdated --- contrib/devtools/README.md | 6 ++++++ contrib/devtools/check-doc.py | 45 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100755 contrib/devtools/check-doc.py (limited to 'contrib/devtools') diff --git a/contrib/devtools/README.md b/contrib/devtools/README.md index a58b8733a6..1647d3ee3b 100644 --- a/contrib/devtools/README.md +++ b/contrib/devtools/README.md @@ -2,6 +2,12 @@ Contents ======== This directory contains tools for developers working on this repository. +check-doc.py +============ + +Check if all command line args are documented. The return value indicates the +number of undocumented args. + clang-format.py =============== diff --git a/contrib/devtools/check-doc.py b/contrib/devtools/check-doc.py new file mode 100755 index 0000000000..bc4ad53491 --- /dev/null +++ b/contrib/devtools/check-doc.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python +# Copyright (c) 2014 The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +''' +This checks if all command line args are documented. +Return value is 0 to indicate no error. + +Author: @MarcoFalke +''' + +from subprocess import check_output +import re + +FOLDER_GREP = 'src' +FOLDER_TEST = 'src/test/' +CMD_ROOT_DIR = '`git rev-parse --show-toplevel`/%s' % FOLDER_GREP +CMD_GREP_ARGS = r"egrep -r -I '(map(Multi)?Args(\.count\(|\[)|Get(Bool)?Arg\()\"\-[^\"]+?\"' %s | grep -v '%s'" % (CMD_ROOT_DIR, FOLDER_TEST) +CMD_GREP_DOCS = r"egrep -r -I 'HelpMessageOpt\(\"\-[^\"=]+?(=|\")' %s" % (CMD_ROOT_DIR) +REGEX_ARG = re.compile(r'(?:map(?:Multi)?Args(?:\.count\(|\[)|Get(?:Bool)?Arg\()\"(\-[^\"]+?)\"') +REGEX_DOC = re.compile(r'HelpMessageOpt\(\"(\-[^\"=]+?)(?:=|\")') +# list unsupported, deprecated and duplicate args as they need no documentation +SET_DOC_OPTIONAL = set(['-rpcssl', '-benchmark', '-h', '-help', '-socks', '-tor', '-debugnet']) + +def main(): + used = check_output(CMD_GREP_ARGS, shell=True) + docd = check_output(CMD_GREP_DOCS, shell=True) + + args_used = set(re.findall(REGEX_ARG,used)) + args_docd = set(re.findall(REGEX_DOC,docd)).union(SET_DOC_OPTIONAL) + args_need_doc = args_used.difference(args_docd) + args_unknown = args_docd.difference(args_used) + + print "Args used : %s" % len(args_used) + print "Args documented : %s" % len(args_docd) + print "Args undocumented: %s" % len(args_need_doc) + print args_need_doc + print "Args unknown : %s" % len(args_unknown) + print args_unknown + + exit(len(args_need_doc)) + +if __name__ == "__main__": + main() -- cgit v1.2.3 From fa4f4b6974cedd0689726a7eb791eb8f2d1d66ed Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Wed, 6 Jan 2016 15:26:56 +0100 Subject: Add clang-format-diff.py from the LLVM svn ------------------------------------------------------------------------ r249567 | djasper | 2015-10-07 19:00:20 +0200 (Wed, 07 Oct 2015) | 2 lines clang-format: Add include sorting capabilities to sublime, emacs and clang-format-diff.py. ------------------------------------------------------------------------ r231926 | djasper | 2015-03-11 15:58:38 +0100 (Wed, 11 Mar 2015) | 3 lines clang-format: Recognize the .ts (TypeScript) extension as JavaScript. Patch by Martin Probst. Thank you. ------------------------------------------------------------------------ r223685 | djasper | 2014-12-08 20:39:03 +0100 (Mon, 08 Dec 2014) | 1 line clang-format: Make clang-format-diff.py format java files. ------------------------------------------------------------------------ r221990 | djasper | 2014-11-14 14:27:28 +0100 (Fri, 14 Nov 2014) | 4 lines clang-format: Give clang-format-diff.py a -v option. With it, it prints the file being formatted. Apparently people are formatting thousands of files and some progress indication is helpful. ------------------------------------------------------------------------ r216945 | ed | 2014-09-02 22:59:13 +0200 (Tue, 02 Sep 2014) | 6 lines Use /usr/bin/env python instead of /usr/bin/python. On operating systems like the BSDs, it is typically the case that /usr/bin/python does not exist. We should therefore use /usr/bin/env instead. This is also done in various other scripts in tools/. ------------------------------------------------------------------------ r208766 | djasper | 2014-05-14 11:36:11 +0200 (Wed, 14 May 2014) | 1 line clang-format: Add clang-format-diff usage examples for SVN. ------------------------------------------------------------------------ r199750 | djasper | 2014-01-21 16:40:01 +0100 (Tue, 21 Jan 2014) | 3 lines clang-format: Enable formatting for .proto and .protodevel files. Support for protocol buffer files seems complete enough. ------------------------------------------------------------------------ r197668 | djasper | 2013-12-19 11:21:37 +0100 (Thu, 19 Dec 2013) | 1 line Fix usage description of clang-format-diff.py. ------------------------------------------------------------------------ r197608 | alp | 2013-12-18 22:34:07 +0100 (Wed, 18 Dec 2013) | 7 lines clang-format-diff.py: fix -regex/-iregex matching While debating the finer points of file extension matching, we somehow missed the bigger problem that the current code will match anything starting with the default or user-specified pattern (e.g. lit.site.cfg.in). Fix this by doing what find(1) does, implicitly wrapping the pattern with ^$. ------------------------------------------------------------------------ r197542 | alp | 2013-12-18 01:58:58 +0100 (Wed, 18 Dec 2013) | 3 lines clang-format-diff.py: add the OpenCL file extension It's handled correctly as a C-family language. ------------------------------------------------------------------------ r197378 | alexfh | 2013-12-16 11:57:30 +0100 (Mon, 16 Dec 2013) | 14 lines Added -iregex for case-insensitive regex to filter file names. Summary: -regex and -iregex both mimic options of the find utility. Made the default list of extensions case-insensitive, so that it's not only C and CPP extensions are accepted in upper case. Reviewers: djasper Reviewed By: djasper CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D2415 ------------------------------------------------------------------------ r196917 | alp | 2013-12-10 14:51:53 +0100 (Tue, 10 Dec 2013) | 10 lines clang-format-diff.py: Support -regex filter and more filename extensions Add support for more filename extensions based on the list in the clang plus JavaScript. Also adds a -regex option so users can override defaults if they have unusual file extensions or want to format everything in the diff. Keeping with tradition the flag is modelled on Unix conventions, this time matching the semantics of find(1). ------------------------------------------------------------------------ r196484 | alp | 2013-12-05 09:14:54 +0100 (Thu, 05 Dec 2013) | 4 lines clang-format-diff.py: pass through errors to stderr, not stdout Also use write() for unified diff output to avoid further processing by the print function (e.g. trailing newline). ------------------------------------------------------------------------ r196336 | alp | 2013-12-04 01:48:22 +0100 (Wed, 04 Dec 2013) | 3 lines clang-format-diff.py: Fix 'beintroduced' in help output Also update docs to reflect recently changed -i inplace edit behaviour. ------------------------------------------------------------------------ r192505 | alexfh | 2013-10-11 23:32:01 +0200 (Fri, 11 Oct 2013) | 17 lines Changed clang-format-diff.py to output diff by default. Added -i option to apply changes to files instead. Summary: "svn diff|clang-format-diff.py" will just output the diff. Now it's possible to use: svn diff|clang-format-diff.py|patch -p0 as an equivalent to: svn diff|clang-format-diff.py -i ;) Reviewers: djasper Reviewed By: djasper CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1840 ------------------------------------------------------------------------ r192184 | djasper | 2013-10-08 17:54:36 +0200 (Tue, 08 Oct 2013) | 7 lines clang-format: Don't exit with failure on empty files. Also let clang-format-diff.py detect errors based on clang-format's return code. Otherwise messages like "Can't find usable .clang-format, falling back to LLVM style" can make it fail, which might be undesired. Patch by Alp Toker. Thank you! ------------------------------------------------------------------------ r191820 | djasper | 2013-10-02 15:59:03 +0200 (Wed, 02 Oct 2013) | 18 lines clang-format: Fix clang-format-diff.py according to diff specification. Patch by Alp Toker. Many thanks! Original descriptions: clang-format-diff incorrectly modifies unchanged lines due to an error in diff parsing. The unified diff format has a default line change count of 1, and 0 may be specified to indicate that no lines have been added. This patch updates the parser to accurately reflect the diff specification. This also has the benefit of stabilising the operation so it will produce the same output when run multiple times on the same changeset, which was previously not the case. No tests added because this script is not currently tested (though we should look into that!) ------------------------------------------------------------------------ r191137 | djasper | 2013-09-21 12:05:02 +0200 (Sat, 21 Sep 2013) | 3 lines Fix clang-format-diff.py to accept -style again. Copy and paste error in r190935.. ------------------------------------------------------------------------ r190935 | djasper | 2013-09-18 14:14:09 +0200 (Wed, 18 Sep 2013) | 3 lines Simplify clang-format-diff.py using new clang-format options. clang-format's -lines parameter makes this significantly easier. ------------------------------------------------------------------------ r189765 | alexfh | 2013-09-02 18:39:23 +0200 (Mon, 02 Sep 2013) | 2 lines Added WebKit style to the BasedOnStyle handling and to the relevant help messages. ------------------------------------------------------------------------ r182923 | djasper | 2013-05-30 13:50:20 +0200 (Thu, 30 May 2013) | 4 lines Fix default value of clang-format-diff's -p option. This way, it has the same default as 'patch' and also the example in the code makes more sense as it is explicitly setting -p 1. ------------------------------------------------------------------------ r179676 | djasper | 2013-04-17 09:55:02 +0200 (Wed, 17 Apr 2013) | 2 lines Small improvements to clang-format documentation and integration scripts. ------------------------------------------------------------------------ r179377 | djasper | 2013-04-12 15:42:36 +0200 (Fri, 12 Apr 2013) | 1 line Fix clang-format-diff.py script. ------------------------------------------------------------------------ r179098 | djasper | 2013-04-09 17:23:04 +0200 (Tue, 09 Apr 2013) | 5 lines Improvements to clang-format integrations. This adds an emacs editor integration (thanks to Ami Fischman). Also pulls out the style into a variable for the vi integration and just uses clang-formats defaults style in clang-format-diff.py. ------------------------------------------------------------------------ r177506 | djasper | 2013-03-20 10:53:23 +0100 (Wed, 20 Mar 2013) | 1 line Add clang-format binary to cfe. ------------------------------------------------------------------------ s --- contrib/devtools/clang-format-diff.py | 124 ++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100755 contrib/devtools/clang-format-diff.py (limited to 'contrib/devtools') diff --git a/contrib/devtools/clang-format-diff.py b/contrib/devtools/clang-format-diff.py new file mode 100755 index 0000000000..9e02bb0938 --- /dev/null +++ b/contrib/devtools/clang-format-diff.py @@ -0,0 +1,124 @@ +#!/usr/bin/env python +# +#===- clang-format-diff.py - ClangFormat Diff Reformatter ----*- python -*--===# +# +# The LLVM Compiler Infrastructure +# +# This file is distributed under the University of Illinois Open Source +# License. See LICENSE.TXT for details. +# +#===------------------------------------------------------------------------===# + +r""" +ClangFormat Diff Reformatter +============================ + +This script reads input from a unified diff and reformats all the changed +lines. This is useful to reformat all the lines touched by a specific patch. +Example usage for git/svn users: + + git diff -U0 HEAD^ | clang-format-diff.py -p1 -i + svn diff --diff-cmd=diff -x-U0 | clang-format-diff.py -i + +""" + +import argparse +import difflib +import re +import string +import subprocess +import StringIO +import sys + + +# Change this to the full path if clang-format is not on the path. +binary = 'clang-format' + + +def main(): + parser = argparse.ArgumentParser(description= + 'Reformat changed lines in diff. Without -i ' + 'option just output the diff that would be ' + 'introduced.') + parser.add_argument('-i', action='store_true', default=False, + help='apply edits to files instead of displaying a diff') + parser.add_argument('-p', metavar='NUM', default=0, + help='strip the smallest prefix containing P slashes') + parser.add_argument('-regex', metavar='PATTERN', default=None, + help='custom pattern selecting file paths to reformat ' + '(case sensitive, overrides -iregex)') + parser.add_argument('-iregex', metavar='PATTERN', default= + r'.*\.(cpp|cc|c\+\+|cxx|c|cl|h|hpp|m|mm|inc|js|ts|proto' + r'|protodevel|java)', + help='custom pattern selecting file paths to reformat ' + '(case insensitive, overridden by -regex)') + parser.add_argument('-sort-includes', action='store_true', default=False, + help='let clang-format sort include blocks') + parser.add_argument('-v', '--verbose', action='store_true', + help='be more verbose, ineffective without -i') + parser.add_argument( + '-style', + help= + 'formatting style to apply (LLVM, Google, Chromium, Mozilla, WebKit)') + args = parser.parse_args() + + # Extract changed lines for each file. + filename = None + lines_by_file = {} + for line in sys.stdin: + match = re.search('^\+\+\+\ (.*?/){%s}(\S*)' % args.p, line) + if match: + filename = match.group(2) + if filename == None: + continue + + if args.regex is not None: + if not re.match('^%s$' % args.regex, filename): + continue + else: + if not re.match('^%s$' % args.iregex, filename, re.IGNORECASE): + continue + + match = re.search('^@@.*\+(\d+)(,(\d+))?', line) + if match: + start_line = int(match.group(1)) + line_count = 1 + if match.group(3): + line_count = int(match.group(3)) + if line_count == 0: + continue + end_line = start_line + line_count - 1; + lines_by_file.setdefault(filename, []).extend( + ['-lines', str(start_line) + ':' + str(end_line)]) + + # Reformat files containing changes in place. + for filename, lines in lines_by_file.iteritems(): + if args.i and args.verbose: + print 'Formatting', filename + command = [binary, filename] + if args.i: + command.append('-i') + if args.sort_includes: + command.append('-sort-includes') + command.extend(lines) + if args.style: + command.extend(['-style', args.style]) + p = subprocess.Popen(command, stdout=subprocess.PIPE, + stderr=None, stdin=subprocess.PIPE) + stdout, stderr = p.communicate() + if p.returncode != 0: + sys.exit(p.returncode); + + if not args.i: + with open(filename) as f: + code = f.readlines() + formatted_code = StringIO.StringIO(stdout).readlines() + diff = difflib.unified_diff(code, formatted_code, + filename, filename, + '(before formatting)', '(after formatting)') + diff_string = string.join(diff, '') + if len(diff_string) > 0: + sys.stdout.write(diff_string) + +if __name__ == '__main__': + main() -- cgit v1.2.3 From fa074a6fd098153c75ba0e76b7dd94eab82ae599 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Wed, 6 Jan 2016 16:11:31 +0100 Subject: [contrib] Prepare clang-format-diff for usage --- contrib/devtools/README.md | 12 ++++++++ contrib/devtools/clang-format-diff.py | 54 ++++++++++++++++++++++++++++++----- 2 files changed, 59 insertions(+), 7 deletions(-) (limited to 'contrib/devtools') diff --git a/contrib/devtools/README.md b/contrib/devtools/README.md index 240ab6d9e0..978f26b084 100644 --- a/contrib/devtools/README.md +++ b/contrib/devtools/README.md @@ -7,6 +7,18 @@ clang-format.py A script to format cpp source code according to [.clang-format](../../src/.clang-format). This should only be applied to new files or files which are currently not actively developed on. Also, git subtrees are not subject to formatting. +clang-format-diff.py +=================== + +A script to format unified git diffs according to [.clang-format](../../src/.clang-format). + +For instance, to format the last commit with 0 lines of context, +the script should be called from the git root folder as follows. + +``` +git diff -U0 HEAD~1.. | ./contrib/devtools/clang-format-diff.py -p1 -i -v +``` + fix-copyright-headers.py ======================== diff --git a/contrib/devtools/clang-format-diff.py b/contrib/devtools/clang-format-diff.py index 9e02bb0938..13d2573b9f 100755 --- a/contrib/devtools/clang-format-diff.py +++ b/contrib/devtools/clang-format-diff.py @@ -5,7 +5,52 @@ # The LLVM Compiler Infrastructure # # This file is distributed under the University of Illinois Open Source -# License. See LICENSE.TXT for details. +# License. +# +# ============================================================ +# +# University of Illinois/NCSA +# Open Source License +# +# Copyright (c) 2007-2015 University of Illinois at Urbana-Champaign. +# All rights reserved. +# +# Developed by: +# +# LLVM Team +# +# University of Illinois at Urbana-Champaign +# +# http://llvm.org +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of +# this software and associated documentation files (the "Software"), to deal with +# the Software without restriction, including without limitation the rights to +# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +# of the Software, and to permit persons to whom the Software is furnished to do +# so, subject to the following conditions: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimers. +# +# * Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimers in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the names of the LLVM Team, University of Illinois at +# Urbana-Champaign, nor the names of its contributors may be used to +# endorse or promote products derived from this Software without specific +# prior written permission. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE +# SOFTWARE. +# +# ============================================================ # #===------------------------------------------------------------------------===# @@ -56,10 +101,6 @@ def main(): help='let clang-format sort include blocks') parser.add_argument('-v', '--verbose', action='store_true', help='be more verbose, ineffective without -i') - parser.add_argument( - '-style', - help= - 'formatting style to apply (LLVM, Google, Chromium, Mozilla, WebKit)') args = parser.parse_args() # Extract changed lines for each file. @@ -101,8 +142,7 @@ def main(): if args.sort_includes: command.append('-sort-includes') command.extend(lines) - if args.style: - command.extend(['-style', args.style]) + command.extend(['-style=file', '-fallback-style=none']) p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=None, stdin=subprocess.PIPE) stdout, stderr = p.communicate() -- cgit v1.2.3 From 0331aa350c04253f3b94604a0152042646fc94bb Mon Sep 17 00:00:00 2001 From: calebogden Date: Fri, 8 Jan 2016 13:31:42 -0800 Subject: Fixing typos on security-check.py and torcontrol.cpp --- contrib/devtools/security-check.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'contrib/devtools') diff --git a/contrib/devtools/security-check.py b/contrib/devtools/security-check.py index e96eaa9c38..fe5dc9ad89 100755 --- a/contrib/devtools/security-check.py +++ b/contrib/devtools/security-check.py @@ -1,7 +1,7 @@ #!/usr/bin/python2 ''' Perform basic ELF security checks on a series of executables. -Exit status will be 0 if succesful, and the program will be silent. +Exit status will be 0 if successful, and the program will be silent. Otherwise the exit status will be 1 and it will log which executables failed which checks. Needs `readelf` (for ELF) and `objdump` (for PE). ''' -- cgit v1.2.3 From faeda0e67792855cdafa2f6eaf43ad74de89b18b Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Mon, 4 Jan 2016 19:29:03 +0100 Subject: [travis] Run contrib/devtools/check-doc.py early --- contrib/devtools/check-doc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'contrib/devtools') diff --git a/contrib/devtools/check-doc.py b/contrib/devtools/check-doc.py index bc4ad53491..9c589e6e6d 100755 --- a/contrib/devtools/check-doc.py +++ b/contrib/devtools/check-doc.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# Copyright (c) 2014 The Bitcoin Core developers +# Copyright (c) 2015 The Bitcoin Core developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. -- cgit v1.2.3 From da6d18b6c7a4c305b661684ccda23083731bbb08 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Tue, 19 Jan 2016 09:53:26 +0100 Subject: devtools: replace github-merge with python version This is meant to be a direct translation of the bash script, with the difference that it retrieves the PR title from github, thus creating pull messages like: Merge #12345: Expose transaction temperature over RPC --- contrib/devtools/README.md | 4 +- contrib/devtools/github-merge.py | 223 +++++++++++++++++++++++++++++++++++++++ contrib/devtools/github-merge.sh | 185 -------------------------------- 3 files changed, 225 insertions(+), 187 deletions(-) create mode 100755 contrib/devtools/github-merge.py delete mode 100755 contrib/devtools/github-merge.sh (limited to 'contrib/devtools') diff --git a/contrib/devtools/README.md b/contrib/devtools/README.md index fcb2275fc9..1103ca86c5 100644 --- a/contrib/devtools/README.md +++ b/contrib/devtools/README.md @@ -56,14 +56,14 @@ Usage: `git-subtree-check.sh DIR COMMIT` `COMMIT` may be omitted, in which case `HEAD` is used. -github-merge.sh +github-merge.py =============== A small script to automate merging pull-requests securely and sign them with GPG. For example: - ./github-merge.sh bitcoin/bitcoin 3077 + ./github-merge.py 3077 (in any git repository) will help you merge pull request #3077 for the bitcoin/bitcoin repository. diff --git a/contrib/devtools/github-merge.py b/contrib/devtools/github-merge.py new file mode 100755 index 0000000000..33d33b7005 --- /dev/null +++ b/contrib/devtools/github-merge.py @@ -0,0 +1,223 @@ +#!/usr/bin/env python2 +# Copyright (c) 2016 Bitcoin Core Developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +# This script will locally construct a merge commit for a pull request on a +# github repository, inspect it, sign it and optionally push it. + +# The following temporary branches are created/overwritten and deleted: +# * pull/$PULL/base (the current master we're merging onto) +# * pull/$PULL/head (the current state of the remote pull request) +# * pull/$PULL/merge (github's merge) +# * pull/$PULL/local-merge (our merge) + +# In case of a clean merge that is accepted by the user, the local branch with +# name $BRANCH is overwritten with the merged result, and optionally pushed. +from __future__ import division,print_function,unicode_literals +import os,sys +from sys import stdin,stdout,stderr +import argparse +import subprocess + +# External tools (can be overridden using environment) +GIT = os.getenv('GIT','git') +BASH = os.getenv('BASH','bash') + +def git_config_get(option, default=None): + ''' + Get named configuration option from git repository. + ''' + try: + return subprocess.check_output([GIT,'config','--get',option]).rstrip() + except subprocess.CalledProcessError as e: + return default + +def retrieve_pr_title(repo,pull): + ''' + Retrieve pull request title from github. + Return None if no title can be found, or an error happens. + ''' + import urllib2,json + try: + req = urllib2.Request("https://api.github.com/repos/"+repo+"/pulls/"+pull) + result = urllib2.urlopen(req) + result = json.load(result) + return result['title'] + except Exception as e: + print('Warning: unable to retrieve pull title from github: %s' % e) + return None + +def ask_prompt(text): + print(text,end=" ",file=stderr) + reply = stdin.readline().rstrip() + print("",file=stderr) + return reply + +def parse_arguments(branch): + epilog = ''' + In addition, you can set the following git configuration variables: + githubmerge.repository (mandatory), + user.signingkey (mandatory), + githubmerge.host (default: git@github.com), + githubmerge.branch (default: master), + githubmerge.testcmd (default: none). + ''' + parser = argparse.ArgumentParser(description='Utility to merge, sign and push github pull requests', + epilog=epilog) + parser.add_argument('pull', metavar='PULL', type=int, nargs=1, + help='Pull request ID to merge') + parser.add_argument('branch', metavar='BRANCH', type=str, nargs='?', + default=branch, help='Branch to merge against (default: '+branch+')') + return parser.parse_args() + +def main(): + # Extract settings from git repo + repo = git_config_get('githubmerge.repository') + host = git_config_get('githubmerge.host','git@github.com') + branch = git_config_get('githubmerge.branch','master') + testcmd = git_config_get('githubmerge.testcmd') + signingkey = git_config_get('user.signingkey') + if repo is None: + print("ERROR: No repository configured. Use this command to set:", file=stderr) + print("git config githubmerge.repository /", file=stderr) + exit(1) + if signingkey is None: + print("ERROR: No GPG signing key set. Set one using:",file=stderr) + print("git config --global user.signingkey ",file=stderr) + exit(1) + + host_repo = host+":"+repo # shortcut for push/pull target + + # Extract settings from command line + args = parse_arguments(branch) + pull = str(args.pull[0]) + branch = args.branch + + # Initialize source branches + head_branch = 'pull/'+pull+'/head' + base_branch = 'pull/'+pull+'/base' + merge_branch = 'pull/'+pull+'/merge' + local_merge_branch = 'pull/'+pull+'/local-merge' + + devnull = open(os.devnull,'w') + try: + subprocess.check_call([GIT,'checkout','-q',branch]) + except subprocess.CalledProcessError as e: + print("ERROR: Cannot check out branch %s." % (branch), file=stderr) + exit(3) + try: + subprocess.check_call([GIT,'fetch','-q',host_repo,'+refs/pull/'+pull+'/*:refs/heads/pull/'+pull+'/*']) + except subprocess.CalledProcessError as e: + print("ERROR: Cannot find pull request #%s on %s." % (pull,host_repo), file=stderr) + exit(3) + try: + subprocess.check_call([GIT,'log','-q','-1','refs/heads/'+head_branch], stdout=devnull, stderr=stdout) + except subprocess.CalledProcessError as e: + print("ERROR: Cannot find head of pull request #%s on %s." % (pull,host_repo), file=stderr) + exit(3) + try: + subprocess.check_call([GIT,'log','-q','-1','refs/heads/'+merge_branch], stdout=devnull, stderr=stdout) + except subprocess.CalledProcessError as e: + print("ERROR: Cannot find merge of pull request #%s on %s." % (pull,host_repo), file=stderr) + exit(3) + try: + subprocess.check_call([GIT,'fetch','-q',host_repo,'+refs/heads/'+branch+':refs/heads/'+base_branch]) + except subprocess.CalledProcessError as e: + print("ERROR: Cannot find branch %s on %s." % (branch,host_repo), file=stderr) + exit(3) + subprocess.check_call([GIT,'checkout','-q',base_branch]) + subprocess.call([GIT,'branch','-q','-D',local_merge_branch], stderr=devnull) + subprocess.check_call([GIT,'checkout','-q','-b',local_merge_branch]) + + try: + # Create unsigned merge commit. + title = retrieve_pr_title(repo,pull) + if title: + firstline = 'Merge #%s: %s' % (pull,title) + else: + firstline = 'Merge #%s' % (pull,) + message = firstline + '\n\n' + message += subprocess.check_output([GIT,'log','--no-merges','--topo-order','--pretty=format:%h %s (%an)',base_branch+'..'+head_branch]) + try: + subprocess.check_call([GIT,'merge','-q','--commit','--no-edit','--no-ff','-m',message,head_branch]) + except subprocess.CalledProcessError as e: + print("ERROR: Cannot be merged cleanly.",file=stderr) + subprocess.check_call([GIT,'merge','--abort']) + exit(4) + logmsg = subprocess.check_output([GIT,'log','--pretty=format:%s','-n','1']) + if logmsg.rstrip() != firstline.rstrip(): + print("ERROR: Creating merge failed (already merged?).",file=stderr) + exit(4) + + # Run test command if configured. + if testcmd: + # Go up to the repository's root. + toplevel = subprocess.check_output([GIT,'rev-parse','--show-toplevel']) + os.chdir(toplevel) + if subprocess.call(testcmd,shell=True): + print("ERROR: Running %s failed." % testcmd,file=stderr) + exit(5) + + # Show the created merge. + diff = subprocess.check_output([GIT,'diff',merge_branch+'..'+local_merge_branch]) + subprocess.check_call([GIT,'diff',base_branch+'..'+local_merge_branch]) + if diff: + print("WARNING: merge differs from github!",file=stderr) + reply = ask_prompt("Type 'ignore' to continue.") + if reply.lower() == 'ignore': + print("Difference with github ignored.",file=stderr) + else: + exit(6) + reply = ask_prompt("Press 'd' to accept the diff.") + if reply.lower() == 'd': + print("Diff accepted.",file=stderr) + else: + print("ERROR: Diff rejected.",file=stderr) + exit(6) + else: + # Verify the result manually. + print("Dropping you on a shell so you can try building/testing the merged source.",file=stderr) + print("Run 'git diff HEAD~' to show the changes being merged.",file=stderr) + print("Type 'exit' when done.",file=stderr) + if os.path.isfile('/etc/debian_version'): # Show pull number on Debian default prompt + os.putenv('debian_chroot',pull) + subprocess.call([BASH,'-i']) + reply = ask_prompt("Type 'm' to accept the merge.") + if reply.lower() == 'm': + print("Merge accepted.",file=stderr) + else: + print("ERROR: Merge rejected.",file=stderr) + exit(7) + + # Sign the merge commit. + reply = ask_prompt("Type 's' to sign off on the merge.") + if reply == 's': + try: + subprocess.check_call([GIT,'commit','-q','--gpg-sign','--amend','--no-edit']) + except subprocess.CalledProcessError as e: + print("Error signing, exiting.",file=stderr) + exit(1) + else: + print("Not signing off on merge, exiting.",file=stderr) + exit(1) + + # Put the result in branch. + subprocess.check_call([GIT,'checkout','-q',branch]) + subprocess.check_call([GIT,'reset','-q','--hard',local_merge_branch]) + finally: + # Clean up temporary branches. + subprocess.call([GIT,'checkout','-q',branch]) + subprocess.call([GIT,'branch','-q','-D',head_branch],stderr=devnull) + subprocess.call([GIT,'branch','-q','-D',base_branch],stderr=devnull) + subprocess.call([GIT,'branch','-q','-D',merge_branch],stderr=devnull) + subprocess.call([GIT,'branch','-q','-D',local_merge_branch],stderr=devnull) + + # Push the result. + reply = ask_prompt("Type 'push' to push the result to %s, branch %s." % (host_repo,branch)) + if reply.lower() == 'push': + subprocess.check_call([GIT,'push',host_repo,'refs/heads/'+branch]) + +if __name__ == '__main__': + main() + diff --git a/contrib/devtools/github-merge.sh b/contrib/devtools/github-merge.sh deleted file mode 100755 index afb53f0390..0000000000 --- a/contrib/devtools/github-merge.sh +++ /dev/null @@ -1,185 +0,0 @@ -#!/bin/bash - -# This script will locally construct a merge commit for a pull request on a -# github repository, inspect it, sign it and optionally push it. - -# The following temporary branches are created/overwritten and deleted: -# * pull/$PULL/base (the current master we're merging onto) -# * pull/$PULL/head (the current state of the remote pull request) -# * pull/$PULL/merge (github's merge) -# * pull/$PULL/local-merge (our merge) - -# In case of a clean merge that is accepted by the user, the local branch with -# name $BRANCH is overwritten with the merged result, and optionally pushed. - -REPO="$(git config --get githubmerge.repository)" -if [[ "d$REPO" == "d" ]]; then - echo "ERROR: No repository configured. Use this command to set:" >&2 - echo "git config githubmerge.repository /" >&2 - echo "In addition, you can set the following variables:" >&2 - echo "- githubmerge.host (default git@github.com)" >&2 - echo "- githubmerge.branch (default master)" >&2 - echo "- githubmerge.testcmd (default none)" >&2 - exit 1 -fi - -HOST="$(git config --get githubmerge.host)" -if [[ "d$HOST" == "d" ]]; then - HOST="git@github.com" -fi - -BRANCH="$(git config --get githubmerge.branch)" -if [[ "d$BRANCH" == "d" ]]; then - BRANCH="master" -fi - -TESTCMD="$(git config --get githubmerge.testcmd)" - -PULL="$1" - -if [[ "d$PULL" == "d" ]]; then - echo "Usage: $0 pullnumber [branch]" >&2 - exit 2 -fi - -if [[ "d$2" != "d" ]]; then - BRANCH="$2" -fi - -# Initialize source branches. -git checkout -q "$BRANCH" -if git fetch -q "$HOST":"$REPO" "+refs/pull/$PULL/*:refs/heads/pull/$PULL/*"; then - if ! git log -q -1 "refs/heads/pull/$PULL/head" >/dev/null 2>&1; then - echo "ERROR: Cannot find head of pull request #$PULL on $HOST:$REPO." >&2 - exit 3 - fi - if ! git log -q -1 "refs/heads/pull/$PULL/merge" >/dev/null 2>&1; then - echo "ERROR: Cannot find merge of pull request #$PULL on $HOST:$REPO." >&2 - exit 3 - fi -else - echo "ERROR: Cannot find pull request #$PULL on $HOST:$REPO." >&2 - exit 3 -fi -if git fetch -q "$HOST":"$REPO" +refs/heads/"$BRANCH":refs/heads/pull/"$PULL"/base; then - true -else - echo "ERROR: Cannot find branch $BRANCH on $HOST:$REPO." >&2 - exit 3 -fi -git checkout -q pull/"$PULL"/base -git branch -q -D pull/"$PULL"/local-merge 2>/dev/null -git checkout -q -b pull/"$PULL"/local-merge -TMPDIR="$(mktemp -d -t ghmXXXXX)" - -function cleanup() { - git checkout -q "$BRANCH" - git branch -q -D pull/"$PULL"/head 2>/dev/null - git branch -q -D pull/"$PULL"/base 2>/dev/null - git branch -q -D pull/"$PULL"/merge 2>/dev/null - git branch -q -D pull/"$PULL"/local-merge 2>/dev/null - rm -rf "$TMPDIR" -} - -# Create unsigned merge commit. -( - echo "Merge pull request #$PULL" - echo "" - git log --no-merges --topo-order --pretty='format:%h %s (%an)' pull/"$PULL"/base..pull/"$PULL"/head -)>"$TMPDIR/message" -if git merge -q --commit --no-edit --no-ff -m "$(<"$TMPDIR/message")" pull/"$PULL"/head; then - if [ "d$(git log --pretty='format:%s' -n 1)" != "dMerge pull request #$PULL" ]; then - echo "ERROR: Creating merge failed (already merged?)." >&2 - cleanup - exit 4 - fi -else - echo "ERROR: Cannot be merged cleanly." >&2 - git merge --abort - cleanup - exit 4 -fi - -# Run test command if configured. -if [[ "d$TESTCMD" != "d" ]]; then - # Go up to the repository's root. - while [ ! -d .git ]; do cd ..; done - if ! $TESTCMD; then - echo "ERROR: Running $TESTCMD failed." >&2 - cleanup - exit 5 - fi - # Show the created merge. - git diff pull/"$PULL"/merge..pull/"$PULL"/local-merge >"$TMPDIR"/diff - git diff pull/"$PULL"/base..pull/"$PULL"/local-merge - if [[ "$(<"$TMPDIR"/diff)" != "" ]]; then - echo "WARNING: merge differs from github!" >&2 - read -p "Type 'ignore' to continue. " -r >&2 - if [[ "d$REPLY" =~ ^d[iI][gG][nN][oO][rR][eE]$ ]]; then - echo "Difference with github ignored." >&2 - else - cleanup - exit 6 - fi - fi - read -p "Press 'd' to accept the diff. " -n 1 -r >&2 - echo - if [[ "d$REPLY" =~ ^d[dD]$ ]]; then - echo "Diff accepted." >&2 - else - echo "ERROR: Diff rejected." >&2 - cleanup - exit 6 - fi -else - # Verify the result. - echo "Dropping you on a shell so you can try building/testing the merged source." >&2 - echo "Run 'git diff HEAD~' to show the changes being merged." >&2 - echo "Type 'exit' when done." >&2 - if [[ -f /etc/debian_version ]]; then # Show pull number in prompt on Debian default prompt - export debian_chroot="$PULL" - fi - bash -i - read -p "Press 'm' to accept the merge. " -n 1 -r >&2 - echo - if [[ "d$REPLY" =~ ^d[Mm]$ ]]; then - echo "Merge accepted." >&2 - else - echo "ERROR: Merge rejected." >&2 - cleanup - exit 7 - fi -fi - -# Sign the merge commit. -read -p "Press 's' to sign off on the merge. " -n 1 -r >&2 -echo -if [[ "d$REPLY" =~ ^d[Ss]$ ]]; then - if [[ "$(git config --get user.signingkey)" == "" ]]; then - echo "ERROR: No GPG signing key set, not signing. Set one using:" >&2 - echo "git config --global user.signingkey " >&2 - cleanup - exit 1 - else - if ! git commit -q --gpg-sign --amend --no-edit; then - echo "Error signing, exiting." - cleanup - exit 1 - fi - fi -else - echo "Not signing off on merge, exiting." - cleanup - exit 1 -fi - -# Clean up temporary branches, and put the result in $BRANCH. -git checkout -q "$BRANCH" -git reset -q --hard pull/"$PULL"/local-merge -cleanup - -# Push the result. -read -p "Type 'push' to push the result to $HOST:$REPO, branch $BRANCH. " -r >&2 -if [[ "d$REPLY" =~ ^d[Pp][Uu][Ss][Hh]$ ]]; then - git push "$HOST":"$REPO" refs/heads/"$BRANCH" -fi -- cgit v1.2.3 From 17b5d3896f2cd189b1a4665956bdfba368d46f0e Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Fri, 22 Jan 2016 16:37:21 +0100 Subject: devtools: show pull and commit information in github-merge Print the number and title of the pull, as well as the commits to be merged. --- contrib/devtools/github-merge.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'contrib/devtools') diff --git a/contrib/devtools/github-merge.py b/contrib/devtools/github-merge.py index 33d33b7005..6854ecb073 100755 --- a/contrib/devtools/github-merge.py +++ b/contrib/devtools/github-merge.py @@ -24,6 +24,15 @@ import subprocess GIT = os.getenv('GIT','git') BASH = os.getenv('BASH','bash') +# OS specific configuration for terminal attributes +ATTR_RESET = '' +ATTR_PR = '' +COMMIT_FORMAT = '%h %s (%an)%d' +if os.name == 'posix': # if posix, assume we can use basic terminal escapes + ATTR_RESET = '\033[0m' + ATTR_PR = '\033[1;36m' + COMMIT_FORMAT = '%C(bold blue)%h%Creset %s %C(cyan)(%an)%Creset%C(green)%d%Creset' + def git_config_get(option, default=None): ''' Get named configuration option from git repository. @@ -150,6 +159,9 @@ def main(): print("ERROR: Creating merge failed (already merged?).",file=stderr) exit(4) + print('%s#%s%s %s' % (ATTR_RESET+ATTR_PR,pull,ATTR_RESET,title)) + subprocess.check_call([GIT,'log','--graph','--topo-order','--pretty=format:'+COMMIT_FORMAT,base_branch+'..'+head_branch]) + print() # Run test command if configured. if testcmd: # Go up to the repository's root. -- cgit v1.2.3 From 5ed2f16480142f0887cc1a6257ff53e2abc3e5b6 Mon Sep 17 00:00:00 2001 From: Andrew C Date: Sat, 23 Jan 2016 10:35:27 -0500 Subject: [devtools] github-merge get toplevel dir without extra whitespace Fixes a bug in github merge when it runs the tests where the toplevel directory has an extra '\n' appended to the path string. Now it doesn't. --- contrib/devtools/github-merge.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'contrib/devtools') diff --git a/contrib/devtools/github-merge.py b/contrib/devtools/github-merge.py index 33d33b7005..11118fd7dd 100755 --- a/contrib/devtools/github-merge.py +++ b/contrib/devtools/github-merge.py @@ -153,7 +153,7 @@ def main(): # Run test command if configured. if testcmd: # Go up to the repository's root. - toplevel = subprocess.check_output([GIT,'rev-parse','--show-toplevel']) + toplevel = subprocess.check_output([GIT,'rev-parse','--show-toplevel']).strip() os.chdir(toplevel) if subprocess.call(testcmd,shell=True): print("ERROR: Running %s failed." % testcmd,file=stderr) -- cgit v1.2.3 From cd27bf51e06a8d79790a631696355bd05751b0aa Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Tue, 26 Jan 2016 14:50:50 -0500 Subject: release: fix parsing of BIND_NOW with older readelf --- contrib/devtools/security-check.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'contrib/devtools') diff --git a/contrib/devtools/security-check.py b/contrib/devtools/security-check.py index fe5dc9ad89..0319f739c4 100755 --- a/contrib/devtools/security-check.py +++ b/contrib/devtools/security-check.py @@ -94,7 +94,7 @@ def check_ELF_RELRO(executable): raise IOError('Error opening file') for line in stdout.split('\n'): tokens = line.split() - if len(tokens)>1 and tokens[1] == '(BIND_NOW)': + if len(tokens)>1 and tokens[1] == '(BIND_NOW)' or (len(tokens)>2 and tokens[1] == '(FLAGS)' and 'BIND_NOW' in tokens[2]): have_bindnow = True return have_gnu_relro and have_bindnow -- cgit v1.2.3 From 475813ba5b208eb9a5d027eb628a717cc123ef4f Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Tue, 26 Jan 2016 23:03:15 -0500 Subject: release: add _IO_stdin_used to ignored exports For details see: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=634261#109 --- contrib/devtools/symbol-check.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'contrib/devtools') diff --git a/contrib/devtools/symbol-check.py b/contrib/devtools/symbol-check.py index 93acfcdda4..4ad5136f79 100755 --- a/contrib/devtools/symbol-check.py +++ b/contrib/devtools/symbol-check.py @@ -42,9 +42,12 @@ MAX_VERSIONS = { 'GLIBCXX': (3,4,13), 'GLIBC': (2,11) } +# See here for a description of _IO_stdin_used: +# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=634261#109 + # Ignore symbols that are exported as part of every executable IGNORE_EXPORTS = { -'_edata', '_end', '_init', '__bss_start', '_fini' +'_edata', '_end', '_init', '__bss_start', '_fini', '_IO_stdin_used' } READELF_CMD = os.getenv('READELF', '/usr/bin/readelf') CPPFILT_CMD = os.getenv('CPPFILT', '/usr/bin/c++filt') -- cgit v1.2.3 From c8a6c11d6d4c5910dca14135d466efc5c40f519c Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Wed, 27 Jan 2016 11:39:58 +0100 Subject: devtools: Fix utf-8 support in messages for github-merge MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use 'utf-8' instead of the Python 2 default of 'ascii' to encode/decode commit messages. This can be removed when switching to Python 3, as 'utf-8' is the default there. Necessary for merging #7422 due to the ฿ in ฿tcDrak. --- contrib/devtools/github-merge.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'contrib/devtools') diff --git a/contrib/devtools/github-merge.py b/contrib/devtools/github-merge.py index f7781cceb3..c8dcaae268 100755 --- a/contrib/devtools/github-merge.py +++ b/contrib/devtools/github-merge.py @@ -147,14 +147,14 @@ def main(): else: firstline = 'Merge #%s' % (pull,) message = firstline + '\n\n' - message += subprocess.check_output([GIT,'log','--no-merges','--topo-order','--pretty=format:%h %s (%an)',base_branch+'..'+head_branch]) + message += subprocess.check_output([GIT,'log','--no-merges','--topo-order','--pretty=format:%h %s (%an)',base_branch+'..'+head_branch]).decode('utf-8') try: - subprocess.check_call([GIT,'merge','-q','--commit','--no-edit','--no-ff','-m',message,head_branch]) + subprocess.check_call([GIT,'merge','-q','--commit','--no-edit','--no-ff','-m',message.encode('utf-8'),head_branch]) except subprocess.CalledProcessError as e: print("ERROR: Cannot be merged cleanly.",file=stderr) subprocess.check_call([GIT,'merge','--abort']) exit(4) - logmsg = subprocess.check_output([GIT,'log','--pretty=format:%s','-n','1']) + logmsg = subprocess.check_output([GIT,'log','--pretty=format:%s','-n','1']).decode('utf-8') if logmsg.rstrip() != firstline.rstrip(): print("ERROR: Creating merge failed (already merged?).",file=stderr) exit(4) -- cgit v1.2.3 From 89d113e02a83617b4e971c160d47551476dacc71 Mon Sep 17 00:00:00 2001 From: Gregory Maxwell Date: Sun, 31 Jan 2016 11:59:18 +0000 Subject: Blacklist -whitelistalwaysrelay; replaced by -whitelistrelay. --- contrib/devtools/check-doc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'contrib/devtools') diff --git a/contrib/devtools/check-doc.py b/contrib/devtools/check-doc.py index 9c589e6e6d..8c73cf1e8a 100755 --- a/contrib/devtools/check-doc.py +++ b/contrib/devtools/check-doc.py @@ -21,7 +21,7 @@ CMD_GREP_DOCS = r"egrep -r -I 'HelpMessageOpt\(\"\-[^\"=]+?(=|\")' %s" % (CMD_RO REGEX_ARG = re.compile(r'(?:map(?:Multi)?Args(?:\.count\(|\[)|Get(?:Bool)?Arg\()\"(\-[^\"]+?)\"') REGEX_DOC = re.compile(r'HelpMessageOpt\(\"(\-[^\"=]+?)(?:=|\")') # list unsupported, deprecated and duplicate args as they need no documentation -SET_DOC_OPTIONAL = set(['-rpcssl', '-benchmark', '-h', '-help', '-socks', '-tor', '-debugnet']) +SET_DOC_OPTIONAL = set(['-rpcssl', '-benchmark', '-h', '-help', '-socks', '-tor', '-debugnet', '-whitelistalwaysrelay']) def main(): used = check_output(CMD_GREP_ARGS, shell=True) -- cgit v1.2.3