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

Commitb67bd4c

Browse files
committed
Improved archive function by allowing it to directly write to an output stream - previously it would cache everything to memory and try to provide zipping functionality itself
gitcmd: allows the output stream to be set explicitly which is mainly useful for archiving operations
1 parent00c5497 commitb67bd4c

File tree

4 files changed

+58
-62
lines changed

4 files changed

+58
-62
lines changed

‎CHANGES‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ Repo
6464
- commits to iter_commits to improve the performance, adjusted signature
6565
- init_bare to init, implying less about the options to be used
6666
- fork_bare to clone, as it was to represent general clone functionality, but implied
67-
a bare clone
68-
to be more versatile
67+
a bare clone to be more versatile
68+
- archive_tar_gz and archive_tar and replaced by archive method with different signature
6969
* 'commits' method has no max-count of returned commits anymore, it now behaves
7070
like git-rev-list
7171

‎lib/git/cmd.py‎

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
GIT_PYTHON_TRACE=os.environ.get("GIT_PYTHON_TRACE",False)
1414

1515
execute_kwargs= ('istream','with_keep_cwd','with_extended_output',
16-
'with_exceptions','with_raw_output','as_process')
16+
'with_exceptions','with_raw_output','as_process',
17+
'output_stream' )
1718

1819
extra= {}
1920
ifsys.platform=='win32':
@@ -102,7 +103,8 @@ def execute(self, command,
102103
with_extended_output=False,
103104
with_exceptions=True,
104105
with_raw_output=False,
105-
as_process=False
106+
as_process=False,
107+
output_stream=None
106108
):
107109
"""
108110
Handles executing the command on the shell and consumes and returns
@@ -130,16 +132,20 @@ def execute(self, command,
130132
``with_raw_output``
131133
Whether to avoid stripping off trailing whitespace.
132134
133-
``as_process``
134-
Whether to return the created process instance directly from which
135-
streams can be read on demand. This will render with_extended_output,
136-
with_exceptions and with_raw_output ineffective - the caller will have
137-
to deal with the details himself.
138-
It is important to note that the process will be placed into an AutoInterrupt
139-
wrapper that will interrupt the process once it goes out of scope. If you
140-
use the command in iterators, you should pass the whole process instance
141-
instead of a single stream.
142-
135+
``as_process``
136+
Whether to return the created process instance directly from which
137+
streams can be read on demand. This will render with_extended_output,
138+
with_exceptions and with_raw_output ineffective - the caller will have
139+
to deal with the details himself.
140+
It is important to note that the process will be placed into an AutoInterrupt
141+
wrapper that will interrupt the process once it goes out of scope. If you
142+
use the command in iterators, you should pass the whole process instance
143+
instead of a single stream.
144+
``output_stream``
145+
If set to a file-like object, data produced by the git command will be
146+
output to the given stream directly.
147+
Otherwise a new file will be opened.
148+
143149
Returns::
144150
145151
str(output) # extended_output = False (Default)
@@ -160,13 +166,17 @@ def execute(self, command,
160166
cwd=os.getcwd()
161167
else:
162168
cwd=self.git_dir
169+
170+
ostream=subprocess.PIPE
171+
ifoutput_streamisnotNone:
172+
ostream=output_stream
163173

164174
# Start the process
165175
proc=subprocess.Popen(command,
166176
cwd=cwd,
167177
stdin=istream,
168178
stderr=subprocess.PIPE,
169-
stdout=subprocess.PIPE,
179+
stdout=ostream,
170180
**extra
171181
)
172182

‎lib/git/repo.py‎

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -456,48 +456,27 @@ def clone(self, path, **kwargs):
456456
self.git.clone(self.path,path,**kwargs)
457457
returnRepo(path)
458458

459-
defarchive_tar(self,treeish='master',prefix=None):
460-
"""
461-
Archive the given treeish
462-
463-
``treeish``
464-
is the treeish name/id (default 'master')
465-
466-
``prefix``
467-
is the optional prefix to prepend to each filename in the archive
468-
469-
Examples::
470-
471-
>>> repo.archive_tar
472-
<String containing tar archive>
473-
474-
>>> repo.archive_tar('a87ff14')
475-
<String containing tar archive for commit a87ff14>
476459

477-
>>> repo.archive_tar('master', 'myproject/')
478-
<String containing tar bytes archive, whose files are prefixed with 'myproject/'>
479-
480-
Returns
481-
str (containing bytes of tar archive)
460+
defarchive(self,ostream,treeish=None,prefix=None,**kwargs):
482461
"""
483-
options= {}
484-
ifprefix:
485-
options['prefix']=prefix
486-
returnself.git.archive(treeish,**options)
487-
488-
defarchive_tar_gz(self,treeish='master',prefix=None):
489-
"""
490-
Archive and gzip the given treeish
462+
Archive the tree at the given revision.
463+
``ostream``
464+
file compatible stream object to which the archive will be written
491465
492466
``treeish``
493-
is the treeish name/id (default 'master')
467+
is the treeish name/id, defaults to active branch
494468
495469
``prefix``
496470
is the optional prefix to prepend to each filename in the archive
471+
472+
``kwargs``
473+
Additional arguments passed to git-archive
474+
NOTE: Use the 'format' argument to define the kind of format. Use
475+
specialized ostreams to write any format supported by python
497476
498477
Examples::
499478
500-
>>> repo.archive_tar_gz
479+
>>> repo.archive(open("archive"
501480
<String containing tar.gz archive>
502481
503482
>>> repo.archive_tar_gz('a87ff14')
@@ -506,18 +485,22 @@ def archive_tar_gz(self, treeish='master', prefix=None):
506485
>>> repo.archive_tar_gz('master', 'myproject/')
507486
<String containing tar.gz archive and prefixed with 'myproject/'>
508487
509-
Returns
510-
str (containing the bytes of tar.gz archive)
488+
Raise
489+
GitCommandError in case something went wrong
490+
511491
"""
512-
kwargs= {}
513-
ifprefix:
492+
iftreeishisNone:
493+
treeish=self.active_branch
494+
ifprefixand'prefix'notinkwargs:
514495
kwargs['prefix']=prefix
515-
resultstr=self.git.archive(treeish,**kwargs)
516-
sio=StringIO.StringIO()
517-
gf=gzip.GzipFile(fileobj=sio,mode='wb')
518-
gf.write(resultstr)
519-
gf.close()
520-
returnsio.getvalue()
496+
kwargs['as_process']=True
497+
kwargs['output_stream']=ostream
498+
499+
proc=self.git.archive(treeish,**kwargs)
500+
status=proc.wait()
501+
ifstatus!=0:
502+
raiseGitCommandError("git-archive",status,proc.stderr.read() )
503+
521504

522505

523506
def__repr__(self):

‎test/git/test_repo.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,14 @@ def test_diff_with_parents(self, git):
141141
assert_equal(15,len(diffs))
142142
assert_true(git.called)
143143

144-
deftest_archive_tar(self):
145-
assertself.repo.archive_tar()
146-
147-
deftest_archive_tar_gz(self):
148-
assertself.repo.archive_tar_gz()
144+
deftest_archive(self):
145+
args= (tuple(), (self.repo.heads[-1],),(None,"hello") )
146+
forarg_listinargs:
147+
ftmp=os.tmpfile()
148+
self.repo.archive(ftmp,*arg_list)
149+
ftmp.seek(0,2)
150+
assertftmp.tell()
151+
# END for each arg-list
149152

150153
@patch('git.utils.touch')
151154
deftest_enable_daemon_serve(self,touch):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp