| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d9fb2f4 commit d1d18c2
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -52,8 +52,9 @@ def __init__(self, repo: "Repo", path: PathLike = _HEAD_NAME): | |||
| 52 | 52 | ||
| 53 | 53 | def orig_head(self) -> SymbolicReference: | |
| 54 | 54 | """ | |
| 55 | - :return: SymbolicReference pointing at the ORIG_HEAD, which is maintained | ||
| 56 | - to contain the previous value of HEAD. | ||
| 55 | + :return: | ||
| 56 | + :class:`~git.refs.symbolic.SymbolicReference` pointing at the ORIG_HEAD, | ||
| 57 | + which is maintained to contain the previous value of HEAD. | ||
| 57 | 58 | """ | |
| 58 | 59 | return SymbolicReference(self.repo, self._ORIG_HEAD_NAME) | |
| 59 | 60 | ||
@@ -66,16 +67,16 @@ def reset( | |||
| 66 | 67 | **kwargs: Any, | |
| 67 | 68 | ) -> "HEAD": | |
| 68 | 69 | """Reset our HEAD to the given commit optionally synchronizing | |
| 69 | - the index and working tree. The reference we refer to will be set to | ||
| 70 | - commit as well. | ||
| 70 | + the index and working tree. The reference we refer to will be set to commit as | ||
| 71 | + well. | ||
| 71 | 72 | ||
| 72 | 73 | :param commit: | |
| 73 | - Commit object, Reference Object or string identifying a revision we | ||
| 74 | - should reset HEAD to. | ||
| 74 | + :class:`~git.objects.commit.Commit`, :class:`~git.refs.reference.Reference`, | ||
| 75 | + or string identifying a revision we should reset HEAD to. | ||
| 75 | 76 | ||
| 76 | 77 | :param index: | |
| 77 | - If True, the index will be set to match the given commit. Otherwise | ||
| 78 | - it will not be touched. | ||
| 78 | + If True, the index will be set to match the given commit. | ||
| 79 | + Otherwise it will not be touched. | ||
| 79 | 80 | ||
| 80 | 81 | :param working_tree: | |
| 81 | 82 | If True, the working tree will be forcefully adjusted to match the given | |
@@ -87,7 +88,7 @@ def reset( | |||
| 87 | 88 | that are to be reset. This allows to partially reset individual files. | |
| 88 | 89 | ||
| 89 | 90 | :param kwargs: | |
| 90 | - Additional arguments passed to git-reset. | ||
| 91 | + Additional arguments passed to ``git reset``. | ||
| 91 | 92 | ||
| 92 | 93 | :return: self | |
| 93 | 94 | """ | |
@@ -123,8 +124,8 @@ def reset( | |||
| 123 | 124 | ||
| 124 | 125 | ||
| 125 | 126 | class Head(Reference): | |
| 126 | - """A Head is a named reference to a Commit. Every Head instance contains a name | ||
| 127 | - and a Commit object. | ||
| 127 | + """A Head is a named reference to a :class:`~git.objects.commit.Commit`. Every Head | ||
| 128 | + instance contains a name and a :class:`~git.objects.commit.Commit` object. | ||
| 128 | 129 | ||
| 129 | 130 | Examples:: | |
| 130 | 131 | ||
@@ -150,9 +151,8 @@ def delete(cls, repo: "Repo", *heads: "Union[Head, str]", force: bool = False, * | |||
| 150 | 151 | """Delete the given heads. | |
| 151 | 152 | ||
| 152 | 153 | :param force: | |
| 153 | - If True, the heads will be deleted even if they are not yet merged into | ||
| 154 | - the main development stream. | ||
| 155 | - Default False | ||
| 154 | + If True, the heads will be deleted even if they are not yet merged into the | ||
| 155 | + main development stream. Default False. | ||
| 156 | 156 | """ | |
| 157 | 157 | flag = "-d" | |
| 158 | 158 | if force: | |
@@ -163,9 +163,11 @@ def set_tracking_branch(self, remote_reference: Union["RemoteReference", None]) | |||
| 163 | 163 | """Configure this branch to track the given remote reference. This will | |
| 164 | 164 | alter this branch's configuration accordingly. | |
| 165 | 165 | ||
| 166 | - :param remote_reference: The remote reference to track or None to untrack | ||
| 167 | - any references. | ||
| 168 | - :return: self | ||
| 166 | + :param remote_reference: | ||
| 167 | + The remote reference to track or None to untrack any references. | ||
| 168 | + | ||
| 169 | + :return: | ||
| 170 | + self | ||
| 169 | 171 | """ | |
| 170 | 172 | from .remote import RemoteReference | |
| 171 | 173 | ||
@@ -190,8 +192,10 @@ def set_tracking_branch(self, remote_reference: Union["RemoteReference", None]) | |||
| 190 | 192 | ||
| 191 | 193 | def tracking_branch(self) -> Union["RemoteReference", None]: | |
| 192 | 194 | """ | |
| 193 | - :return: The remote_reference we are tracking, or None if we are | ||
| 194 | - not a tracking branch.""" | ||
| 195 | + :return: | ||
| 196 | + The remote reference we are tracking, or None if we are not a tracking | ||
| 197 | + branch. | ||
| 198 | + """ | ||
| 195 | 199 | from .remote import RemoteReference | |
| 196 | 200 | ||
| 197 | 201 | reader = self.config_reader() | |
@@ -211,16 +215,18 @@ def rename(self, new_path: PathLike, force: bool = False) -> "Head": | |||
| 211 | 215 | """Rename self to a new path. | |
| 212 | 216 | ||
| 213 | 217 | :param new_path: | |
| 214 | - Either a simple name or a path, i.e. new_name or features/new_name. | ||
| 215 | - The prefix refs/heads is implied. | ||
| 218 | + Either a simple name or a path, e.g. ``new_name`` or ``features/new_name``. | ||
| 219 | + The prefix ``refs/heads`` is implied. | ||
| 216 | 220 | ||
| 217 | 221 | :param force: | |
| 218 | 222 | If True, the rename will succeed even if a head with the target name | |
| 219 | 223 | already exists. | |
| 220 | 224 | ||
| 221 | - :return: self | ||
| 225 | + :return: | ||
| 226 | + self | ||
| 222 | 227 | ||
| 223 | - :note: Respects the ref log as git commands are used. | ||
| 228 | + :note: | ||
| 229 | + Respects the ref log as git commands are used. | ||
| 224 | 230 | """ | |
| 225 | 231 | flag = "-m" | |
| 226 | 232 | if force: | |
@@ -247,15 +253,15 @@ def checkout(self, force: bool = False, **kwargs: Any) -> Union["HEAD", "Head"]: | |||
| 247 | 253 | ``b="new_branch"`` to create a new branch at the given spot. | |
| 248 | 254 | ||
| 249 | 255 | :return: | |
| 250 | - The active branch after the checkout operation, usually self unless | ||
| 251 | - a new branch has been created. | ||
| 256 | + The active branch after the checkout operation, usually self unless a new | ||
| 257 | + branch has been created. | ||
| 252 | 258 | If there is no active branch, as the HEAD is now detached, the HEAD | |
| 253 | 259 | reference will be returned instead. | |
| 254 | 260 | ||
| 255 | 261 | :note: | |
| 256 | - By default it is only allowed to checkout heads - everything else | ||
| 257 | - will leave the HEAD detached which is allowed and possible, but remains | ||
| 258 | - a special state that some tools might not be able to handle. | ||
| 262 | + By default it is only allowed to checkout heads - everything else will leave | ||
| 263 | + the HEAD detached which is allowed and possible, but remains a special state | ||
| 264 | + that some tools might not be able to handle. | ||
| 259 | 265 | """ | |
| 260 | 266 | kwargs["f"] = force | |
| 261 | 267 | if kwargs["f"] is False: | |
@@ -279,15 +285,17 @@ def _config_parser(self, read_only: bool) -> SectionConstraint[GitConfigParser]: | |||
| 279 | 285 | ||
| 280 | 286 | def config_reader(self) -> SectionConstraint[GitConfigParser]: | |
| 281 | 287 | """ | |
| 282 | - :return: A configuration parser instance constrained to only read | ||
| 283 | - this instance's values. | ||
| 288 | + :return: | ||
| 289 | + A configuration parser instance constrained to only read this instance's | ||
| 290 | + values. | ||
| 284 | 291 | """ | |
| 285 | 292 | return self._config_parser(read_only=True) | |
| 286 | 293 | ||
| 287 | 294 | def config_writer(self) -> SectionConstraint[GitConfigParser]: | |
| 288 | 295 | """ | |
| 289 | - :return: A configuration writer instance with read-and write access | ||
| 290 | - to options of this head. | ||
| 296 | + :return: | ||
| 297 | + A configuration writer instance with read-and write access to options of | ||
| 298 | + this head. | ||
| 291 | 299 | """ | |
| 292 | 300 | return self._config_parser(read_only=False) | |
| 293 | 301 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,6 +44,7 @@ class RefLogEntry(Tuple[str, str, Actor, Tuple[int, int], str]): | |||
| 44 | 44 | """Named tuple allowing easy access to the revlog data fields.""" | |
| 45 | 45 | ||
| 46 | 46 | _re_hexsha_only = re.compile(r"^[0-9A-Fa-f]{40}$") | |
| 47 | + | ||
| 47 | 48 | __slots__ = () | |
| 48 | 49 | ||
| 49 | 50 | def __repr__(self) -> str: | |
@@ -81,7 +82,7 @@ def actor(self) -> Actor: | |||
| 81 | 82 | ||
| 82 | 83 | @property | |
| 83 | 84 | def time(self) -> Tuple[int, int]: | |
| 84 | - """time as tuple: | ||
| 85 | + """Time as tuple: | ||
| 85 | 86 | ||
| 86 | 87 | * [0] = ``int(time)`` | |
| 87 | 88 | * [1] = ``int(timezone_offset)`` in :attr:`time.altzone` format | |
@@ -113,9 +114,11 @@ def new( | |||
| 113 | 114 | def from_line(cls, line: bytes) -> "RefLogEntry": | |
| 114 | 115 | """:return: New RefLogEntry instance from the given revlog line. | |
| 115 | 116 | ||
| 116 | - :param line: Line bytes without trailing newline | ||
| 117 | + :param line: | ||
| 118 | + Line bytes without trailing newline | ||
| 117 | 119 | ||
| 118 | - :raise ValueError: If `line` could not be parsed | ||
| 120 | + :raise ValueError: | ||
| 121 | + If `line` could not be parsed. | ||
| 119 | 122 | """ | |
| 120 | 123 | line_str = line.decode(defenc) | |
| 121 | 124 | fields = line_str.split("\t", 1) | |
@@ -147,9 +150,9 @@ def from_line(cls, line: bytes) -> "RefLogEntry": | |||
| 147 | 150 | ||
| 148 | 151 | ||
| 149 | 152 | class RefLog(List[RefLogEntry], Serializable): | |
| 150 | - """A reflog contains RefLogEntrys, each of which defines a certain state | ||
| 151 | - of the head in question. Custom query methods allow to retrieve log entries | ||
| 152 | - by date or by other criteria. | ||
| 153 | + R"""A reflog contains :class:`RefLogEntry`\s, each of which defines a certain state | ||
| 154 | + of the head in question. Custom query methods allow to retrieve log entries by date | ||
| 155 | + or by other criteria. | ||
| 153 | 156 | ||
| 154 | 157 | Reflog entries are ordered. The first added entry is first in the list. The last | |
| 155 | 158 | entry, i.e. the last change of the head or reference, is last in the list. | |
@@ -163,8 +166,8 @@ def __new__(cls, filepath: Union[PathLike, None] = None) -> "RefLog": | |||
| 163 | 166 | ||
| 164 | 167 | def __init__(self, filepath: Union[PathLike, None] = None): | |
| 165 | 168 | """Initialize this instance with an optional filepath, from which we will | |
| 166 | - initialize our data. The path is also used to write changes back using | ||
| 167 | - the write() method.""" | ||
| 169 | + initialize our data. The path is also used to write changes back using the | ||
| 170 | + :meth:`write` method.""" | ||
| 168 | 171 | self._path = filepath | |
| 169 | 172 | if filepath is not None: | |
| 170 | 173 | self._read_from_file() | |
@@ -189,31 +192,40 @@ def _read_from_file(self) -> None: | |||
| 189 | 192 | @classmethod | |
| 190 | 193 | def from_file(cls, filepath: PathLike) -> "RefLog": | |
| 191 | 194 | """ | |
| 192 | - :return: A new RefLog instance containing all entries from the reflog | ||
| 193 | - at the given filepath | ||
| 194 | - :param filepath: Path to reflog | ||
| 195 | - :raise ValueError: If the file could not be read or was corrupted in some way | ||
| 195 | + :return: | ||
| 196 | + A new :class:`RefLog` instance containing all entries from the reflog at the | ||
| 197 | + given `filepath`. | ||
| 198 | + | ||
| 199 | + :param filepath: | ||
| 200 | + Path to reflog. | ||
| 201 | + | ||
| 202 | + :raise ValueError: | ||
| 203 | + If the file could not be read or was corrupted in some way. | ||
| 196 | 204 | """ | |
| 197 | 205 | return cls(filepath) | |
| 198 | 206 | ||
| 199 | 207 | @classmethod | |
| 200 | 208 | def path(cls, ref: "SymbolicReference") -> str: | |
| 201 | 209 | """ | |
| 202 | - :return: String to absolute path at which the reflog of the given ref | ||
| 203 | - instance would be found. The path is not guaranteed to point to a valid | ||
| 204 | - file though. | ||
| 205 | - :param ref: SymbolicReference instance | ||
| 210 | + :return: | ||
| 211 | + String to absolute path at which the reflog of the given ref instance would | ||
| 212 | + be found. The path is not guaranteed to point to a valid file though. | ||
| 213 | + | ||
| 214 | + :param ref: | ||
| 215 | + :class:`~git.refs.symbolic.SymbolicReference` instance | ||
| 206 | 216 | """ | |
| 207 | 217 | return osp.join(ref.repo.git_dir, "logs", to_native_path(ref.path)) | |
| 208 | 218 | ||
| 209 | 219 | @classmethod | |
| 210 | 220 | def iter_entries(cls, stream: Union[str, "BytesIO", mmap]) -> Iterator[RefLogEntry]: | |
| 211 | 221 | """ | |
| 212 | - :return: Iterator yielding RefLogEntry instances, one for each line read | ||
| 222 | + :return: | ||
| 223 | + Iterator yielding :class:`RefLogEntry` instances, one for each line read | ||
| 213 | 224 | from the given stream. | |
| 214 | 225 | ||
| 215 | - :param stream: File-like object containing the revlog in its native format | ||
| 216 | - or string instance pointing to a file to read. | ||
| 226 | + :param stream: | ||
| 227 | + File-like object containing the revlog in its native format or string | ||
| 228 | + instance pointing to a file to read. | ||
| 217 | 229 | """ | |
| 218 | 230 | new_entry = RefLogEntry.from_line | |
| 219 | 231 | if isinstance(stream, str): | |
@@ -233,18 +245,23 @@ def iter_entries(cls, stream: Union[str, "BytesIO", mmap]) -> Iterator[RefLogEnt | |||
| 233 | 245 | @classmethod | |
| 234 | 246 | def entry_at(cls, filepath: PathLike, index: int) -> "RefLogEntry": | |
| 235 | 247 | """ | |
| 236 | - :return: RefLogEntry at the given index. | ||
| 248 | + :return: | ||
| 249 | + :class:`RefLogEntry` at the given index. | ||
| 237 | 250 | ||
| 238 | - :param filepath: Full path to the index file from which to read the entry. | ||
| 251 | + :param filepath: | ||
| 252 | + Full path to the index file from which to read the entry. | ||
| 239 | 253 | ||
| 240 | - :param index: Python list compatible index, i.e. it may be negative to | ||
| 241 | - specify an entry counted from the end of the list. | ||
| 254 | + :param index: | ||
| 255 | + Python list compatible index, i.e. it may be negative to specify an entry | ||
| 256 | + counted from the end of the list. | ||
| 242 | 257 | ||
| 243 | - :raise IndexError: If the entry didn't exist. | ||
| 258 | + :raise IndexError: | ||
| 259 | + If the entry didn't exist. | ||
| 244 | 260 | ||
| 245 | - .. note:: This method is faster as it only parses the entry at index, skipping | ||
| 246 | - all other lines. Nonetheless, the whole file has to be read if | ||
| 247 | - the index is negative. | ||
| 261 | + :note: | ||
| 262 | + This method is faster as it only parses the entry at index, skipping all | ||
| 263 | + other lines. Nonetheless, the whole file has to be read if the index is | ||
| 264 | + negative. | ||
| 248 | 265 | """ | |
| 249 | 266 | with open(filepath, "rb") as fp: | |
| 250 | 267 | if index < 0: | |
@@ -264,7 +281,8 @@ def entry_at(cls, filepath: PathLike, index: int) -> "RefLogEntry": | |||
| 264 | 281 | def to_file(self, filepath: PathLike) -> None: | |
| 265 | 282 | """Write the contents of the reflog instance to a file at the given filepath. | |
| 266 | 283 | ||
| 267 | - :param filepath: Path to file, parent directories are assumed to exist. | ||
| 284 | + :param filepath: | ||
| 285 | + Path to file. Parent directories are assumed to exist. | ||
| 268 | 286 | """ | |
| 269 | 287 | lfd = LockedFD(filepath) | |
| 270 | 288 | assure_directory_exists(filepath, is_file=True) | |
@@ -290,19 +308,32 @@ def append_entry( | |||
| 290 | 308 | ) -> "RefLogEntry": | |
| 291 | 309 | """Append a new log entry to the revlog at filepath. | |
| 292 | 310 | ||
| 293 | - :param config_reader: Configuration reader of the repository - used to obtain | ||
| 294 | - user information. May also be an Actor instance identifying the committer | ||
| 311 | + :param config_reader: | ||
| 312 | + Configuration reader of the repository - used to obtain user information. | ||
| 313 | + May also be an :class:`~git.util.Actor` instance identifying the committer | ||
| 295 | 314 | directly or None. | |
| 296 | - :param filepath: Full path to the log file. | ||
| 297 | - :param oldbinsha: Binary sha of the previous commit. | ||
| 298 | - :param newbinsha: Binary sha of the current commit. | ||
| 299 | - :param message: Message describing the change to the reference. | ||
| 300 | - :param write: If True, the changes will be written right away. Otherwise the | ||
| 301 | - change will not be written. | ||
| 302 | 315 | ||
| 303 | - :return: RefLogEntry objects which was appended to the log. | ||
| 316 | + :param filepath: | ||
| 317 | + Full path to the log file. | ||
| 318 | + | ||
| 319 | + :param oldbinsha: | ||
| 320 | + Binary sha of the previous commit. | ||
| 321 | + | ||
| 322 | + :param newbinsha: | ||
| 323 | + Binary sha of the current commit. | ||
| 324 | + | ||
| 325 | + :param message: | ||
| 326 | + Message describing the change to the reference. | ||
| 327 | + | ||
| 328 | + :param write: | ||
| 329 | + If True, the changes will be written right away. | ||
| 330 | + Otherwise the change will not be written. | ||
| 331 | + | ||
| 332 | + :return: | ||
| 333 | + :class:`RefLogEntry` objects which was appended to the log. | ||
| 304 | 334 | ||
| 305 | - :note: As we are append-only, concurrent access is not a problem as we do not | ||
| 335 | + :note: | ||
| 336 | + As we are append-only, concurrent access is not a problem as we do not | ||
| 306 | 337 | interfere with readers. | |
| 307 | 338 | """ | |
| 308 | 339 | ||
@@ -340,7 +371,8 @@ def append_entry( | |||
| 340 | 371 | def write(self) -> "RefLog": | |
| 341 | 372 | """Write this instance's data to the file we are originating from. | |
| 342 | 373 | ||
| 343 | - :return: self | ||
| 374 | + :return: | ||
| 375 | + self | ||
| 344 | 376 | """ | |
| 345 | 377 | if self._path is None: | |
| 346 | 378 | raise ValueError("Instance was not initialized with a path, use to_file(...) instead") | |
| Back | FazBrowse Home | New Git URL |
0 commit comments