Kiln » Dependencies » Dulwich Read More
Clone URL:  
Pushed to one repository · View In Graph Contained in master-1, master-0, and 0.9.4

removed try catch finally block from GitClient.fetch() so it no longer catches errors that should (probably) be handled by code using the GitClient

created a function in HttpGitClient _http_request() which correctly
handles exceptions thrown by http errors such as 404 and 500.

In HttpGitClient modified _discover_references() and _smart_request() to
use the new _http_request() function, removing code that is common to both
functions.

Signed-off-by: Jelmer Vernooij <jelmer@samba.org>

Changeset 9fa05a292c10

Parent 8e4be44df92e

committed by Jelmer Vernooij

authored by Chris Reid

Changes to one file · Browse files at 9fa05a292c10 Showing diff from parent 8e4be44df92e Diff from another changeset...

Change 1 of 4 Show Entire File dulwich/​client.py Stacked
 
199
200
201
202
203
 
204
205
206
 
 
207
208
209
 
641
642
643
 
 
 
 
 
 
 
 
 
 
 
644
645
646
 
658
659
660
661
662
663
664
665
666
667
 
668
669
670
 
678
679
680
681
682
683
684
685
686
687
688
689
 
 
690
691
692
 
199
200
201
 
 
202
203
 
 
204
205
206
207
208
 
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
 
668
669
670
 
 
 
 
 
 
 
671
672
673
674
 
682
683
684
 
 
 
 
 
 
 
 
 
685
686
687
688
689
@@ -199,11 +199,10 @@
  if determine_wants is None:   determine_wants = target.object_store.determine_wants_all   f, commit = target.object_store.add_pack() - try: - return self.fetch_pack(path, determine_wants, + result = self.fetch_pack(path, determine_wants,   target.get_graph_walker(), f.write, progress) - finally: - commit() + commit() + return result     def fetch_pack(self, path, determine_wants, graph_walker, pack_data,   progress=None): @@ -641,6 +640,17 @@
  def _get_url(self, path):   return urlparse.urljoin(self.base_url, path).rstrip("/") + "/"   + def _http_request(self, url, headers={}, data=None): + req = urllib2.Request(url, headers=headers, data=data) + try: + resp = self._perform(req) + except urllib2.HTTPError as e: + if e.code == 404: + raise NotGitRepository() + if e.code != 200: + raise GitProtocolError("unexpected http response %d" % e.code) + return resp +   def _perform(self, req):   """Perform a HTTP request.   @@ -658,13 +668,7 @@
  if self.dumb != False:   url += "?service=%s" % service   headers["Content-Type"] = "application/x-%s-request" % service - req = urllib2.Request(url, headers=headers) - resp = self._perform(req) - if resp.getcode() == 404: - raise NotGitRepository() - if resp.getcode() != 200: - raise GitProtocolError("unexpected http response %d" % - resp.getcode()) + resp = self._http_request(url, headers)   self.dumb = (not resp.info().gettype().startswith("application/x-git-"))   proto = Protocol(resp.read, None)   if not self.dumb: @@ -678,15 +682,8 @@
  def _smart_request(self, service, url, data):   assert url[-1] == "/"   url = urlparse.urljoin(url, service) - req = urllib2.Request(url, - headers={"Content-Type": "application/x-%s-request" % service}, - data=data) - resp = self._perform(req) - if resp.getcode() == 404: - raise NotGitRepository() - if resp.getcode() != 200: - raise GitProtocolError("Invalid HTTP response from server: %d" - % resp.getcode()) + headers = {"Content-Type": "application/x-%s-request" % service} + resp = self._http_request(url, headers, data)   if resp.info().gettype() != ("application/x-%s-result" % service):   raise GitProtocolError("Invalid content-type from server: %s"   % resp.info().gettype())