120 | 120 |
|
121 | 121 |
|
122 | 122 |
def _fileno_can_read(fileno):
|
123 | |
"""Check if a file descriptor is readable."""
|
|
123 |
"""Check if a file descriptor is readable.
|
|
124 |
"""
|
124 | 125 |
return len(select.select([fileno], [], [], 0)[0]) > 0
|
125 | 126 |
|
126 | 127 |
|
127 | 128 |
def _win32_peek_avail(handle):
|
128 | |
"""Wrapper around PeekNamedPipe to check how many bytes are available."""
|
|
129 |
"""Wrapper around PeekNamedPipe to check how many bytes are available.
|
|
130 |
"""
|
129 | 131 |
from ctypes import byref, wintypes, windll
|
130 | 132 |
c_avail = wintypes.DWORD()
|
131 | 133 |
c_message = wintypes.DWORD()
|
|
145 | 147 |
|
146 | 148 |
|
147 | 149 |
class ReportStatusParser(object):
|
148 | |
"""Handle status as reported by servers with 'report-status' capability.
|
149 | |
"""
|
|
150 |
"""Handle status as reported by servers with 'report-status' capability."""
|
150 | 151 |
|
151 | 152 |
def __init__(self):
|
152 | 153 |
self._done = False
|
|
157 | 158 |
def check(self):
|
158 | 159 |
"""Check if there were any errors and, if so, raise exceptions.
|
159 | 160 |
|
160 | |
:raise SendPackError: Raised when the server could not unpack
|
161 | |
:raise UpdateRefsError: Raised when refs could not be updated
|
|
161 |
Raises:
|
|
162 |
SendPackError: Raised when the server could not unpack
|
|
163 |
UpdateRefsError: Raised when refs could not be updated
|
162 | 164 |
"""
|
163 | 165 |
if self._pack_status not in (b'unpack ok', None):
|
164 | 166 |
raise SendPackError(self._pack_status)
|
|
186 | 188 |
def handle_packet(self, pkt):
|
187 | 189 |
"""Handle a packet.
|
188 | 190 |
|
189 | |
:raise GitProtocolError: Raised when packets are received after a
|
190 | |
flush packet.
|
|
191 |
Raises:
|
|
192 |
GitProtocolError: Raised when packets are received after a flush
|
|
193 |
packet.
|
191 | 194 |
"""
|
192 | 195 |
if self._done:
|
193 | 196 |
raise GitProtocolError("received more data after status report")
|
|
225 | 228 |
class FetchPackResult(object):
|
226 | 229 |
"""Result of a fetch-pack operation.
|
227 | 230 |
|
228 | |
:var refs: Dictionary with all remote refs
|
229 | |
:var symrefs: Dictionary with remote symrefs
|
230 | |
:var agent: User agent string
|
|
231 |
Attributes:
|
|
232 |
refs: Dictionary with all remote refs
|
|
233 |
symrefs: Dictionary with remote symrefs
|
|
234 |
agent: User agent string
|
231 | 235 |
"""
|
232 | 236 |
|
233 | 237 |
_FORWARDED_ATTRS = [
|
|
303 | 307 |
# support some capabilities. This should work properly with servers
|
304 | 308 |
# that don't support multi_ack.
|
305 | 309 |
class GitClient(object):
|
306 | |
"""Git smart server client.
|
307 | |
|
308 | |
"""
|
|
310 |
"""Git smart server client."""
|
309 | 311 |
|
310 | 312 |
def __init__(self, thin_packs=True, report_activity=None, quiet=False):
|
311 | 313 |
"""Create a new GitClient instance.
|
312 | 314 |
|
313 | |
:param thin_packs: Whether or not thin packs should be retrieved
|
314 | |
:param report_activity: Optional callback for reporting transport
|
|
315 |
Args:
|
|
316 |
thin_packs: Whether or not thin packs should be retrieved
|
|
317 |
report_activity: Optional callback for reporting transport
|
315 | 318 |
activity.
|
316 | 319 |
"""
|
317 | 320 |
self._report_activity = report_activity
|
|
328 | 331 |
def get_url(self, path):
|
329 | 332 |
"""Retrieves full url to given path.
|
330 | 333 |
|
331 | |
:param path: Repository path (as string)
|
332 | |
:return: Url to path (as string)
|
|
334 |
Args:
|
|
335 |
path: Repository path (as string)
|
|
336 |
|
|
337 |
Returns:
|
|
338 |
Url to path (as string)
|
|
339 |
|
333 | 340 |
"""
|
334 | 341 |
raise NotImplementedError(self.get_url)
|
335 | 342 |
|
|
337 | 344 |
def from_parsedurl(cls, parsedurl, **kwargs):
|
338 | 345 |
"""Create an instance of this client from a urlparse.parsed object.
|
339 | 346 |
|
340 | |
:param parsedurl: Result of urlparse.urlparse()
|
341 | |
:return: A `GitClient` object
|
|
347 |
Args:
|
|
348 |
parsedurl: Result of urlparse.urlparse()
|
|
349 |
|
|
350 |
Returns:
|
|
351 |
A `GitClient` object
|
342 | 352 |
"""
|
343 | 353 |
raise NotImplementedError(cls.from_parsedurl)
|
344 | 354 |
|
|
346 | 356 |
progress=None):
|
347 | 357 |
"""Upload a pack to a remote repository.
|
348 | 358 |
|
349 | |
:param path: Repository path (as bytestring)
|
350 | |
:param update_refs: Function to determine changes to remote refs.
|
351 | |
Receive dict with existing remote refs, returns dict with
|
|
359 |
Args:
|
|
360 |
path: Repository path (as bytestring)
|
|
361 |
update_refs: Function to determine changes to remote refs. Receive
|
|
362 |
dict with existing remote refs, returns dict with
|
352 | 363 |
changed refs (name -> sha, where sha=ZERO_SHA for deletions)
|
353 | |
:param generate_pack_data: Function that can return a tuple
|
|
364 |
generate_pack_data: Function that can return a tuple
|
354 | 365 |
with number of objects and list of pack data to include
|
355 | |
:param progress: Optional progress function
|
356 | |
|
357 | |
:raises SendPackError: if server rejects the pack data
|
358 | |
:raises UpdateRefsError: if the server supports report-status
|
359 | |
and rejects ref updates
|
360 | |
:return: new_refs dictionary containing the changes that were made
|
|
366 |
progress: Optional progress function
|
|
367 |
|
|
368 |
Returns:
|
|
369 |
new_refs dictionary containing the changes that were made
|
361 | 370 |
{refname: new_ref}, including deleted refs.
|
|
371 |
|
|
372 |
Raises:
|
|
373 |
SendPackError: if server rejects the pack data
|
|
374 |
UpdateRefsError: if the server supports report-status
|
|
375 |
and rejects ref updates
|
|
376 |
|
362 | 377 |
"""
|
363 | 378 |
raise NotImplementedError(self.send_pack)
|
364 | 379 |
|
|
366 | 381 |
depth=None):
|
367 | 382 |
"""Fetch into a target repository.
|
368 | 383 |
|
369 | |
:param path: Path to fetch from (as bytestring)
|
370 | |
:param target: Target repository to fetch into
|
371 | |
:param determine_wants: Optional function to determine what refs
|
372 | |
to fetch. Receives dictionary of name->sha, should return
|
|
384 |
Args:
|
|
385 |
path: Path to fetch from (as bytestring)
|
|
386 |
target: Target repository to fetch into
|
|
387 |
determine_wants: Optional function to determine what refs to fetch.
|
|
388 |
Receives dictionary of name->sha, should return
|
373 | 389 |
list of shas to fetch. Defaults to all shas.
|
374 | |
:param progress: Optional progress function
|
375 | |
:param depth: Depth to fetch at
|
376 | |
:return: Dictionary with all remote refs (not just those fetched)
|
|
390 |
progress: Optional progress function
|
|
391 |
depth: Depth to fetch at
|
|
392 |
|
|
393 |
Returns:
|
|
394 |
Dictionary with all remote refs (not just those fetched)
|
|
395 |
|
377 | 396 |
"""
|
378 | 397 |
if determine_wants is None:
|
379 | 398 |
determine_wants = target.object_store.determine_wants_all
|
|
407 | 426 |
progress=None, depth=None):
|
408 | 427 |
"""Retrieve a pack from a git smart server.
|
409 | 428 |
|
410 | |
:param path: Remote path to fetch from
|
411 | |
:param determine_wants: Function determine what refs
|
412 | |
to fetch. Receives dictionary of name->sha, should return
|
413 | |
list of shas to fetch.
|
414 | |
:param graph_walker: Object with next() and ack().
|
415 | |
:param pack_data: Callback called for each bit of data in the pack
|
416 | |
:param progress: Callback for progress reports (strings)
|
417 | |
:param depth: Shallow fetch depth
|
418 | |
:return: FetchPackResult object
|
|
429 |
Args:
|
|
430 |
path: Remote path to fetch from
|
|
431 |
determine_wants: Function determine what refs
|
|
432 |
to fetch. Receives dictionary of name->sha, should return
|
|
433 |
list of shas to fetch.
|
|
434 |
graph_walker: Object with next() and ack().
|
|
435 |
pack_data: Callback called for each bit of data in the pack
|
|
436 |
progress: Callback for progress reports (strings)
|
|
437 |
depth: Shallow fetch depth
|
|
438 |
|
|
439 |
Returns:
|
|
440 |
FetchPackResult object
|
|
441 |
|
419 | 442 |
"""
|
420 | 443 |
raise NotImplementedError(self.fetch_pack)
|
421 | 444 |
|
422 | 445 |
def get_refs(self, path):
|
423 | 446 |
"""Retrieve the current refs from a git smart server.
|
424 | 447 |
|
425 | |
:param path: Path to the repo to fetch from. (as bytestring)
|
|
448 |
Args:
|
|
449 |
path: Path to the repo to fetch from. (as bytestring)
|
|
450 |
|
|
451 |
Returns:
|
|
452 |
|
426 | 453 |
"""
|
427 | 454 |
raise NotImplementedError(self.get_refs)
|
428 | 455 |
|
|
468 | 495 |
|
469 | 496 |
This requires the side-band-64k capability.
|
470 | 497 |
|
471 | |
:param proto: Protocol object to read from
|
472 | |
:param channel_callbacks: Dictionary mapping channels to packet
|
|
498 |
Args:
|
|
499 |
proto: Protocol object to read from
|
|
500 |
channel_callbacks: Dictionary mapping channels to packet
|
473 | 501 |
handlers to use. None for a callback discards channel data.
|
474 | 502 |
"""
|
475 | 503 |
for pkt in proto.read_pkt_seq():
|
|
487 | 515 |
new_refs):
|
488 | 516 |
"""Handle the head of a 'git-receive-pack' request.
|
489 | 517 |
|
490 | |
:param proto: Protocol object to read from
|
491 | |
:param capabilities: List of negotiated capabilities
|
492 | |
:param old_refs: Old refs, as received from the server
|
493 | |
:param new_refs: Refs to change
|
494 | |
:return: (have, want) tuple
|
|
518 |
Args:
|
|
519 |
proto: Protocol object to read from
|
|
520 |
capabilities: List of negotiated capabilities
|
|
521 |
old_refs: Old refs, as received from the server
|
|
522 |
new_refs: Refs to change
|
|
523 |
|
|
524 |
Returns:
|
|
525 |
have, want) tuple
|
|
526 |
|
495 | 527 |
"""
|
496 | 528 |
want = []
|
497 | 529 |
have = [x for x in old_refs.values() if not x == ZERO_SHA]
|
|
535 | 567 |
def _handle_receive_pack_tail(self, proto, capabilities, progress=None):
|
536 | 568 |
"""Handle the tail of a 'git-receive-pack' request.
|
537 | 569 |
|
538 | |
:param proto: Protocol object to read from
|
539 | |
:param capabilities: List of negotiated capabilities
|
540 | |
:param progress: Optional progress reporting function
|
|
570 |
Args:
|
|
571 |
proto: Protocol object to read from
|
|
572 |
capabilities: List of negotiated capabilities
|
|
573 |
progress: Optional progress reporting function
|
|
574 |
|
|
575 |
Returns:
|
|
576 |
|
541 | 577 |
"""
|
542 | 578 |
if CAPABILITY_SIDE_BAND_64K in capabilities:
|
543 | 579 |
if progress is None:
|
|
578 | 614 |
wants, can_read, depth):
|
579 | 615 |
"""Handle the head of a 'git-upload-pack' request.
|
580 | 616 |
|
581 | |
:param proto: Protocol object to read from
|
582 | |
:param capabilities: List of negotiated capabilities
|
583 | |
:param graph_walker: GraphWalker instance to call .ack() on
|
584 | |
:param wants: List of commits to fetch
|
585 | |
:param can_read: function that returns a boolean that indicates
|
586 | |
whether there is extra graph data to read on proto
|
587 | |
:param depth: Depth for request
|
|
617 |
Args:
|
|
618 |
proto: Protocol object to read from
|
|
619 |
capabilities: List of negotiated capabilities
|
|
620 |
graph_walker: GraphWalker instance to call .ack() on
|
|
621 |
wants: List of commits to fetch
|
|
622 |
can_read: function that returns a boolean that indicates
|
|
623 |
whether there is extra graph data to read on proto
|
|
624 |
depth: Depth for request
|
|
625 |
|
|
626 |
Returns:
|
|
627 |
|
588 | 628 |
"""
|
589 | 629 |
assert isinstance(wants, list) and isinstance(wants[0], bytes)
|
590 | 630 |
proto.write_pkt_line(COMMAND_WANT + b' ' + wants[0] + b' ' +
|
|
632 | 672 |
pack_data, progress=None, rbufsize=_RBUFSIZE):
|
633 | 673 |
"""Handle the tail of a 'git-upload-pack' request.
|
634 | 674 |
|
635 | |
:param proto: Protocol object to read from
|
636 | |
:param capabilities: List of negotiated capabilities
|
637 | |
:param graph_walker: GraphWalker instance to call .ack() on
|
638 | |
:param pack_data: Function to call with pack data
|
639 | |
:param progress: Optional progress reporting function
|
640 | |
:param rbufsize: Read buffer size
|
|
675 |
Args:
|
|
676 |
proto: Protocol object to read from
|
|
677 |
capabilities: List of negotiated capabilities
|
|
678 |
graph_walker: GraphWalker instance to call .ack() on
|
|
679 |
pack_data: Function to call with pack data
|
|
680 |
progress: Optional progress reporting function
|
|
681 |
rbufsize: Read buffer size
|
|
682 |
|
|
683 |
Returns:
|
|
684 |
|
641 | 685 |
"""
|
642 | 686 |
pkt = proto.read_pkt_line()
|
643 | 687 |
while pkt:
|
|
669 | 713 |
def check_wants(wants, refs):
|
670 | 714 |
"""Check that a set of wants is valid.
|
671 | 715 |
|
672 | |
:param wants: Set of object SHAs to fetch
|
673 | |
:param refs: Refs dictionary to check against
|
|
716 |
Args:
|
|
717 |
wants: Set of object SHAs to fetch
|
|
718 |
refs: Refs dictionary to check against
|
|
719 |
|
|
720 |
Returns:
|
|
721 |
|
674 | 722 |
"""
|
675 | 723 |
missing = set(wants) - {
|
676 | 724 |
v for (k, v) in refs.items()
|
|
680 | 728 |
|
681 | 729 |
|
682 | 730 |
def remote_error_from_stderr(stderr):
|
683 | |
"""Return an appropriate exception based on stderr output. """
|
684 | 731 |
if stderr is None:
|
685 | 732 |
return HangupException()
|
686 | 733 |
for l in stderr.readlines():
|
|
709 | 756 |
for use and a can_read function which may be used to see if
|
710 | 757 |
reads would block.
|
711 | 758 |
|
712 | |
:param cmd: The git service name to which we should connect.
|
713 | |
:param path: The path we should pass to the service. (as bytestirng)
|
|
759 |
Args:
|
|
760 |
cmd: The git service name to which we should connect.
|
|
761 |
path: The path we should pass to the service. (as bytestirng)
|
714 | 762 |
"""
|
715 | 763 |
raise NotImplementedError()
|
716 | 764 |
|
|
718 | 766 |
progress=None):
|
719 | 767 |
"""Upload a pack to a remote repository.
|
720 | 768 |
|
721 | |
:param path: Repository path (as bytestring)
|
722 | |
:param update_refs: Function to determine changes to remote refs.
|
723 | |
Receive dict with existing remote refs, returns dict with
|
724 | |
changed refs (name -> sha, where sha=ZERO_SHA for deletions)
|
725 | |
:param generate_pack_data: Function that can return a tuple with
|
726 | |
number of objects and pack data to upload.
|
727 | |
:param progress: Optional callback called with progress updates
|
728 | |
|
729 | |
:raises SendPackError: if server rejects the pack data
|
730 | |
:raises UpdateRefsError: if the server supports report-status
|
731 | |
and rejects ref updates
|
732 | |
:return: new_refs dictionary containing the changes that were made
|
733 | |
{refname: new_ref}, including deleted refs.
|
|
769 |
Args:
|
|
770 |
path: Repository path (as bytestring)
|
|
771 |
update_refs: Function to determine changes to remote refs.
|
|
772 |
Receive dict with existing remote refs, returns dict with
|
|
773 |
changed refs (name -> sha, where sha=ZERO_SHA for deletions)
|
|
774 |
generate_pack_data: Function that can return a tuple with
|
|
775 |
number of objects and pack data to upload.
|
|
776 |
progress: Optional callback called with progress updates
|
|
777 |
|
|
778 |
Returns:
|
|
779 |
new_refs dictionary containing the changes that were made
|
|
780 |
{refname: new_ref}, including deleted refs.
|
|
781 |
|
|
782 |
Raises:
|
|
783 |
SendPackError: if server rejects the pack data
|
|
784 |
UpdateRefsError: if the server supports report-status
|
|
785 |
and rejects ref updates
|
|
786 |
|
734 | 787 |
"""
|
735 | 788 |
proto, unused_can_read, stderr = self._connect(b'receive-pack', path)
|
736 | 789 |
with proto:
|
|
797 | 850 |
progress=None, depth=None):
|
798 | 851 |
"""Retrieve a pack from a git smart server.
|
799 | 852 |
|
800 | |
:param path: Remote path to fetch from
|
801 | |
:param determine_wants: Function determine what refs
|
802 | |
to fetch. Receives dictionary of name->sha, should return
|
803 | |
list of shas to fetch.
|
804 | |
:param graph_walker: Object with next() and ack().
|
805 | |
:param pack_data: Callback called for each bit of data in the pack
|
806 | |
:param progress: Callback for progress reports (strings)
|
807 | |
:param depth: Shallow fetch depth
|
808 | |
:return: FetchPackResult object
|
|
853 |
Args:
|
|
854 |
path: Remote path to fetch from
|
|
855 |
determine_wants: Function determine what refs
|
|
856 |
to fetch. Receives dictionary of name->sha, should return
|
|
857 |
list of shas to fetch.
|
|
858 |
graph_walker: Object with next() and ack().
|
|
859 |
pack_data: Callback called for each bit of data in the pack
|
|
860 |
progress: Callback for progress reports (strings)
|
|
861 |
depth: Shallow fetch depth
|
|
862 |
|
|
863 |
Returns:
|
|
864 |
FetchPackResult object
|
|
865 |
|
809 | 866 |
"""
|
810 | 867 |
proto, can_read, stderr = self._connect(b'upload-pack', path)
|
811 | 868 |
with proto:
|
|
841 | 898 |
refs, symrefs, agent, new_shallow, new_unshallow)
|
842 | 899 |
|
843 | 900 |
def get_refs(self, path):
|
844 | |
"""Retrieve the current refs from a git smart server."""
|
|
901 |
"""Retrieve the current refs from a git smart server.
|
|
902 |
"""
|
845 | 903 |
# stock `git ls-remote` uses upload-pack
|
846 | 904 |
proto, _, stderr = self._connect(b'upload-pack', path)
|
847 | 905 |
with proto:
|
|
981 | 1039 |
|
982 | 1040 |
|
983 | 1041 |
def find_git_command():
|
984 | |
"""Find command to run for system Git (usually C Git).
|
985 | |
"""
|
|
1042 |
"""Find command to run for system Git (usually C Git)."""
|
986 | 1043 |
if sys.platform == 'win32': # support .exe, .bat and .cmd
|
987 | 1044 |
try: # to avoid overhead
|
988 | 1045 |
import win32api
|
|
1027 | 1084 |
def __init__(self, thin_packs=True, report_activity=None, config=None):
|
1028 | 1085 |
"""Create a new LocalGitClient instance.
|
1029 | 1086 |
|
1030 | |
:param thin_packs: Whether or not thin packs should be retrieved
|
1031 | |
:param report_activity: Optional callback for reporting transport
|
|
1087 |
Args:
|
|
1088 |
thin_packs: Whether or not thin packs should be retrieved
|
|
1089 |
report_activity: Optional callback for reporting transport
|
1032 | 1090 |
activity.
|
1033 | 1091 |
"""
|
1034 | 1092 |
self._report_activity = report_activity
|
|
1052 | 1110 |
progress=None):
|
1053 | 1111 |
"""Upload a pack to a remote repository.
|
1054 | 1112 |
|
1055 | |
:param path: Repository path (as bytestring)
|
1056 | |
:param update_refs: Function to determine changes to remote refs.
|
1057 | |
Receive dict with existing remote refs, returns dict with
|
1058 | |
changed refs (name -> sha, where sha=ZERO_SHA for deletions)
|
1059 | |
:param generate_pack_data: Function that can return a tuple
|
1060 | |
with number of items and pack data to upload.
|
1061 | |
:param progress: Optional progress function
|
1062 | |
|
1063 | |
:raises SendPackError: if server rejects the pack data
|
1064 | |
:raises UpdateRefsError: if the server supports report-status
|
1065 | |
and rejects ref updates
|
1066 | |
:return: new_refs dictionary containing the changes that were made
|
1067 | |
{refname: new_ref}, including deleted refs.
|
|
1113 |
Args:
|
|
1114 |
path: Repository path (as bytestring)
|
|
1115 |
update_refs: Function to determine changes to remote refs.
|
|
1116 |
Receive dict with existing remote refs, returns dict with
|
|
1117 |
changed refs (name -> sha, where sha=ZERO_SHA for deletions)
|
|
1118 |
generate_pack_data: Function that can return a tuple
|
|
1119 |
with number of items and pack data to upload.
|
|
1120 |
progress: Optional progress function
|
|
1121 |
|
|
1122 |
Returns:
|
|
1123 |
new_refs dictionary containing the changes that were made
|
|
1124 |
{refname: new_ref}, including deleted refs.
|
|
1125 |
|
|
1126 |
Raises:
|
|
1127 |
SendPackError: if server rejects the pack data
|
|
1128 |
UpdateRefsError: if the server supports report-status
|
|
1129 |
and rejects ref updates
|
|
1130 |
|
1068 | 1131 |
"""
|
1069 | 1132 |
if not progress:
|
1070 | 1133 |
def progress(x):
|
|
1106 | 1169 |
depth=None):
|
1107 | 1170 |
"""Fetch into a target repository.
|
1108 | 1171 |
|
1109 | |
:param path: Path to fetch from (as bytestring)
|
1110 | |
:param target: Target repository to fetch into
|
1111 | |
:param determine_wants: Optional function determine what refs
|
1112 | |
to fetch. Receives dictionary of name->sha, should return
|
1113 | |
list of shas to fetch. Defaults to all shas.
|
1114 | |
:param progress: Optional progress function
|
1115 | |
:param depth: Shallow fetch depth
|
1116 | |
:return: FetchPackResult object
|
|
1172 |
Args:
|
|
1173 |
path: Path to fetch from (as bytestring)
|
|
1174 |
target: Target repository to fetch into
|
|
1175 |
determine_wants: Optional function determine what refs
|
|
1176 |
to fetch. Receives dictionary of name->sha, should return
|
|
1177 |
list of shas to fetch. Defaults to all shas.
|
|
1178 |
progress: Optional progress function
|
|
1179 |
depth: Shallow fetch depth
|
|
1180 |
|
|
1181 |
Returns:
|
|
1182 |
FetchPackResult object
|
|
1183 |
|
1117 | 1184 |
"""
|
1118 | 1185 |
with self._open_repo(path) as r:
|
1119 | 1186 |
refs = r.fetch(target, determine_wants=determine_wants,
|
|
1125 | 1192 |
progress=None, depth=None):
|
1126 | 1193 |
"""Retrieve a pack from a git smart server.
|
1127 | 1194 |
|
1128 | |
:param path: Remote path to fetch from
|
1129 | |
:param determine_wants: Function determine what refs
|
1130 | |
to fetch. Receives dictionary of name->sha, should return
|
1131 | |
list of shas to fetch.
|
1132 | |
:param graph_walker: Object with next() and ack().
|
1133 | |
:param pack_data: Callback called for each bit of data in the pack
|
1134 | |
:param progress: Callback for progress reports (strings)
|
1135 | |
:param depth: Shallow fetch depth
|
1136 | |
:return: FetchPackResult object
|
|
1195 |
Args:
|
|
1196 |
path: Remote path to fetch from
|
|
1197 |
determine_wants: Function determine what refs
|
|
1198 |
to fetch. Receives dictionary of name->sha, should return
|
|
1199 |
list of shas to fetch.
|
|
1200 |
graph_walker: Object with next() and ack().
|
|
1201 |
pack_data: Callback called for each bit of data in the pack
|
|
1202 |
progress: Callback for progress reports (strings)
|
|
1203 |
depth: Shallow fetch depth
|
|
1204 |
|
|
1205 |
Returns:
|
|
1206 |
FetchPackResult object
|
|
1207 |
|
1137 | 1208 |
"""
|
1138 | 1209 |
with self._open_repo(path) as r:
|
1139 | 1210 |
objects_iter = r.fetch_objects(
|
|
1150 | 1221 |
return FetchPackResult(r.get_refs(), symrefs, agent)
|
1151 | 1222 |
|
1152 | 1223 |
def get_refs(self, path):
|
1153 | |
"""Retrieve the current refs from a git smart server."""
|
|
1224 |
"""Retrieve the current refs from a git smart server.
|
|
1225 |
"""
|
1154 | 1226 |
|
1155 | 1227 |
with self._open_repo(path) as target:
|
1156 | 1228 |
return target.get_refs()
|
|
1180 | 1252 |
Run a command remotely and return a file-like object for interaction
|
1181 | 1253 |
with the remote command.
|
1182 | 1254 |
|
1183 | |
:param host: Host name
|
1184 | |
:param command: Command to run (as argv array)
|
1185 | |
:param username: Optional ame of user to log in as
|
1186 | |
:param port: Optional SSH port to use
|
1187 | |
:param password: Optional ssh password for login or private key
|
1188 | |
:param key_filename: Optional path to private keyfile
|
|
1255 |
Args:
|
|
1256 |
host: Host name
|
|
1257 |
command: Command to run (as argv array)
|
|
1258 |
username: Optional ame of user to log in as
|
|
1259 |
port: Optional SSH port to use
|
|
1260 |
password: Optional ssh password for login or private key
|
|
1261 |
key_filename: Optional path to private keyfile
|
|
1262 |
|
|
1263 |
Returns:
|
|
1264 |
|
1189 | 1265 |
"""
|
1190 | 1266 |
raise NotImplementedError(self.run_command)
|
1191 | 1267 |
|
|
1347 | 1423 |
|
1348 | 1424 |
Honour detected proxy configurations.
|
1349 | 1425 |
|
1350 | |
:param config: `dulwich.config.ConfigDict` instance with Git configuration.
|
1351 | |
:param kwargs: Additional arguments for urllib3.ProxyManager
|
1352 | |
:return: `urllib3.ProxyManager` instance for proxy configurations,
|
1353 | |
`urllib3.PoolManager` otherwise.
|
|
1426 |
Args:
|
|
1427 |
config: dulwich.config.ConfigDict` instance with Git configuration.
|
|
1428 |
kwargs: Additional arguments for urllib3.ProxyManager
|
|
1429 |
|
|
1430 |
Returns:
|
|
1431 |
urllib3.ProxyManager` instance for proxy configurations,
|
|
1432 |
`urllib3.PoolManager` otherwise.
|
|
1433 |
|
1354 | 1434 |
"""
|
1355 | 1435 |
proxy_server = user_agent = None
|
1356 | 1436 |
ca_certs = ssl_verify = None
|
|
1477 | 1557 |
allow_compression=False):
|
1478 | 1558 |
"""Perform HTTP request.
|
1479 | 1559 |
|
1480 | |
:param url: Request URL.
|
1481 | |
:param headers: Optional custom headers to override defaults.
|
1482 | |
:param data: Request data.
|
1483 | |
:param allow_compression: Allow GZipped communication.
|
1484 | |
:return: Tuple (`response`, `read`), where response is an `urllib3`
|
1485 | |
response object with additional `content_type` and
|
1486 | |
`redirect_location` properties, and `read` is a consumable read
|
1487 | |
method for the response data.
|
|
1560 |
Args:
|
|
1561 |
url: Request URL.
|
|
1562 |
headers: Optional custom headers to override defaults.
|
|
1563 |
data: Request data.
|
|
1564 |
allow_compression: Allow GZipped communication.
|
|
1565 |
|
|
1566 |
Returns:
|
|
1567 |
Tuple (`response`, `read`), where response is an `urllib3`
|
|
1568 |
response object with additional `content_type` and
|
|
1569 |
`redirect_location` properties, and `read` is a consumable read
|
|
1570 |
method for the response data.
|
|
1571 |
|
1488 | 1572 |
"""
|
1489 | 1573 |
req_headers = self.pool_manager.headers.copy()
|
1490 | 1574 |
if headers is not None:
|
|
1575 | 1659 |
progress=None):
|
1576 | 1660 |
"""Upload a pack to a remote repository.
|
1577 | 1661 |
|
1578 | |
:param path: Repository path (as bytestring)
|
1579 | |
:param update_refs: Function to determine changes to remote refs.
|
1580 | |
Receive dict with existing remote refs, returns dict with
|
1581 | |
changed refs (name -> sha, where sha=ZERO_SHA for deletions)
|
1582 | |
:param generate_pack_data: Function that can return a tuple
|
1583 | |
with number of elements and pack data to upload.
|
1584 | |
:param progress: Optional progress function
|
1585 | |
|
1586 | |
:raises SendPackError: if server rejects the pack data
|
1587 | |
:raises UpdateRefsError: if the server supports report-status
|
1588 | |
and rejects ref updates
|
1589 | |
:return: new_refs dictionary containing the changes that were made
|
1590 | |
{refname: new_ref}, including deleted refs.
|
|
1662 |
Args:
|
|
1663 |
path: Repository path (as bytestring)
|
|
1664 |
update_refs: Function to determine changes to remote refs.
|
|
1665 |
Receive dict with existing remote refs, returns dict with
|
|
1666 |
changed refs (name -> sha, where sha=ZERO_SHA for deletions)
|
|
1667 |
generate_pack_data: Function that can return a tuple
|
|
1668 |
with number of elements and pack data to upload.
|
|
1669 |
progress: Optional progress function
|
|
1670 |
|
|
1671 |
Returns:
|
|
1672 |
new_refs dictionary containing the changes that were made
|
|
1673 |
{refname: new_ref}, including deleted refs.
|
|
1674 |
|
|
1675 |
Raises:
|
|
1676 |
SendPackError: if server rejects the pack data
|
|
1677 |
UpdateRefsError: if the server supports report-status
|
|
1678 |
and rejects ref updates
|
|
1679 |
|
1591 | 1680 |
"""
|
1592 | 1681 |
url = self._get_url(path)
|
1593 | 1682 |
old_refs, server_capabilities, url = self._discover_references(
|
|
1630 | 1719 |
progress=None, depth=None):
|
1631 | 1720 |
"""Retrieve a pack from a git smart server.
|
1632 | 1721 |
|
1633 | |
:param determine_wants: Callback that returns list of commits to fetch
|
1634 | |
:param graph_walker: Object with next() and ack().
|
1635 | |
:param pack_data: Callback called for each bit of data in the pack
|
1636 | |
:param progress: Callback for progress reports (strings)
|
1637 | |
:param depth: Depth for request
|
1638 | |
:return: FetchPackResult object
|
|
1722 |
Args:
|
|
1723 |
path: Path to fetch from
|
|
1724 |
determine_wants: Callback that returns list of commits to fetch
|
|
1725 |
graph_walker: Object with next() and ack().
|
|
1726 |
pack_data: Callback called for each bit of data in the pack
|
|
1727 |
progress: Callback for progress reports (strings)
|
|
1728 |
depth: Depth for request
|
|
1729 |
|
|
1730 |
Returns:
|
|
1731 |
FetchPackResult object
|
|
1732 |
|
1639 | 1733 |
"""
|
1640 | 1734 |
url = self._get_url(path)
|
1641 | 1735 |
refs, server_capabilities, url = self._discover_references(
|
|
1671 | 1765 |
resp.close()
|
1672 | 1766 |
|
1673 | 1767 |
def get_refs(self, path):
|
1674 | |
"""Retrieve the current refs from a git smart server."""
|
|
1768 |
"""Retrieve the current refs from a git smart server.
|
|
1769 |
"""
|
1675 | 1770 |
url = self._get_url(path)
|
1676 | 1771 |
refs, _, _ = self._discover_references(
|
1677 | 1772 |
b"git-upload-pack", url)
|
|
1681 | 1776 |
def get_transport_and_path_from_url(url, config=None, **kwargs):
|
1682 | 1777 |
"""Obtain a git client from a URL.
|
1683 | 1778 |
|
1684 | |
:param url: URL to open (a unicode string)
|
1685 | |
:param config: Optional config object
|
1686 | |
:param thin_packs: Whether or not thin packs should be retrieved
|
1687 | |
:param report_activity: Optional callback for reporting transport
|
|
1779 |
Args:
|
|
1780 |
url: URL to open (a unicode string)
|
|
1781 |
config: Optional config object
|
|
1782 |
thin_packs: Whether or not thin packs should be retrieved
|
|
1783 |
report_activity: Optional callback for reporting transport
|
1688 | 1784 |
activity.
|
1689 | |
:return: Tuple with client instance and relative path.
|
|
1785 |
|
|
1786 |
Returns:
|
|
1787 |
Tuple with client instance and relative path.
|
|
1788 |
|
1690 | 1789 |
"""
|
1691 | 1790 |
parsed = urlparse.urlparse(url)
|
1692 | 1791 |
if parsed.scheme == 'git':
|
|
1705 | 1804 |
|
1706 | 1805 |
|
1707 | 1806 |
def parse_rsync_url(location):
|
1708 | |
"""Parse a rsync-style URL."""
|
|
1807 |
"""Parse a rsync-style URL.
|
|
1808 |
"""
|
1709 | 1809 |
if ':' in location and '@' not in location:
|
1710 | 1810 |
# SSH with no user@, zero or one leading slash.
|
1711 | 1811 |
(host, path) = location.split(':', 1)
|
|
1726 | 1826 |
def get_transport_and_path(location, **kwargs):
|
1727 | 1827 |
"""Obtain a git client from a URL.
|
1728 | 1828 |
|
1729 | |
:param location: URL or path (a string)
|
1730 | |
:param config: Optional config object
|
1731 | |
:param thin_packs: Whether or not thin packs should be retrieved
|
1732 | |
:param report_activity: Optional callback for reporting transport
|
|
1829 |
Args:
|
|
1830 |
location: URL or path (a string)
|
|
1831 |
config: Optional config object
|
|
1832 |
thin_packs: Whether or not thin packs should be retrieved
|
|
1833 |
report_activity: Optional callback for reporting transport
|
1733 | 1834 |
activity.
|
1734 | |
:return: Tuple with client instance and relative path.
|
|
1835 |
|
|
1836 |
Returns:
|
|
1837 |
Tuple with client instance and relative path.
|
|
1838 |
|
1735 | 1839 |
"""
|
1736 | 1840 |
# First, try to parse it as a URL
|
1737 | 1841 |
try:
|