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/symbolic.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'git/refs/symbolic.py') 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"] -- 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/symbolic.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'git/refs/symbolic.py') 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 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/symbolic.py') 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/symbolic.py') 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 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/symbolic.py') 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 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/symbolic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'git/refs/symbolic.py') 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