Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
R
rust-rocksdb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fangzongwu
rust-rocksdb
Commits
511dd22f
Commit
511dd22f
authored
Mar 27, 2017
by
siddontang
Committed by
GitHub
Mar 27, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add rocksdb format tool and format code (#31)
parent
4bc4c325
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
181 additions
and
23 deletions
+181
-23
Makefile
Makefile
+2
-0
c.cc
librocksdb_sys/crocksdb/c.cc
+11
-15
format-diff.sh
librocksdb_sys/crocksdb/format-diff.sh
+160
-0
c.h
librocksdb_sys/crocksdb/rocksdb/c.h
+8
-8
No files found.
Makefile
View file @
511dd22f
...
...
@@ -27,6 +27,8 @@ format:
@
$
(
call format-code-in, .
)
@
$
(
call format-code-in, tests/test.rs
)
@
$
(
call format-code-in, librocksdb_sys
)
# User may not install clang-format-diff.py, ignore any error here.
@
librocksdb_sys/crocksdb/format-diff.sh
>
/dev/null
||
true
clean
:
@
cargo clean
...
...
librocksdb_sys/crocksdb/c.cc
View file @
511dd22f
...
...
@@ -2768,23 +2768,19 @@ void crocksdb_delete_file_in_range_cf(
void
crocksdb_free
(
void
*
ptr
)
{
free
(
ptr
);
}
crocksdb_logger_t
*
crocksdb_create_log_from_options
(
const
char
*
path
,
crocksdb_options_t
*
opts
,
char
**
errptr
)
{
crocksdb_logger_t
*
logger
=
new
crocksdb_logger_t
;
if
(
SaveError
(
errptr
,
CreateLoggerFromOptions
(
std
::
string
(
path
),
opts
->
rep
,
&
logger
->
rep
)))
{
delete
logger
;
return
NULL
;
}
crocksdb_logger_t
*
crocksdb_create_log_from_options
(
const
char
*
path
,
crocksdb_options_t
*
opts
,
char
**
errptr
)
{
crocksdb_logger_t
*
logger
=
new
crocksdb_logger_t
;
if
(
SaveError
(
errptr
,
CreateLoggerFromOptions
(
std
::
string
(
path
),
opts
->
rep
,
&
logger
->
rep
)))
{
delete
logger
;
return
NULL
;
}
return
logger
;
return
logger
;
}
void
crocksdb_log_destroy
(
crocksdb_logger_t
*
logger
)
{
delete
logger
;
}
void
crocksdb_log_destroy
(
crocksdb_logger_t
*
logger
)
{
delete
logger
;
}
}
// end extern "C"
librocksdb_sys/crocksdb/format-diff.sh
0 → 100755
View file @
511dd22f
#!/bin/bash
# BSD License
# For rocksdb software
# Copyright (c) 2011-present, Facebook, Inc.
# All rights reserved.
# ---------------------------------------------------------------------
# Copyright (c) 2011 The LevelDB Authors. All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# If clang_format_diff.py command is not specfied, we assume we are able to
# access directly without any path.
if
[
-z
$CLANG_FORMAT_DIFF
]
then
CLANG_FORMAT_DIFF
=
"clang-format-diff.py"
fi
# Check clang-format-diff.py
if
!
which
$CLANG_FORMAT_DIFF
&> /dev/null
then
echo
"You didn't have clang-format-diff.py and/or clang-format available in your computer!"
echo
"You can download clang-format-diff.py by running: "
echo
" curl --location http://goo.gl/iUW1u2 -o
${
CLANG_FORMAT_DIFF
}
"
echo
"You can download clang-format by running: "
echo
" brew install clang-format"
echo
"Then, move both files (i.e.
${
CLANG_FORMAT_DIFF
}
and clang-format) to some directory within PATH=
${
PATH
}
"
exit
128
fi
# Check argparse, a library that clang-format-diff.py requires.
python 2>/dev/null
<<
EOF
import argparse
EOF
if
[
"
$?
"
!=
0
]
then
echo
"To run clang-format-diff.py, we'll need the library "
argparse
" to be"
echo
"installed. You can try either of the follow ways to install it:"
echo
" 1. Manually download argparse: https://pypi.python.org/pypi/argparse"
echo
" 2. easy_install argparse (if you have easy_install)"
echo
" 3. pip install argparse (if you have pip)"
exit
129
fi
# TODO(kailiu) following work is not complete since we still need to figure
# out how to add the modified files done pre-commit hook to git's commit index.
#
# Check if this script has already been added to pre-commit hook.
# Will suggest user to add this script to pre-commit hook if their pre-commit
# is empty.
# PRE_COMMIT_SCRIPT_PATH="`git rev-parse --show-toplevel`/.git/hooks/pre-commit"
# if ! ls $PRE_COMMIT_SCRIPT_PATH &> /dev/null
# then
# echo "Would you like to add this script to pre-commit hook, which will do "
# echo -n "the format check for all the affected lines before you check in (y/n):"
# read add_to_hook
# if [ "$add_to_hook" == "y" ]
# then
# ln -s `git rev-parse --show-toplevel`/build_tools/format-diff.sh $PRE_COMMIT_SCRIPT_PATH
# fi
# fi
set
-e
uncommitted_code
=
`
git diff HEAD
`
LAST_MASTER
=
`
git merge-base master HEAD
`
# If there's no uncommitted changes, we assume user are doing post-commit
# format check, in which case we'll check the modified lines since last commit
# from master. Otherwise, we'll check format of the uncommitted code only.
if
[
-z
"
$uncommitted_code
"
]
then
# Check the format of last commit
diffs
=
$(
git diff
-U0
$LAST_MASTER
^ |
$CLANG_FORMAT_DIFF
-p
1
)
else
# Check the format of uncommitted lines,
diffs
=
$(
git diff
-U0
HEAD |
$CLANG_FORMAT_DIFF
-p
1
)
fi
if
[
-z
"
$diffs
"
]
then
echo
"Nothing needs to be reformatted!"
exit
0
fi
# Highlight the insertion/deletion from the clang-format-diff.py's output
COLOR_END
=
"
\0
33[0m"
COLOR_RED
=
"
\0
33[0;31m"
COLOR_GREEN
=
"
\0
33[0;32m"
echo
-e
"Detect lines that doesn't follow the format rules:
\r
"
# Add the color to the diff. lines added will be green; lines removed will be red.
echo
"
$diffs
"
|
sed
-e
"s/
\(
^-.*
$\
)/
`
echo
-e
\"
$COLOR_RED
\1
$COLOR_END
\"
`
/"
|
sed
-e
"s/
\(
^+.*
$\
)/
`
echo
-e
\"
$COLOR_GREEN
\1
$COLOR_END
\"
`
/"
if
[[
"
$OPT
"
==
*
"-DTRAVIS"
*
]]
then
exit
1
fi
# echo -e "Would you like to fix the format automatically (y/n): \c"
# # Make sure under any mode, we can read user input.
# exec < /dev/tty
# read to_fix
# if [ "$to_fix" != "y" ]
# then
# exit 1
# fi
# Do in-place format adjustment.
if
[
-z
"
$uncommitted_code
"
]
then
git diff
-U0
$LAST_MASTER
^ |
$CLANG_FORMAT_DIFF
-i
-p
1
else
git diff
-U0
HEAD^ |
$CLANG_FORMAT_DIFF
-i
-p
1
fi
echo
"Files reformatted!"
# Amend to last commit if user do the post-commit format check
if
[
-z
"
$uncommitted_code
"
]
;
then
echo
-e
"Would you like to amend the changes to last commit (
`
git log HEAD
--oneline
|
head
-1
`
)? (y/n):
\c
"
read
to_amend
if
[
"
$to_amend
"
==
"y"
]
then
git commit
-a
--amend
--reuse-message
HEAD
echo
"Amended to last commit"
fi
fi
librocksdb_sys/crocksdb/rocksdb/c.h
View file @
511dd22f
...
...
@@ -659,16 +659,16 @@ extern C_ROCKSDB_LIBRARY_API void crocksdb_options_set_max_write_buffer_number(
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_options_set_min_write_buffer_number_to_merge
(
crocksdb_options_t
*
,
int
);
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_options_set_max_write_buffer_number_to_maintain
(
crocksdb_options_t
*
,
int
);
crocksdb_options_set_max_write_buffer_number_to_maintain
(
crocksdb_options_t
*
,
int
);
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_options_set_max_background_compactions
(
crocksdb_options_t
*
,
int
);
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_options_set_base_background_compactions
(
crocksdb_options_t
*
,
int
);
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_options_set_max_background_flushes
(
crocksdb_options_t
*
,
int
);
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_options_set_max_log_file_size
(
crocksdb_options_t
*
,
size_t
);
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_options_set_max_log_file_size
(
crocksdb_options_t
*
,
size_t
);
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_options_set_log_file_time_to_roll
(
crocksdb_options_t
*
,
size_t
);
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_options_set_keep_log_file_num
(
...
...
@@ -1115,10 +1115,10 @@ extern C_ROCKSDB_LIBRARY_API void crocksdb_delete_file_in_range_cf(
// to free memory that was malloc()ed
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_free
(
void
*
ptr
);
extern
C_ROCKSDB_LIBRARY_API
crocksdb_logger_t
*
crocksdb_create_log_from_options
(
const
char
*
path
,
crocksdb_options_t
*
opts
,
char
**
errptr
);
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_log_destroy
(
crocksdb_logger_t
*
);
extern
C_ROCKSDB_LIBRARY_API
crocksdb_logger_t
*
crocksdb_create_log_from_options
(
const
char
*
path
,
crocksdb_options_t
*
opts
,
char
**
errptr
);
extern
C_ROCKSDB_LIBRARY_API
void
crocksdb_log_destroy
(
crocksdb_logger_t
*
);
#ifdef __cplusplus
}
/* end extern "C" */
#endif
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment