summaryrefslogtreecommitdiff
path: root/git/refs
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2015-01-06 16:11:34 +0100
committerSebastian Thiel <byronimo@gmail.com>2015-01-06 16:11:34 +0100
commit56e942318f3c493c8dcd4759f806034331ebeda5 (patch)
tree82cdca65cd197f36ea3680171186e0ddcf234266 /git/refs
parentd46e3fe9cb0dea2617cd9231d29bf6919b0f1e91 (diff)
parent68f8a43d1b643318732f30ee1cd75e1d315a4537 (diff)
downloadgitpython-56e942318f3c493c8dcd4759f806034331ebeda5.tar.gz
Merge branch 'py3' into 0.3
Conflicts: git/refs/log.py
Diffstat (limited to 'git/refs')
-rw-r--r--git/refs/head.py9
-rw-r--r--git/refs/log.py26
-rw-r--r--git/refs/reference.py3
-rw-r--r--git/refs/remote.py3
-rw-r--r--git/refs/symbolic.py27
-rw-r--r--git/refs/tag.py2
6 files changed, 43 insertions, 27 deletions
diff --git a/git/refs/head.py b/git/refs/head.py
index 25c994a3..750d15b6 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"]
@@ -150,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
diff --git a/git/refs/log.py b/git/refs/log.py
index 07465e6f..7708dd73 100644
--- a/git/refs/log.py
+++ b/git/refs/log.py
@@ -17,6 +17,11 @@ from git.objects.util import (
Serializable,
altz_to_utctz_str,
)
+from git.compat import (
+ xrange,
+ string_types,
+ defenc
+)
import time
import re
@@ -34,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
@@ -78,7 +82,7 @@ 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"""
fields = line.split('\t', 1)
if len(fields) == 1:
@@ -89,6 +93,7 @@ class RefLogEntry(tuple):
raise ValueError("Line must have up to two TAB-separated fields."
" Got %s" % repr(line))
# END handle first split
+
oldhexsha = info[:40]
newhexsha = info[41:81]
for hexsha in (oldhexsha, newhexsha):
@@ -174,7 +179,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:
@@ -253,15 +258,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 +294,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):
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..cbb129d4 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,
@@ -18,8 +19,12 @@ from gitdb.util import (
hex_to_bin,
LockedFD
)
+from git.compat import (
+ string_types,
+ defenc
+)
-from log import RefLog
+from .log import RefLog
__all__ = ["SymbolicReference"]
@@ -77,10 +82,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:
@@ -121,12 +126,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
@@ -139,7 +144,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
+ tokens = sha, path
break
# END for each packed ref
# END handle packed refs
@@ -273,7 +279,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
@@ -303,7 +309,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
@@ -424,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)
@@ -441,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
@@ -473,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))
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"]