Skip to content

Commit d590bf3

Browse files
committed
Format codes
Signed-off-by: JaySon-Huang <tshent@qq.com>
1 parent 5ca0601 commit d590bf3

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

dbms/src/TiDB/Schema/TiDB.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -202,19 +202,10 @@ struct ColumnInfo
202202
#ifdef M
203203
#error "Please undefine macro M first."
204204
#endif
205-
#define M(f, v) \
206-
inline bool has##f##Flag() const \
207-
{ \
208-
return (flag & (v)) != 0; \
209-
} \
210-
inline void set##f##Flag() \
211-
{ \
212-
flag |= (v); \
213-
} \
214-
inline void clear##f##Flag() \
215-
{ \
216-
flag &= (~(v)); \
217-
}
205+
#define M(f, v) \
206+
inline bool has##f##Flag() const { return (flag & (v)) != 0; } \
207+
inline void set##f##Flag() { flag |= (v); } \
208+
inline void clear##f##Flag() { flag &= (~(v)); }
218209
COLUMN_FLAGS(M)
219210
#undef M
220211

format-diff.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,22 @@ def run_cmd(cmd, show_cmd=False):
2929
return res
3030

3131

32+
def try_find_clang_format(exec_path):
33+
candidates = ['clang-format-13']
34+
if exec_path is not None:
35+
candidates.insert(0, exec_path)
36+
for c in candidates:
37+
if which(c) is not None:
38+
return c
39+
return candidates[-1]
40+
41+
42+
def get_clang_format_version(clang_format_cmd):
43+
proc = subprocess.run([clang_format_cmd, '--version'], capture_output=True, text=True, check=True)
44+
clang_format_version = proc.stdout.strip()
45+
return clang_format_version
46+
47+
3248
def main():
3349
default_suffix = ['.cpp', '.h', '.cc', '.hpp']
3450
parser = argparse.ArgumentParser(description='TiFlash Code Format',
@@ -45,6 +61,8 @@ def main():
4561
help='exit -1 if NOT formatted', action='store_true')
4662
parser.add_argument('--dump_diff_files_to',
4763
help='dump diff file names to specific path', default=None)
64+
parser.add_argument('--clang_format',
65+
help='path to clang-format', default=None)
4866

4967
args = parser.parse_args()
5068
default_suffix = args.suffix.strip().split(' ') if args.suffix else []
@@ -82,10 +100,10 @@ def main():
82100
len(da), args.dump_diff_files_to))
83101

84102
if files_to_format:
103+
clang_format_cmd = try_find_clang_format(args.clang_format)
104+
clang_format_version = get_clang_format_version(clang_format_cmd)
105+
print('Using {}'.format(clang_format_version))
85106
print('Files to format:\n {}'.format('\n '.join(files_to_format)))
86-
clang_format_cmd = 'clang-format-13'
87-
if which(clang_format_cmd) is None:
88-
clang_format_cmd = 'clang-format'
89107
for file in files_to_format:
90108
cmd = clang_format_cmd + ' -i {}'.format(file)
91109
if subprocess.Popen(cmd, shell=True, cwd=tiflash_repo_path).wait():

0 commit comments

Comments
 (0)