summaryrefslogtreecommitdiff
path: root/git/remote.py
diff options
context:
space:
mode:
Diffstat (limited to 'git/remote.py')
-rw-r--r--git/remote.py50
1 files changed, 27 insertions, 23 deletions
diff --git a/git/remote.py b/git/remote.py
index 44b7ffaa..484bc031 100644
--- a/git/remote.py
+++ b/git/remote.py
@@ -5,33 +5,35 @@
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
# Module implementing a remote object allowing easy access to git remotes
+import re
+import os
-from exc import GitCommandError
-from ConfigParser import NoOptionError
-from config import SectionConstraint
-
-from git.util import (
- LazyMixin,
- Iterable,
- IterableList,
- RemoteProgress
+from .exc import GitCommandError
+from .config import (
+ SectionConstraint,
+ cp,
)
-
-from refs import (
+from .refs import (
Reference,
RemoteReference,
SymbolicReference,
TagReference
)
+
+from git.util import (
+ LazyMixin,
+ Iterable,
+ IterableList,
+ RemoteProgress
+)
from git.util import (
join_path,
finalize_process
)
from gitdb.util import join
+from git.compat import defenc
-import re
-import os
__all__ = ('RemoteProgress', 'PushInfo', 'FetchInfo', 'Remote')
@@ -45,16 +47,16 @@ def digest_process_messages(fh, progress):
:param fh: File handle to read from
:return: list(line, ...) list of lines without linebreaks that did
not contain progress information"""
- line_so_far = ''
+ line_so_far = b''
dropped_lines = list()
while True:
- char = fh.read(1)
+ char = fh.read(1) # reads individual single byte strings
if not char:
break
- if char in ('\r', '\n') and line_so_far:
- dropped_lines.extend(progress._parse_progress_line(line_so_far))
- line_so_far = ''
+ if char in (b'\r', b'\n') and line_so_far:
+ dropped_lines.extend(progress._parse_progress_line(line_so_far.decode(defenc)))
+ line_so_far = b''
else:
line_so_far += char
# END process parsed line
@@ -136,7 +138,7 @@ class PushInfo(object):
@classmethod
def _from_line(cls, remote, line):
"""Create a new PushInfo instance as parsed from line which is expected to be like
- refs/heads/master:refs/heads/master 05d2687..1d0568e"""
+ refs/heads/master:refs/heads/master 05d2687..1d0568e as bytes"""
control_character, from_to, summary = line.split('\t', 3)
flags = 0
@@ -390,7 +392,7 @@ class Remote(LazyMixin, Iterable):
# even though a slot of the same name exists
try:
return self._config_reader.get(attr)
- except NoOptionError:
+ except cp.NoOptionError:
return super(Remote, self).__getattr__(attr)
# END handle exception
@@ -520,6 +522,7 @@ class Remote(LazyMixin, Iterable):
def _get_fetch_info_from_stderr(self, proc, progress):
# skip first line as it is some remote info we are not interested in
+ # TODO: Use poll() to process stdout and stderr at same time
output = IterableList('name')
# lines which are no progress are fetch info lines
@@ -542,8 +545,8 @@ class Remote(LazyMixin, Iterable):
# END for each line
# read head information
- fp = open(join(self.repo.git_dir, 'FETCH_HEAD'), 'r')
- fetch_head_info = fp.readlines()
+ fp = open(join(self.repo.git_dir, 'FETCH_HEAD'), 'rb')
+ fetch_head_info = [l.decode(defenc) for l in fp.readlines()]
fp.close()
# NOTE: We assume to fetch at least enough progress lines to allow matching each fetch head line with it.
@@ -560,10 +563,12 @@ class Remote(LazyMixin, Iterable):
# we hope stdout can hold all the data, it should ...
# read the lines manually as it will use carriage returns between the messages
# to override the previous one. This is why we read the bytes manually
+ # TODO: poll() on file descriptors to know what to read next, process streams concurrently
digest_process_messages(proc.stderr, progress)
output = IterableList('name')
for line in proc.stdout.readlines():
+ line = line.decode(defenc)
try:
output.append(PushInfo._from_line(self, line))
except ValueError:
@@ -571,7 +576,6 @@ class Remote(LazyMixin, Iterable):
pass
# END exception handling
# END for each line
-
finalize_process(proc)
return output