From f6aa8d116eb33293c0a9d6d600eb7c32832758b9 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 4 Jan 2015 19:14:33 +0100 Subject: initial set of adjustments to make (most) imports work. More to come, especially when it's about strings --- git/refs/head.py | 8 +++----- git/refs/reference.py | 3 ++- git/refs/remote.py | 3 ++- git/refs/symbolic.py | 3 ++- git/refs/tag.py | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) (limited to 'git/refs') diff --git a/git/refs/head.py b/git/refs/head.py index 25c994a3..0a14158c 100644 --- a/git/refs/head.py +++ b/git/refs/head.py @@ -1,12 +1,10 @@ -from symbolic import SymbolicReference -from reference import Reference - from git.config import SectionConstraint - from git.util import join_path - from git.exc import GitCommandError +from .symbolic import SymbolicReference +from .reference import Reference + __all__ = ["HEAD", "Head"] diff --git a/git/refs/reference.py b/git/refs/reference.py index b07ac0cd..8741ebb9 100644 --- a/git/refs/reference.py +++ b/git/refs/reference.py @@ -1,8 +1,9 @@ -from symbolic import SymbolicReference from git.util import ( LazyMixin, Iterable, ) +from .symbolic import SymbolicReference + __all__ = ["Reference"] diff --git a/git/refs/remote.py b/git/refs/remote.py index e3827ad9..b692e6df 100644 --- a/git/refs/remote.py +++ b/git/refs/remote.py @@ -1,7 +1,8 @@ -from head import Head from git.util import join_path from gitdb.util import join +from .head import Head + import os diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index e0f5531a..0cd04e07 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -1,4 +1,5 @@ import os + from git.objects import Object, Commit from git.util import ( join_path, @@ -19,7 +20,7 @@ from gitdb.util import ( LockedFD ) -from log import RefLog +from .log import RefLog __all__ = ["SymbolicReference"] diff --git a/git/refs/tag.py b/git/refs/tag.py index 6509c891..3334e53c 100644 --- a/git/refs/tag.py +++ b/git/refs/tag.py @@ -1,4 +1,4 @@ -from reference import Reference +from .reference import Reference __all__ = ["TagReference", "Tag"] -- cgit v1.2.3 From ae2ff0f9d704dc776a1934f72a339da206a9fff4 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Sun, 4 Jan 2015 19:50:28 +0100 Subject: Dum brute force conversion of all types. However, StringIO really is ByteIO in most cases, and py2.7 should run but doesn't. This should be made work first. --- git/refs/log.py | 6 +++++- git/refs/symbolic.py | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'git/refs') diff --git a/git/refs/log.py b/git/refs/log.py index e3f3363c..94e07104 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -17,6 +17,10 @@ from git.objects.util import ( Serializable, altz_to_utctz_str, ) +from git.compat import ( + xrange, + string_types +) import time import re @@ -170,7 +174,7 @@ class RefLog(list, Serializable): :param stream: file-like object containing the revlog in its native format or basestring instance pointing to a file to read""" new_entry = RefLogEntry.from_line - if isinstance(stream, basestring): + if isinstance(stream, string_types): stream = file_contents_ro_filepath(stream) # END handle stream type while True: diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index 0cd04e07..624b1a09 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -19,6 +19,7 @@ from gitdb.util import ( hex_to_bin, LockedFD ) +from git.compat import string_types from .log import RefLog @@ -274,7 +275,7 @@ class SymbolicReference(object): elif isinstance(ref, Object): obj = ref write_value = ref.hexsha - elif isinstance(ref, basestring): + elif isinstance(ref, string_types): try: obj = self.repo.rev_parse(ref + "^{}") # optionally deref tags write_value = obj.hexsha -- cgit v1.2.3 From bc8c91200a7fb2140aadd283c66b5ab82f9ad61e Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 5 Jan 2015 10:09:51 +0100 Subject: Fixed io types to make tests work on PY2 once again. Now it's about going through PY3 issues --- git/refs/log.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git/refs') diff --git a/git/refs/log.py b/git/refs/log.py index 94e07104..f397548e 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -85,7 +85,7 @@ class RefLogEntry(tuple): :param line: line without trailing newline :raise ValueError: If line could not be parsed""" try: - info, msg = line.split('\t', 2) + info, msg = line.split('\t', 1) except ValueError: raise ValueError("line is missing tab separator") # END handle first plit -- cgit v1.2.3 From 04357d0d46fee938a618b64daed1716606e05ca5 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 5 Jan 2015 15:53:46 +0100 Subject: Intermediate commit: test_config and test_actor works Kind of tackling the tasks step by step, picking low-hanging fruit first, or the ones that everyone depends on --- git/refs/symbolic.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'git/refs') diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index 624b1a09..1ac9ac65 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -19,7 +19,9 @@ from gitdb.util import ( hex_to_bin, LockedFD ) -from git.compat import string_types +from git.compat import ( + string_types, +) from .log import RefLog @@ -79,10 +81,10 @@ class SymbolicReference(object): @classmethod def _iter_packed_refs(cls, repo): - """Returns an iterator yielding pairs of sha1/path pairs for the corresponding refs. + """Returns an iterator yielding pairs of sha1/path pairs (as bytes) for the corresponding refs. :note: The packed refs file will be kept open as long as we iterate""" try: - fp = open(cls._get_packed_refs_path(repo), 'rb') + fp = open(cls._get_packed_refs_path(repo), 'rt') for line in fp: line = line.strip() if not line: @@ -123,12 +125,12 @@ class SymbolicReference(object): @classmethod def _get_ref_info(cls, repo, ref_path): - """Return: (sha, target_ref_path) if available, the sha the file at + """Return: (str(sha), str(target_ref_path)) if available, the sha the file at rela_path points to, or None. target_ref_path is the reference we point to, or None""" tokens = None try: - fp = open(join(repo.git_dir, ref_path), 'r') + fp = open(join(repo.git_dir, ref_path), 'rt') value = fp.read().rstrip() fp.close() # Don't only split on spaces, but on whitespace, which allows to parse lines like @@ -141,7 +143,8 @@ class SymbolicReference(object): for sha, path in cls._iter_packed_refs(repo): if path != ref_path: continue - tokens = (sha, path) + # sha will be used as + tokens = sha, path break # END for each packed ref # END handle packed refs -- cgit v1.2.3 From e1060a2a8c90c0730c3541811df8f906dac510a7 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 5 Jan 2015 17:59:22 +0100 Subject: test_commit works once again --- git/refs/symbolic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git/refs') diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index 1ac9ac65..252462a9 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -308,7 +308,7 @@ class SymbolicReference(object): lfd = LockedFD(fpath) fd = lfd.open(write=True, stream=True) - fd.write(write_value) + fd.write(write_value.encode('ascii')) lfd.commit() # Adjust the reflog -- cgit v1.2.3 From b5a37564b6eec05b98c2efa5edcd1460a2df02aa Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 6 Jan 2015 11:02:31 +0100 Subject: test_reflog works --- git/refs/log.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'git/refs') diff --git a/git/refs/log.py b/git/refs/log.py index f397548e..c3019d39 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -19,7 +19,8 @@ from git.objects.util import ( ) from git.compat import ( xrange, - string_types + string_types, + defenc ) import time @@ -38,9 +39,8 @@ class RefLogEntry(tuple): def __repr__(self): """Representation of ourselves in git reflog format""" act = self.actor - name = act.name.encode('utf-8') time = self.time - return self._fmt % (self.oldhexsha, self.newhexsha, name, act.email, + return self._fmt % (self.oldhexsha, self.newhexsha, act.name, act.email, time[0], altz_to_utctz_str(time[1]), self.message) @property @@ -82,8 +82,9 @@ class RefLogEntry(tuple): @classmethod def from_line(cls, line): """:return: New RefLogEntry instance from the given revlog line. - :param line: line without trailing newline + :param line: line bytes without trailing newline :raise ValueError: If line could not be parsed""" + line = line.decode(defenc) try: info, msg = line.split('\t', 1) except ValueError: @@ -253,15 +254,18 @@ class RefLog(list, Serializable): # END handle sha type assure_directory_exists(filepath, is_file=True) committer = isinstance(config_reader, Actor) and config_reader or Actor.committer(config_reader) - entry = RefLogEntry( - (bin_to_hex(oldbinsha), bin_to_hex(newbinsha), committer, (int(time.time()), time.altzone), message)) + entry = RefLogEntry(( + bin_to_hex(oldbinsha).decode('ascii'), + bin_to_hex(newbinsha).decode('ascii'), + committer, (int(time.time()), time.altzone), message + )) lf = LockFile(filepath) lf._obtain_lock_or_raise() - fd = open(filepath, 'a') + fd = open(filepath, 'ab') try: - fd.write(repr(entry)) + fd.write(repr(entry).encode(defenc)) finally: fd.close() lf._release_lock() @@ -286,7 +290,7 @@ class RefLog(list, Serializable): # write all entries for e in self: - write(repr(e)) + write(repr(e).encode(defenc)) # END for each entry def _deserialize(self, stream): -- cgit v1.2.3 From a83eee5bcee64eeb000dd413ab55aa98dcc8c7f2 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 6 Jan 2015 11:14:19 +0100 Subject: test_refs works --- git/refs/symbolic.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'git/refs') diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index 252462a9..45a12385 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -21,6 +21,7 @@ from gitdb.util import ( ) from git.compat import ( string_types, + defenc ) from .log import RefLog @@ -429,6 +430,7 @@ class SymbolicReference(object): # in the line # If we deleted the last line and this one is a tag-reference object, # we drop it as well + line = line.decode(defenc) if (line.startswith('#') or full_ref_path not in line) and \ (not dropped_last_line or dropped_last_line and not line.startswith('^')): new_lines.append(line) @@ -446,7 +448,7 @@ class SymbolicReference(object): if made_change: # write-binary is required, otherwise windows will # open the file in text mode and change LF to CRLF ! - open(pack_file_path, 'wb').writelines(new_lines) + open(pack_file_path, 'wb').writelines(l.encode(defenc) for l in new_lines) # END write out file # END open exception handling # END handle deletion @@ -478,7 +480,7 @@ class SymbolicReference(object): target_data = target.path if not resolve: target_data = "ref: " + target_data - existing_data = open(abs_ref_path, 'rb').read().strip() + existing_data = open(abs_ref_path, 'rb').read().decode(defenc).strip() if existing_data != target_data: raise OSError("Reference at %r does already exist, pointing to %r, requested was %r" % (full_ref_path, existing_data, target_data)) -- cgit v1.2.3 From a05e49d2419d65c59c65adf5cd8c05f276550e1d Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 6 Jan 2015 14:05:30 +0100 Subject: test_repo works --- git/refs/head.py | 1 + 1 file changed, 1 insertion(+) (limited to 'git/refs') diff --git a/git/refs/head.py b/git/refs/head.py index 0a14158c..750d15b6 100644 --- a/git/refs/head.py +++ b/git/refs/head.py @@ -148,6 +148,7 @@ class Head(Reference): writer.set_value(self.k_config_remote, remote_reference.remote_name) writer.set_value(self.k_config_remote_ref, Head.to_full_path(remote_reference.remote_head)) # END handle ref value + writer.release() return self -- cgit v1.2.3 From e0c65d6638698f4e3a9e726efca8c0bcf466cd62 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Tue, 6 Jan 2015 15:38:20 +0100 Subject: Make flake8 happy --- git/refs/log.py | 2 +- git/refs/symbolic.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'git/refs') diff --git a/git/refs/log.py b/git/refs/log.py index c3019d39..69189b51 100644 --- a/git/refs/log.py +++ b/git/refs/log.py @@ -256,7 +256,7 @@ class RefLog(list, Serializable): committer = isinstance(config_reader, Actor) and config_reader or Actor.committer(config_reader) entry = RefLogEntry(( bin_to_hex(oldbinsha).decode('ascii'), - bin_to_hex(newbinsha).decode('ascii'), + bin_to_hex(newbinsha).decode('ascii'), committer, (int(time.time()), time.altzone), message )) diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index 45a12385..cbb129d4 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -144,7 +144,7 @@ class SymbolicReference(object): for sha, path in cls._iter_packed_refs(repo): if path != ref_path: continue - # sha will be used as + # sha will be used tokens = sha, path break # END for each packed ref -- cgit v1.2.3