Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita3c89a5

Browse files
committed
Support repeated kwargs
Some Git command line options are allowed to be repeated multiple times.Examples of this are the -C flag which may occur more than once to"strengthen" its effect, or the -L flag on Git blames, to selectmultiple blocks of lines to blame. $ git diff -C -C HEAD~1 HEAD $ git blame -L 1-3 -L 12-18 HEAD -- somefile.pyThis patch supports passing a list/tuple as the value part for kwargs,so that the generated Git command contain the repeated options.
1 parent8bbf1a3 commita3c89a5

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

‎git/cmd.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -764,23 +764,31 @@ def custom_environment(self, **kwargs):
764764
finally:
765765
self.update_environment(**old_env)
766766

767+
deftransform_kwarg(self,name,value,split_single_char_options):
768+
iflen(name)==1:
769+
ifvalueisTrue:
770+
return ["-%s"%name]
771+
eliftype(value)isnotbool:
772+
ifsplit_single_char_options:
773+
return ["-%s"%name,"%s"%value]
774+
else:
775+
return ["-%s%s"% (name,value)]
776+
else:
777+
ifvalueisTrue:
778+
return ["--%s"%dashify(name)]
779+
eliftype(value)isnotbool:
780+
return ["--%s=%s"% (dashify(name),value)]
781+
return []
782+
767783
deftransform_kwargs(self,split_single_char_options=True,**kwargs):
768784
"""Transforms Python style kwargs into git command line options."""
769785
args=list()
770786
fork,vinkwargs.items():
771-
iflen(k)==1:
772-
ifvisTrue:
773-
args.append("-%s"%k)
774-
eliftype(v)isnotbool:
775-
ifsplit_single_char_options:
776-
args.extend(["-%s"%k,"%s"%v])
777-
else:
778-
args.append("-%s%s"% (k,v))
787+
ifisinstance(v, (list,tuple)):
788+
forvalueinv:
789+
args+=self.transform_kwarg(k,value,split_single_char_options)
779790
else:
780-
ifvisTrue:
781-
args.append("--%s"%dashify(k))
782-
eliftype(v)isnotbool:
783-
args.append("--%s=%s"% (dashify(k),v))
791+
args+=self.transform_kwarg(k,v,split_single_char_options)
784792
returnargs
785793

786794
@classmethod

‎git/test/test_git.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ def test_it_transforms_kwargs_into_git_command_arguments(self):
7070
assert_equal(["--max-count"],self.git.transform_kwargs(**{'max_count':True}))
7171
assert_equal(["--max-count=5"],self.git.transform_kwargs(**{'max_count':5}))
7272

73+
# Multiple args are supported by using lists/tuples
74+
assert_equal(["-L","1-3","-L","12-18"],self.git.transform_kwargs(**{'L': ('1-3','12-18')}))
75+
assert_equal(["-C","-C"],self.git.transform_kwargs(**{'C': [True,True]}))
76+
7377
# order is undefined
7478
res=self.git.transform_kwargs(**{'s':True,'t':True})
7579
assert ['-s','-t']==resor ['-t','-s']==res

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp