• Home
  • Raw
  • Download

Lines Matching +full:commits +full:-

3 #===- git-clang-format - ClangFormat Git Integration ---------*- python -*--===#
10 #===------------------------------------------------------------------------===#
13 clang-format git integration
16 This file provides a clang-format integration for git. Put it somewhere in your
17 path and ensure that it is executable. Then, "git clang-format" will invoke
18 clang-format on the changes in current files or a specific commit.
21 git clang-format -h
35 usage = 'git clang-format [OPTIONS] [<commit>] [<commit>] [--] [<file>...]'
38 If zero or one commits are given, run clang-format on all lines that differ
42 If two commits are given (requires --diff), run clang-format on all lines in the
45 The following git-config settings set the default of the corresponding option:
52 # Name of the temporary index file in which save the output of clang-format.
54 temp_index_basename = 'clang-format-index'
63 # In order to keep '--' yet allow options after positionals, we need to
64 # check for '--' ourselves. (Setting nargs='*' throws away the '--', while
68 idx = argv.index('--')
81 # Other languages that clang-format supports
91 p.add_argument('--binary',
92 default=config.get('clangformat.binary', 'clang-format'),
93 help='path to clang-format'),
94 p.add_argument('--commit',
97 p.add_argument('--diff', action='store_true',
99 p.add_argument('--extensions',
102 help=('comma-separated list of file extensions to format, '
103 'excluding the period and case-insensitive')),
104 p.add_argument('-f', '--force', action='store_true',
106 p.add_argument('-p', '--patch', action='store_true',
108 p.add_argument('-q', '--quiet', action='count', default=0,
110 p.add_argument('--style',
112 help='passed to clang-format'),
113 p.add_argument('-v', '--verbose', action='count', default=0,
124 opts.verbose -= opts.quiet
127 commits, files = interpret_args(opts.args, dash_dash, opts.commit)
128 if len(commits) > 1:
130 die('--diff is required when two commits are given')
132 if len(commits) > 2:
133 die('at most two commits allowed; %d given' % len(commits))
134 changed_lines = compute_diff_and_extract_lines(commits, files)
145 print 'Running clang-format on the following files:'
154 if len(commits) > 1:
155 old_tree = commits[1]
157 revision=commits[1],
170 print 'clang-format did not modify any files'
186 is a dictionary mapping option name (in lower case) to either "--bool" or
187 "--int"."""
191 for entry in run('git', 'config', '--list', '--null').split('\0'):
201 """Interpret `args` as "[commits] [--] [files]" and return (commits, files).
203 It is assumed that "--" and everything that follows has been removed from
206 If "--" is present (i.e., `dash_dash` is non-empty), the arguments to its
207 left (if present) are taken as commits. Otherwise, the arguments are checked
208 from left to right if they are commits or files. If commits are not given,
212 commits = [default_commit]
214 commits = args
215 for commit in commits:
224 commits = []
228 commits.append(args.pop(0))
229 if not commits:
230 commits = [default_commit]
233 commits = [default_commit]
235 return commits, files
242 run('git', 'rev-parse', value, verbose=False)
255 cmd = ['git', 'cat-file', '-t', value]
263 def compute_diff_and_extract_lines(commits, files): argument
265 diff_process = compute_diff(commits, files)
275 def compute_diff(commits, files): argument
276 """Return a subprocess object producing the diff from `commits`.
280 one was specified, or the difference between both specified commits, filtered
281 on `files` (if non-empty). Zero context lines are used in the patch."""
282 git_tool = 'diff-index'
283 if len(commits) > 1:
284 git_tool = 'diff-tree'
285 cmd = ['git', git_tool, '-p', '-U0'] + commits + ['--']
298 The input must have been produced with ``-U0``, meaning unidiff format with
306 match = re.search(r'^@@ -[0-9,]+ \+(\d+)(,(\d+))?', line)
331 toplevel = run('git', 'rev-parse', '--show-toplevel')
338 Returns the object ID (SHA-1) of the created tree."""
339 return create_tree(filenames, '--stdin')
343 binary='clang-format', style=None):
344 """Run clang-format on each file and save the result to a git tree.
346 Returns the object ID (SHA-1) of the created tree."""
355 return create_tree(index_info_generator(), '--index-info')
361 If mode is '--stdin', it must be a list of filenames. If mode is
362 '--index-info' is must be a list of values suitable for "git update-index
363 --index-info", such as "<mode> <SP> <sha1> <TAB> <filename>". Any other mode
365 assert mode in ('--stdin', '--index-info')
366 cmd = ['git', 'update-index', '--add', '-z', mode]
374 tree_id = run('git', 'write-tree')
379 binary='clang-format', style=None):
380 """Run clang-format on the given file and save the result to a git blob.
385 Returns the object ID (SHA-1) of the created blob."""
388 clang_format_cmd.extend(['-style='+style])
390 '-lines=%s:%s' % (start_line, start_line+line_count-1)
393 clang_format_cmd.extend(['-assume-filename='+filename])
394 git_show_cmd = ['git', 'cat-file', 'blob', '%s:%s' % (revision, filename)]
414 hash_object_cmd = ['git', 'hash-object', '-w', '--path='+filename, '--stdin']
450 gitdir = run('git', 'rev-parse', '--git-dir')
453 tree = '--empty'
454 run('git', 'read-tree', '--index-output='+path, tree)
460 # We use the porcelain 'diff' and not plumbing 'diff-tree' because the output
467 subprocess.check_call(['git', 'diff', '--diff-filter=M', old_tree, new_tree,
468 '--'])
475 `patch_mode`, runs `git checkout --patch` to select hunks interactively."""
476 changed_files = run('git', 'diff-tree', '--diff-filter=M', '-r', '-z',
477 '--name-only', old_tree,
480 unstaged_files = run('git', 'diff-files', '--name-status', *changed_files)
495 subprocess.check_call(['git', 'checkout', '--patch', new_tree])
499 run('git', 'checkout-index', '-a', '-f')