Dulwich.io dulwich / 9a402c5
Initial work migrating docstrings to google style. Jelmer Vernooń≥ 19 days ago
3 changed file(s) with 323 addition(s) and 204 deletion(s). Raw diff Collapse all Expand all
7474 pieces (bytestrings). To obtain the complete .tar.gz binary file, simply
7575 concatenate these chunks.
7676
77 :param store: Object store to retrieve objects from
78 :param tree: Tree object for the tree root
79 :param mtime: UNIX timestamp that is assigned as the modification time for
77 Args:
78 store: Object store to retrieve objects from
79 tree: Tree object for the tree root
80 mtime: UNIX timestamp that is assigned as the modification time for
8081 all files, and the gzip header modification time if format='gz'
81 :param format: Optional compression format for tarball
82 :return: Bytestrings
82 format: Optional compression format for tarball
83 Returns:
84 Bytestrings
8385 """
8486 buf = BytesIO()
8587 with closing(tarfile.open(None, "w:%s" % format, buf)) as tar:
120120
121121
122122 def _fileno_can_read(fileno):
123 """Check if a file descriptor is readable."""
123 """Check if a file descriptor is readable.
124 """
124125 return len(select.select([fileno], [], [], 0)[0]) > 0
125126
126127
127128 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 """
129131 from ctypes import byref, wintypes, windll
130132 c_avail = wintypes.DWORD()
131133 c_message = wintypes.DWORD()
145147
146148
147149 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."""
150151
151152 def __init__(self):
152153 self._done = False
157158 def check(self):
158159 """Check if there were any errors and, if so, raise exceptions.
159160
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
162164 """
163165 if self._pack_status not in (b'unpack ok', None):
164166 raise SendPackError(self._pack_status)
186188 def handle_packet(self, pkt):
187189 """Handle a packet.
188190
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.
191194 """
192195 if self._done:
193196 raise GitProtocolError("received more data after status report")
225228 class FetchPackResult(object):
226229 """Result of a fetch-pack operation.
227230
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
231235 """
232236
233237 _FORWARDED_ATTRS = [
303307 # support some capabilities. This should work properly with servers
304308 # that don't support multi_ack.
305309 class GitClient(object):
306 """Git smart server client.
307
308 """
310 """Git smart server client."""
309311
310312 def __init__(self, thin_packs=True, report_activity=None, quiet=False):
311313 """Create a new GitClient instance.
312314
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
315318 activity.
316319 """
317320 self._report_activity = report_activity
328331 def get_url(self, path):
329332 """Retrieves full url to given path.
330333
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
333340 """
334341 raise NotImplementedError(self.get_url)
335342
337344 def from_parsedurl(cls, parsedurl, **kwargs):
338345 """Create an instance of this client from a urlparse.parsed object.
339346
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
342352 """
343353 raise NotImplementedError(cls.from_parsedurl)
344354
346356 progress=None):
347357 """Upload a pack to a remote repository.
348358
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
352363 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
354365 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
361370 {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
362377 """
363378 raise NotImplementedError(self.send_pack)
364379
366381 depth=None):
367382 """Fetch into a target repository.
368383
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
373389 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
377396 """
378397 if determine_wants is None:
379398 determine_wants = target.object_store.determine_wants_all
407426 progress=None, depth=None):
408427 """Retrieve a pack from a git smart server.
409428
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
419442 """
420443 raise NotImplementedError(self.fetch_pack)
421444
422445 def get_refs(self, path):
423446 """Retrieve the current refs from a git smart server.
424447
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
426453 """
427454 raise NotImplementedError(self.get_refs)
428455
468495
469496 This requires the side-band-64k capability.
470497
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
473501 handlers to use. None for a callback discards channel data.
474502 """
475503 for pkt in proto.read_pkt_seq():
487515 new_refs):
488516 """Handle the head of a 'git-receive-pack' request.
489517
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
495527 """
496528 want = []
497529 have = [x for x in old_refs.values() if not x == ZERO_SHA]
535567 def _handle_receive_pack_tail(self, proto, capabilities, progress=None):
536568 """Handle the tail of a 'git-receive-pack' request.
537569
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
541577 """
542578 if CAPABILITY_SIDE_BAND_64K in capabilities:
543579 if progress is None:
578614 wants, can_read, depth):
579615 """Handle the head of a 'git-upload-pack' request.
580616
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
588628 """
589629 assert isinstance(wants, list) and isinstance(wants[0], bytes)
590630 proto.write_pkt_line(COMMAND_WANT + b' ' + wants[0] + b' ' +
632672 pack_data, progress=None, rbufsize=_RBUFSIZE):
633673 """Handle the tail of a 'git-upload-pack' request.
634674
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
641685 """
642686 pkt = proto.read_pkt_line()
643687 while pkt:
669713 def check_wants(wants, refs):
670714 """Check that a set of wants is valid.
671715
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
674722 """
675723 missing = set(wants) - {
676724 v for (k, v) in refs.items()
680728
681729
682730 def remote_error_from_stderr(stderr):
683 """Return an appropriate exception based on stderr output. """
684731 if stderr is None:
685732 return HangupException()
686733 for l in stderr.readlines():
709756 for use and a can_read function which may be used to see if
710757 reads would block.
711758
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)
714762 """
715763 raise NotImplementedError()
716764
718766 progress=None):
719767 """Upload a pack to a remote repository.
720768
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
734787 """
735788 proto, unused_can_read, stderr = self._connect(b'receive-pack', path)
736789 with proto:
797850 progress=None, depth=None):
798851 """Retrieve a pack from a git smart server.
799852
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
809866 """
810867 proto, can_read, stderr = self._connect(b'upload-pack', path)
811868 with proto:
841898 refs, symrefs, agent, new_shallow, new_unshallow)
842899
843900 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 """
845903 # stock `git ls-remote` uses upload-pack
846904 proto, _, stderr = self._connect(b'upload-pack', path)
847905 with proto:
9811039
9821040
9831041 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)."""
9861043 if sys.platform == 'win32': # support .exe, .bat and .cmd
9871044 try: # to avoid overhead
9881045 import win32api
10271084 def __init__(self, thin_packs=True, report_activity=None, config=None):
10281085 """Create a new LocalGitClient instance.
10291086
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
10321090 activity.
10331091 """
10341092 self._report_activity = report_activity
10521110 progress=None):
10531111 """Upload a pack to a remote repository.
10541112
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
10681131 """
10691132 if not progress:
10701133 def progress(x):
11061169 depth=None):
11071170 """Fetch into a target repository.
11081171
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
11171184 """
11181185 with self._open_repo(path) as r:
11191186 refs = r.fetch(target, determine_wants=determine_wants,
11251192 progress=None, depth=None):
11261193 """Retrieve a pack from a git smart server.
11271194
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
11371208 """
11381209 with self._open_repo(path) as r:
11391210 objects_iter = r.fetch_objects(
11501221 return FetchPackResult(r.get_refs(), symrefs, agent)
11511222
11521223 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 """
11541226
11551227 with self._open_repo(path) as target:
11561228 return target.get_refs()
11801252 Run a command remotely and return a file-like object for interaction
11811253 with the remote command.
11821254
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
11891265 """
11901266 raise NotImplementedError(self.run_command)
11911267
13471423
13481424 Honour detected proxy configurations.
13491425
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
13541434 """
13551435 proxy_server = user_agent = None
13561436 ca_certs = ssl_verify = None
14771557 allow_compression=False):
14781558 """Perform HTTP request.
14791559
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
14881572 """
14891573 req_headers = self.pool_manager.headers.copy()
14901574 if headers is not None:
15751659 progress=None):
15761660 """Upload a pack to a remote repository.
15771661
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
15911680 """
15921681 url = self._get_url(path)
15931682 old_refs, server_capabilities, url = self._discover_references(
16301719 progress=None, depth=None):
16311720 """Retrieve a pack from a git smart server.
16321721
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
16391733 """
16401734 url = self._get_url(path)
16411735 refs, server_capabilities, url = self._discover_references(
16711765 resp.close()
16721766
16731767 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 """
16751770 url = self._get_url(path)
16761771 refs, _, _ = self._discover_references(
16771772 b"git-upload-pack", url)
16811776 def get_transport_and_path_from_url(url, config=None, **kwargs):
16821777 """Obtain a git client from a URL.
16831778
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
16881784 activity.
1689 :return: Tuple with client instance and relative path.
1785
1786 Returns:
1787 Tuple with client instance and relative path.
1788
16901789 """
16911790 parsed = urlparse.urlparse(url)
16921791 if parsed.scheme == 'git':
17051804
17061805
17071806 def parse_rsync_url(location):
1708 """Parse a rsync-style URL."""
1807 """Parse a rsync-style URL.
1808 """
17091809 if ':' in location and '@' not in location:
17101810 # SSH with no user@, zero or one leading slash.
17111811 (host, path) = location.split(':', 1)
17261826 def get_transport_and_path(location, **kwargs):
17271827 """Obtain a git client from a URL.
17281828
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
17331834 activity.
1734 :return: Tuple with client instance and relative path.
1835
1836 Returns:
1837 Tuple with client instance and relative path.
1838
17351839 """
17361840 # First, try to parse it as a URL
17371841 try:
118118 def get(self, section, name):
119119 """Retrieve the contents of a configuration setting.
120120
121 :param section: Tuple with section name and optional subsection namee
122 :param subsection: Subsection name
123 :return: Contents of the setting
124 :raise KeyError: if the value is not set
121 Args:
122 section: Tuple with section name and optional subsection namee
123 subsection: Subsection name
124 Returns:
125 Contents of the setting
126 Raises:
127 KeyError: if the value is not set
125128 """
126129 raise NotImplementedError(self.get)
127130
128131 def get_boolean(self, section, name, default=None):
129132 """Retrieve a configuration setting as boolean.
130133
131 :param section: Tuple with section name and optional subsection name
132 :param name: Name of the setting, including section and possible
134 Args:
135 section: Tuple with section name and optional subsection name
136 name: Name of the setting, including section and possible
133137 subsection.
134 :return: Contents of the setting
135 :raise KeyError: if the value is not set
138 Returns:
139 Contents of the setting
140 Raises:
141 KeyError: if the value is not set
136142 """
137143 try:
138144 value = self.get(section, name)
147153 def set(self, section, name, value):
148154 """Set a configuration value.
149155
150 :param section: Tuple with section name and optional subsection namee
151 :param name: Name of the configuration value, including section
156 Args:
157 section: Tuple with section name and optional subsection namee
158 name: Name of the configuration value, including section
152159 and optional subsection
153 :param: Value of the setting
160 value: value of the setting
154161 """
155162 raise NotImplementedError(self.set)
156163
157164 def iteritems(self, section):
158165 """Iterate over the configuration pairs for a specific section.
159166
160 :param section: Tuple with section name and optional subsection namee
161 :return: Iterator over (name, value) pairs
167 Args:
168 section: Tuple with section name and optional subsection namee
169 Returns:
170 Iterator over (name, value) pairs
162171 """
163172 raise NotImplementedError(self.iteritems)
164173
172181 def has_section(self, name):
173182 """Check if a specified section exists.
174183
175 :param name: Name of section to check for
176 :return: boolean indicating whether the section exists
184 Args:
185 name: Name of section to check for
186 Returns:
187 boolean indicating whether the section exists
177188 """
178189 return (name in self.itersections())
179190
537548 def parse_submodules(config):
538549 """Parse a gitmodules GitConfig file, returning submodules.
539550
540 :param config: A `ConfigFile`
541 :return: list of tuples (submodule path, url, name),
551 Args:
552 config: A `ConfigFile`
553 Returns:
554 list of tuples (submodule path, url, name),
542555 where name is quoted part of the section's name.
543556 """
544557 for section in config.keys():