Skip to content

Revise comments, docstrings, some messages, and a bit of code #1725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7dd2095
Fix docstrings that intend '\' literally
EliahKagan Oct 10, 2023
ffcbf07
Put all regex patterns in r-strings
EliahKagan Oct 10, 2023
2c94b6a
Remove r prefix from strings that need not be raw
EliahKagan Oct 10, 2023
35fd65b
Fix _index_from_*_format docstrings (proc reading)
EliahKagan Oct 15, 2023
5af7446
Fix case in IndexObject.abspath exception message
EliahKagan Oct 16, 2023
692e59e
Remove Commit._deserialize doc for param_from_rev_list
EliahKagan Oct 16, 2023
ab46192
Add missing space in Submodule.update debug message
EliahKagan Oct 17, 2023
1114828
Remove obsolete comment in Submodule.module
EliahKagan Oct 18, 2023
f95d4fd
Clarify "master repository" in RootModule docs
EliahKagan Oct 18, 2023
9fea488
Change spelling from "commit'ish" to "commit-ish"
EliahKagan Oct 18, 2023
4536b63
Update git-source citation in Reference.set_object
EliahKagan Oct 18, 2023
59d208c
Fix message in SymbolicReference.from_path
EliahKagan Oct 18, 2023
add46d9
Use "is" to compare __class__
EliahKagan Oct 18, 2023
cd16a35
Revise docstrings and comments for clarity and formatting
EliahKagan Oct 18, 2023
e8343e2
Firm up comment about is_win in util.is_cygwin_git
EliahKagan Oct 18, 2023
f78587f
Remove explicit inheritance from object
EliahKagan Oct 18, 2023
0327f8f
Make all one-element __slots__ be tuples
EliahKagan Oct 18, 2023
d4a87c1
Revise comments in tests used to generate tutorials
EliahKagan Oct 22, 2023
11fce8a
Revise docstrings/comments in most other test modules
EliahKagan Oct 20, 2023
cf9243a
Add a module docstring to tstrunner.py
EliahKagan Oct 23, 2023
b5c3ca4
Slightly improve readability of installation-test strings
EliahKagan Oct 23, 2023
f444470
More wording improvements (in git module)
EliahKagan Oct 23, 2023
db317f1
Change :returns: to :return:
EliahKagan Oct 23, 2023
720e4bb
Fix TestBigRepoR.setUp info message
EliahKagan Oct 23, 2023
faa19ac
Remove outdated git_daemon_launched Windows info
EliahKagan Oct 24, 2023
bffc537
Revise docstrings/comments in test helpers
EliahKagan Oct 24, 2023
30f49d9
Revise docstrings/comments in performance tests
EliahKagan Oct 24, 2023
8d3efc5
Remove explicit inheritance from object in test suite
EliahKagan Oct 24, 2023
a5fc1d8
Improve consistency of "END" comments
EliahKagan Oct 24, 2023
c2eb6b5
Add missing comment revisions in git/objects/submodule/base.py
EliahKagan Oct 24, 2023
ddb4417
Improve consistency of "END" comments in test suite
EliahKagan Oct 24, 2023
1d3f275
Avoid making "END" notation more verbose
EliahKagan Oct 30, 2023
81dad7e
Add missing comment revisions in git/index/base.py
EliahKagan Oct 30, 2023
a040edb
Shorten some docstring references with tilde notation
EliahKagan Oct 30, 2023
af1b5d4
Fix commented *.py names at the top of modules
EliahKagan Oct 30, 2023
b970d42
Remove encoding declarations
EliahKagan Oct 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve consistency of "END" comments
In the git module (including modules it contains).

This does not add any new "# end" or "# END" comments. Instead, it
improves the consistency and clarity of existing ones by converting
each "# end" comment to "# END" (since capitalization was not used
systematically to indicate nesting level or other semantic
information, and capitalizing "END" makes clear the nature of the
comment), and by adding some information to a few of the comments.

This also removes end comments that did not provide information or
significant visual indication that a "section" was ending, or where
the visual indication they provided was at least as well provided
by replacing them with a blank line. However, it does *not* attempt
to apply this change everywhere it might be applicable.
  • Loading branch information
EliahKagan committed Oct 24, 2023
commit a5fc1d863be74db0e2b9c4e962937e9ee4efb8a4
10 changes: 5 additions & 5 deletions git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ def execute(
else:
cmd_not_found_exception = FileNotFoundError # NOQA # exists, flake8 unknown @UndefinedVariable
maybe_patch_caller_env = contextlib.nullcontext()
# end handle
# END handle

stdout_sink = PIPE if with_stdout else getattr(subprocess, "DEVNULL", None) or open(os.devnull, "wb")
if shell is None:
Expand Down Expand Up @@ -1048,7 +1048,7 @@ def kill_process(pid: int) -> None:
pass
return

# end
# END def kill_process

if kill_after_timeout is not None:
kill_check = threading.Event()
Expand Down Expand Up @@ -1100,7 +1100,7 @@ def kill_process(pid: int) -> None:
def as_text(stdout_value: Union[bytes, str]) -> str:
return not output_stream and safe_decode(stdout_value) or "<OUTPUT_STREAM>"

# end
# END def as_text

if stderr_value:
log.info(
Expand Down Expand Up @@ -1304,9 +1304,9 @@ def _call_process(
"Couldn't find argument '%s' in args %s to insert cmd options after"
% (insert_after_this_arg, str(ext_args))
) from err
# end handle error
# END handle error
args_list = ext_args[: index + 1] + opt_args + ext_args[index + 1 :]
# end handle opts_kwargs
# END handle opts_kwargs

call = [self.GIT_PYTHON_GIT_EXECUTABLE]

Expand Down
28 changes: 13 additions & 15 deletions git/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,11 @@ def _read(self, fp: Union[BufferedReader, IO[bytes]], fpname: str) -> None:
def string_decode(v: str) -> str:
if v[-1] == "\\":
v = v[:-1]
# end cut trailing escapes to prevent decode error
# END cut trailing escapes to prevent decode error

return v.encode(defenc).decode("unicode_escape")
# end

# end
# END def string_decode

while True:
# We assume to read binary!
Expand Down Expand Up @@ -496,12 +495,12 @@ def string_decode(v: str) -> str:
optval = optval.strip()
if optval == '""':
optval = ""
# end handle empty string
# END handle empty string
optname = self.optionxform(optname.rstrip())
if len(optval) > 1 and optval[0] == '"' and optval[-1] != '"':
is_multi_line = True
optval = string_decode(optval[1:])
# end handle multi-line
# END handle multi-line
# Preserves multiple values for duplicate optnames.
cursect.add(optname, optval)
else:
Expand All @@ -516,7 +515,7 @@ def string_decode(v: str) -> str:
if line.endswith('"'):
is_multi_line = False
line = line[:-1]
# end handle quotations
# END handle quotations
optval = cursect.getlast(optname)
cursect.setlast(optname, optval + string_decode(line))
# END parse section or option
Expand Down Expand Up @@ -600,7 +599,7 @@ def read(self) -> None: # type: ignore[override]
files_to_read = [self._file_or_files]
else: # for lists or tuples
files_to_read = list(self._file_or_files)
# end ensure we have a copy of the paths to handle
# END ensure we have a copy of the paths to handle

seen = set(files_to_read)
num_read_include_files = 0
Expand Down Expand Up @@ -631,27 +630,26 @@ def read(self) -> None: # type: ignore[override]
if not osp.isabs(include_path):
if not file_ok:
continue
# end ignore relative paths if we don't know the configuration file path
# END ignore relative paths if we don't know the configuration file path
file_path = cast(PathLike, file_path)
assert osp.isabs(file_path), "Need absolute paths to be sure our cycle checks will work"
include_path = osp.join(osp.dirname(file_path), include_path)
# end make include path absolute
# END make include path absolute
include_path = osp.normpath(include_path)
if include_path in seen or not os.access(include_path, os.R_OK):
continue
seen.add(include_path)
# Insert included file to the top to be considered first.
files_to_read.insert(0, include_path)
num_read_include_files += 1
# each include path in configuration file
# end handle includes
# END each include path in configuration file
# END handle includes
# END for each file object to read

# If there was no file included, we can safely write back (potentially) the
# configuration file without altering its meaning.
if num_read_include_files == 0:
self._merge_includes = False
# end

def _write(self, fp: IO) -> None:
"""Write an .ini-format representation of the configuration state in
Expand Down Expand Up @@ -714,15 +712,15 @@ def write(self) -> None:
"Cannot write back if there is not exactly a single file to write to, have %i files"
% len(self._file_or_files)
)
# end assert multiple files
# END assert multiple files

if self._has_includes():
log.debug(
"Skipping write-back of configuration file as include files were merged in."
+ "Set merge_includes=False to prevent this."
)
return None
# end
# END stop if we have include files

fp = self._file_or_files

Expand Down Expand Up @@ -904,7 +902,7 @@ def rename_section(self, section: str, new_name: str) -> "GitConfigParser":
new_section = self._sections[new_name]
for k, vs in self.items_all(section):
new_section.setall(k, vs)
# end for each value to copy
# END for each value to copy

# This call writes back the changes, which is why we don't have the respective decorator.
self.remove_section(section)
Expand Down
8 changes: 4 additions & 4 deletions git/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def __str__(self) -> str:
msg += self.diff.decode(defenc) if isinstance(self.diff, bytes) else self.diff
except UnicodeDecodeError:
msg += "OMITTED BINARY DATA"
# end handle encoding
# END handle encoding
msg += "\n---"
# END diff info

Expand Down Expand Up @@ -543,7 +543,7 @@ def _index_from_patch_format(cls, repo: "Repo", proc: Union["Popen", "Git.AutoIn
# and then retro-actively assign it to our index.
if previous_header is not None:
index[-1].diff = text[previous_header.end() : _header.start()]
# end assign actual diff
# END assign actual diff

# Make sure the mode is set if the path is set. Otherwise the resulting blob is invalid.
# We just use the one mode we should have parsed.
Expand Down Expand Up @@ -571,10 +571,10 @@ def _index_from_patch_format(cls, repo: "Repo", proc: Union["Popen", "Git.AutoIn

previous_header = _header
header = _header
# end for each header we parse
# END for each header we parse
if index and header:
index[-1].diff = text[header.end() :]
# end assign last diff
# END assign last diff

return index

Expand Down
6 changes: 3 additions & 3 deletions git/index/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def raise_exc(e: Exception) -> NoReturn:
if S_ISLNK(st.st_mode):
yield abs_path.replace(rs, "")
continue
# end check symlink
# END check symlink

# If the path is not already pointing to an existing file, resolve globs if possible.
if not os.path.exists(abs_path) and ("?" in abs_path or "*" in abs_path or "[" in abs_path):
Expand Down Expand Up @@ -689,7 +689,7 @@ def _entries_for_paths(
gitrelative_path = path
if self.repo.working_tree_dir:
abspath = osp.join(self.repo.working_tree_dir, gitrelative_path)
# end obtain relative and absolute paths
# END obtain relative and absolute paths

blob = Blob(
self.repo,
Expand Down Expand Up @@ -867,7 +867,7 @@ def handle_null_entries(self: "IndexFile") -> None:
)
# END for each entry index

# end closure
# END closure
handle_null_entries(self)
# END null_entry handling

Expand Down
2 changes: 1 addition & 1 deletion git/index/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def run_commit_hook(name: str, index: "IndexFile", *args: str) -> None:
stdout = force_text(stdout, defenc)
stderr = force_text(stderr, defenc)
raise HookExecutionError(hp, process.returncode, stderr, stdout)
# end handle return code
# END handle return code


def stat_mode_to_index_mode(mode: int) -> int:
Expand Down
6 changes: 3 additions & 3 deletions git/objects/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ def create_from_tree(
for p in parent_commits:
if not isinstance(p, cls):
raise ValueError(f"Parent commit '{p!r}' must be of type {cls}")
# end check parent commit types
# END check parent commit types
# END if parent commits are unset

# Retrieve all additional information, create a commit object, and serialize it.
Expand Down Expand Up @@ -730,7 +730,7 @@ def _deserialize(self, stream: BytesIO) -> "Commit":
next_line = readline()
while next_line.startswith(b" "):
next_line = readline()
# end skip mergetags
# END skip mergetags

# Now we can have the encoding line, or an empty line followed by the optional message.
self.encoding = self.default_encoding
Expand All @@ -754,7 +754,7 @@ def _deserialize(self, stream: BytesIO) -> "Commit":
is_next_header = True
break
sig += sigbuf[1:]
# end read all signature
# END read all signature
self.gpgsig = sig.rstrip(b"\n").decode(self.encoding, "ignore")
if is_next_header:
continue
Expand Down
Loading