Skip to content

Commit 2cc9c44

Browse files
plamen5kovpetekanev
authored andcommitted
update permissions on linux and fixed a typo
1 parent bc4741d commit 2cc9c44

5 files changed

Lines changed: 120 additions & 0 deletions

File tree

tools/.astyle

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Insert space padding between a header (e.g. 'if', 'for', 'while'...) and the following paren. Any end of line comments will remain in the original column, if possible. This can be used with unpad-paren to remove unwanted spaces.
2+
-H
3+
4+
# Attach a pointer or reference operator (*, &, or ^) to either the variable type (left) or variable name (right), or place it between the type and name (middle). The spacing between the type and name will be preserved, if possible. This option is for C/C++, C++/CLI, and C# files.
5+
-k1
6+
7+
# Add brackets to unbracketed one line conditional statements (e.g. 'if', 'for', 'while'...). The statement must be on a single line. The brackets will be added according to the currently requested predefined style or bracket type. If no style or bracket type is requested the brackets will be attached. If --add-one-line-brackets is also used the result will be one line brackets.
8+
-j
9+
10+
# Converts tabs into spaces in the non-indentation part of the line. The number of spaces inserted will maintain the spacing of the tab. The current setting for spaces per tab is used. It may not produce the expected results if convert-tabs is used when changing spaces per tab. Tabs are not replaced in quotes.
11+
-C
12+
13+
# Indent 4 spaces
14+
-s4
15+
16+
# Specify a file or sub directory #### to be excluded from processing.
17+
--exclude="runtime/src/main/jni/include"
18+
19+
# Allow processing to continue if there are errors in the "exclude=###" options.
20+
-i
21+
22+
# Do not retain a backup of the original file. The original file is purged after it is formatted.
23+
-n
24+

tools/astyle

463 KB
Binary file not shown.

tools/astyle.exe

490 KB
Binary file not shown.

tools/astyle.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
let process = require("process");
2+
let child_process = require("child_process");
3+
let argv = process.argv;
4+
5+
const validFiles = ['c', 'cpp', 'h', 'java'];
6+
7+
// let date = new Date();
8+
// let dateString = `${date.getDay() + 1}-${date.getMonth() + 1}-${date.getFullYear()}--${date.getHours()}:${date.getMinutes()}`
9+
// let backupDir = `formatbackup-${dateString}`;
10+
11+
let astyleOptions = "-H -k1 -j -C -s4 -i -n" // "--options=tools\\.astyle"
12+
let astyle = "astyle";
13+
14+
if (process.platform.indexOf("win") === 0) {
15+
astyle = "tools\\astyle.exe"
16+
} else if (process.platform.indexOf("linux") === 0) {
17+
astyle = "./tools/astyle"
18+
}
19+
20+
let against = argv[2] || "HEAD";
21+
22+
let stdout = child_process.execSync(`git diff-index --diff-filter=ACMR --name-only -r --cached ${against} --`);
23+
let stdoutStr = stdout.toString("utf8").split(/\r?\n/);
24+
25+
let filteredFiles = stdoutStr.filter((val) => {
26+
var fileNameParts = val.split(".");
27+
if (fileNameParts.length > 1) {
28+
// get the extension (i.e., the last "piece" of the file name)
29+
var fileExtension = fileNameParts[fileNameParts.length - 1];
30+
31+
// if the extension is in the array, return true, if not, return false
32+
return validFiles.indexOf(fileExtension) >= 0;
33+
}
34+
else {
35+
return false;
36+
}
37+
});
38+
39+
for (let i = 0; i < filteredFiles.length; i++) {
40+
let file = filteredFiles[i];
41+
let executable = `${astyle} ${astyleOptions} ${file}`;
42+
43+
let processStdout = child_process.execSync(executable);
44+
console.log(processStdout.toString());
45+
child_process.execSync(`git add ${file}`);
46+
}

tools/pre-commit

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/sh
2+
3+
# Astyle pre-commit hook - Version 2.0 (By Ramon Fried and Yossi Segev)
4+
# This file should be placed under .git/hooks and should have executables permissions
5+
# Things to change (if you want):
6+
# 1. The Astyle settings (it no longer takes it from the default)
7+
# 2. The files the scripts operates upon (currently only C/C++ source / header files)
8+
9+
DATE=$(date +%d-%m-%Y--%H:%M)
10+
BACKUPDIR="formatbackup-$DATE"
11+
12+
ASTYLE_PARAMETERS="--options=.astyle"
13+
14+
if git rev-parse --verify HEAD >/dev/null 2>&1
15+
then
16+
against=HEAD
17+
else
18+
# Initial commit: diff against an empty tree object
19+
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
20+
fi
21+
22+
# If you want to allow non-ASCII filenames set this variable to true.
23+
allownonascii=$(git config --bool hooks.allownonascii)
24+
25+
# Cross platform projects tend to avoid non-ascii filenames; prevent
26+
# them from being added to the repository. We exploit the fact that the
27+
# printable range starts at the space character and ends with tilde.
28+
if [ "$allownonascii" != "true" ] &&
29+
# Note that the use of brackets around a tr range is ok here, (it's
30+
# even required, for portability to Solaris 10's /usr/bin/tr), since
31+
# the square bracket bytes happen to fall in the designated range.
32+
test "$(git diff --cached --name-only --diff-filter=A -z $against |
33+
LC_ALL=C tr -d '[ -~]\0')"
34+
then
35+
echo "Error: Attempt to add a non-ascii file name."
36+
echo
37+
echo "This can cause problems if you want to work"
38+
echo "with people on other platforms."
39+
echo
40+
echo "To be portable it is advisable to rename the file ..."
41+
echo
42+
echo "If you know what you are doing you can disable this"
43+
echo "check using:"
44+
echo
45+
echo " git config hooks.allownonascii true"
46+
echo
47+
exit 1
48+
fi
49+
50+
eval node "./tools/astyle.js" $against

0 commit comments

Comments
 (0)