| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,21 +7,22 @@ | |||
| 7 | 7 | ||
| 8 | 8 | from git.objects.util import ( | |
| 9 | 9 | Actor, | |
| 10 | - parse_actor_and_date, | ||
| 10 | + parse_date, | ||
| 11 | 11 | Serializable, | |
| 12 | 12 | utctz_to_altz, | |
| 13 | 13 | altz_to_utctz_str, | |
| 14 | 14 | ) | |
| 15 | 15 | ||
| 16 | 16 | import os | |
| 17 | - | ||
| 17 | + import re | ||
| 18 | 18 | ||
| 19 | 19 | __all__ = ["RefLog", "RefLogEntry"] | |
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | 22 | class RefLogEntry(tuple): | |
| 23 | 23 | """Named tuple allowing easy access to the revlog data fields""" | |
| 24 | - _fmt = "%s %s %s <%s> %i %s\t%s" | ||
| 24 | + _fmt = "%s %s %s <%s> %i %s\t%s\n" | ||
| 25 | + _re_hexsha_only = re.compile('^[0-9A-Fa-f]{40}$') | ||
| 25 | 26 | __slots__ = tuple() | |
| 26 | 27 | ||
| 27 | 28 | def __repr__(self): | |
@@ -68,13 +69,34 @@ def new(self, oldhexsha, newhexsha, actor, time, tz_offset, message): | |||
| 68 | 69 | return RefLogEntry((oldhexsha, newhexsha, actor, (time, tz_offset), message)) | |
| 69 | 70 | ||
| 70 | 71 | @classmethod | |
| 71 | - def from_line(self, line): | ||
| 72 | + def from_line(cls, line): | ||
| 72 | 73 | """:return: New RefLogEntry instance from the given revlog line. | |
| 73 | 74 | :param line: line without trailing newline | |
| 74 | 75 | :raise ValueError: If line could not be parsed""" | |
| 75 | - raise NotImplementedError("todo") | ||
| 76 | + try: | ||
| 77 | + info, msg = line.split('\t', 2) | ||
| 78 | + except ValueError: | ||
| 79 | + raise ValueError("line is missing tab separator") | ||
| 80 | + #END handle first plit | ||
| 81 | + oldhexsha = info[:40] | ||
| 82 | + newhexsha = info[41:81] | ||
| 83 | + for hexsha in (oldhexsha, newhexsha): | ||
| 84 | + if not cls._re_hexsha_only.match(hexsha): | ||
| 85 | + raise ValueError("Invalid hexsha: %s" % hexsha) | ||
| 86 | + # END if hexsha re doesn't match | ||
| 87 | + #END for each hexsha | ||
| 88 | + | ||
| 89 | + email_end = info.find('>', 82) | ||
| 90 | + if email_end == -1: | ||
| 91 | + raise ValueError("Missing token: >") | ||
| 92 | + #END handle missing end brace | ||
| 93 | + | ||
| 94 | + actor = Actor._from_string(info[82:email_end+1]) | ||
| 95 | + time, tz_offset = parse_date(info[email_end+2:]) | ||
| 96 | + | ||
| 97 | + return RefLogEntry((oldhexsha, newhexsha, actor, (time, tz_offset), msg)) | ||
| 98 | + | ||
| 76 | 99 | ||
| 77 | - | ||
| 78 | 100 | class RefLog(list, Serializable): | |
| 79 | 101 | """A reflog contains reflog entries, each of which defines a certain state | |
| 80 | 102 | of the head in question. Custom query methods allow to retrieve log entries | |
@@ -104,7 +126,7 @@ def from_file(cls, filepath): | |||
| 104 | 126 | return inst | |
| 105 | 127 | ||
| 106 | 128 | @classmethod | |
| 107 | - def reflog_path(cls, ref): | ||
| 129 | + def path(cls, ref): | ||
| 108 | 130 | """ | |
| 109 | 131 | :return: string to absolute path at which the reflog of the given ref | |
| 110 | 132 | instance would be found. The path is not guaranteed to point to a valid | |
@@ -123,7 +145,12 @@ def iter_entries(cls, stream): | |||
| 123 | 145 | if isinstance(stream, basestring): | |
| 124 | 146 | stream = file_contents_ro_filepath(stream) | |
| 125 | 147 | #END handle stream type | |
| 126 | - return (new_entry(line.strip()) for line in stream) | ||
| 148 | + while True: | ||
| 149 | + line = stream.readline() | ||
| 150 | + if not line: | ||
| 151 | + return | ||
| 152 | + yield new_entry(line.strip()) | ||
| 153 | + #END endless loop | ||
| 127 | 154 | ||
| 128 | 155 | def to_file(self, filepath): | |
| 129 | 156 | """Write the contents of the reflog instance to a file at the given filepath. | |
@@ -140,22 +167,13 @@ def to_file(self, filepath): | |||
| 140 | 167 | #{ Serializable Interface | |
| 141 | 168 | def _serialize(self, stream): | |
| 142 | 169 | lm1 = len(self) - 1 | |
| 143 | - write = stream.write() | ||
| 170 | + write = stream.write | ||
| 144 | 171 | ||
| 145 | 172 | # write all entries | |
| 146 | - for i, e in self: | ||
| 147 | - s = repr(e) | ||
| 148 | - if i != lm1: | ||
| 149 | - s += "\n" | ||
| 150 | - #END handle line separator | ||
| 151 | - write(s) | ||
| 173 | + for i, e in enumerate(self): | ||
| 174 | + write(repr(e)) | ||
| 152 | 175 | #END for each entry | |
| 153 | 176 | ||
| 154 | 177 | def _deserialize(self, stream): | |
| 155 | - new_entry = RefLogEntry.from_line | ||
| 156 | - append = self.append | ||
| 157 | - # NOTE: should use iter_entries, but this way it will be more direct and faster | ||
| 158 | - for line in stream: | ||
| 159 | - append(new_entry(line.strip())) | ||
| 160 | - #END handle deserializatoin | ||
| 178 | + self.extend(self.iter_entries(stream)) | ||
| 161 | 179 | #} END serializable interface | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + 501bf602abea7d21c3dbb409b435976e92033145 82b8902e033430000481eb355733cd7065342037 Sebastian Thiel <byronimo@gmail.com> 1270634931 +0200 commit: Used this release for a first beta of the 0.2 branch of development | ||
| 2 | + 82b8902e033430000481eb355733cd7065342037 69361d96a59381fde0ac34d19df2d4aff05fb9a9 Sebastian Thiel <byronimo@gmail.com> 1271229940 commit: conf.py: Adjusted version to match with the actual version | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + 501bf602abea7d21c3dbb409b435976e92033145 82b8902e033430000481eb355733cd7065342037 Sebastian Thiel <byronimo@gmail.com> 1270634931 +0200 commit: Used this release for a first beta of the 0.2 branch of development | ||
| 2 | + 82b8902e033430000481eb355733cd7065342037 69361d96a59381fde0ac34d19df2d4aff05fb9a9 Sebastian Thiel <byronimo@gmail. 1271229940 +0200 commit: conf.py: Adjusted version to match with the actual version | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + 501bf602abea7d21c3dbb409b435976e92033145 82b8902e033430000481eb355733cd7065342037 Sebastian Thiel <byronimo@gmail.com> 1270634931 +0200 commit: Used this release for a first beta of the 0.2 branch of development | ||
| 2 | + 82b8902e033430000481eb355733cd7065342037 69361d96a59381fde0ac34d19df2d Sebastian Thiel <byronimo@gmail.com> 1271229940 +0200 commit: conf.py: Adjusted version to match with the actual version | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + 501bf602abea7d21c3dbb409b435976e92033145 82b8902e033430000481eb355733cd7065342037 Sebastian Thiel <byronimo@gmail.com> 1270634931 +0200 commit: Used this release for a first beta of the 0.2 branch of development | ||
| 2 | + 82b8902e033430000481eb3 69361d96a59381fde0ac34d19df2d4aff05fb9a9 Sebastian Thiel <byronimo@gmail.com> 1271229940 +0200 commit: conf.py: Adjusted version to match with the actual version | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + 501bf602abea7d21c3dbb409b435976e92033145 82b8902e033430000481eb355733cd7065342037 Sebastian Thiel <byronimo@gmail.com> 1270634931 +0200 commit: Used this release for a first beta of the 0.2 branch of development | ||
| 2 | + 82b8902e033430000481eb355733cd7065342037 69361d96a59381fde0ac34d19df2d4aff05fb9a9 Sebastian Thiel <byronimo@gmail.com> 1271229940 +0200 commit: conf.py: Adjusted version to match with the actual version | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments