Skip to content

Commit 7bbccb4

Browse files
committed
Rename logger globals from log to _logger
These globals were nonpublic, because even though they were named without leading underscores, they all appeared in modules in which __all__ was defined and did not list them. (They remain nonpublic.) This renaming is to avoid confusion between those log attributes ang logging features of Git itself ("git log", "git reflog"), and more importantly, with the related git.refs.log module, referred to by the log attribute of the git.refs module, and the log attribute of the git module (git/__init__.py has a * import from git.refs).
1 parent 987dbf4 commit 7bbccb4

File tree

11 files changed

+62
-62
lines changed

11 files changed

+62
-62
lines changed

git/cmd.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@
8181
"strip_newline_in_stdout",
8282
}
8383

84-
log = logging.getLogger(__name__)
85-
log.addHandler(logging.NullHandler())
84+
_logger = logging.getLogger(__name__)
85+
_logger.addHandler(logging.NullHandler())
8686

8787
__all__ = ("Git",)
8888

@@ -146,7 +146,7 @@ def pump_stream(
146146
handler(line)
147147

148148
except Exception as ex:
149-
log.error(f"Pumping {name!r} of cmd({remove_password_if_present(cmdline)}) failed due to: {ex!r}")
149+
_logger.error(f"Pumping {name!r} of cmd({remove_password_if_present(cmdline)}) failed due to: {ex!r}")
150150
if "I/O operation on closed file" not in str(ex):
151151
# Only reraise if the error was not due to the stream closing
152152
raise CommandError([f"<{name}-pump>"] + remove_password_if_present(cmdline), ex) from ex
@@ -600,7 +600,7 @@ def _terminate(self) -> None:
600600
self.status = self._status_code_if_terminate or proc.poll()
601601
return
602602
except OSError as ex:
603-
log.info("Ignored error after process had died: %r", ex)
603+
_logger.info("Ignored error after process had died: %r", ex)
604604

605605
# It can be that nothing really exists anymore...
606606
if os is None or getattr(os, "kill", None) is None:
@@ -613,7 +613,7 @@ def _terminate(self) -> None:
613613

614614
self.status = self._status_code_if_terminate or status
615615
except OSError as ex:
616-
log.info("Ignored error after process had died: %r", ex)
616+
_logger.info("Ignored error after process had died: %r", ex)
617617
# END exception handling
618618

619619
def __del__(self) -> None:
@@ -654,7 +654,7 @@ def read_all_from_possibly_closed_stream(stream: Union[IO[bytes], None]) -> byte
654654

655655
if status != 0:
656656
errstr = read_all_from_possibly_closed_stream(p_stderr)
657-
log.debug("AutoInterrupt wait stderr: %r" % (errstr,))
657+
_logger.debug("AutoInterrupt wait stderr: %r" % (errstr,))
658658
raise GitCommandError(remove_password_if_present(self.args), status, errstr)
659659
return status
660660

@@ -1018,7 +1018,7 @@ def execute(
10181018
# Remove password for the command if present.
10191019
redacted_command = remove_password_if_present(command)
10201020
if self.GIT_PYTHON_TRACE and (self.GIT_PYTHON_TRACE != "full" or as_process):
1021-
log.info(" ".join(redacted_command))
1021+
_logger.info(" ".join(redacted_command))
10221022

10231023
# Allow the user to have the command executed in their working dir.
10241024
try:
@@ -1055,7 +1055,7 @@ def execute(
10551055
stdout_sink = PIPE if with_stdout else getattr(subprocess, "DEVNULL", None) or open(os.devnull, "wb")
10561056
if shell is None:
10571057
shell = self.USE_SHELL
1058-
log.debug(
1058+
_logger.debug(
10591059
"Popen(%s, cwd=%s, stdin=%s, shell=%s, universal_newlines=%s)",
10601060
redacted_command,
10611061
cwd,
@@ -1167,17 +1167,17 @@ def as_text(stdout_value: Union[bytes, str]) -> str:
11671167
# END as_text
11681168

11691169
if stderr_value:
1170-
log.info(
1170+
_logger.info(
11711171
"%s -> %d; stdout: '%s'; stderr: '%s'",
11721172
cmdstr,
11731173
status,
11741174
as_text(stdout_value),
11751175
safe_decode(stderr_value),
11761176
)
11771177
elif stdout_value:
1178-
log.info("%s -> %d; stdout: '%s'", cmdstr, status, as_text(stdout_value))
1178+
_logger.info("%s -> %d; stdout: '%s'", cmdstr, status, as_text(stdout_value))
11791179
else:
1180-
log.info("%s -> %d", cmdstr, status)
1180+
_logger.info("%s -> %d", cmdstr, status)
11811181
# END handle debug printing
11821182

11831183
if with_exceptions and status != 0:

git/config.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161
__all__ = ("GitConfigParser", "SectionConstraint")
6262

6363

64-
log = logging.getLogger(__name__)
65-
log.addHandler(logging.NullHandler())
64+
_logger = logging.getLogger(__name__)
65+
_logger.addHandler(logging.NullHandler())
6666

6767

6868
CONFIG_LEVELS: ConfigLevels_Tup = ("system", "user", "global", "repository")
@@ -412,7 +412,7 @@ def release(self) -> None:
412412
try:
413413
self.write()
414414
except IOError:
415-
log.error("Exception during destruction of GitConfigParser", exc_info=True)
415+
_logger.error("Exception during destruction of GitConfigParser", exc_info=True)
416416
except ReferenceError:
417417
# This happens in Python 3... and usually means that some state cannot be
418418
# written as the sections dict cannot be iterated. This usually happens when
@@ -712,7 +712,7 @@ def write(self) -> None:
712712
# END assert multiple files
713713

714714
if self._has_includes():
715-
log.debug(
715+
_logger.debug(
716716
"Skipping write-back of configuration file as include files were merged in."
717717
+ "Set merge_includes=False to prevent this."
718718
)

git/objects/commit.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252

5353
# ------------------------------------------------------------------------
5454

55-
log = logging.getLogger(__name__)
56-
log.addHandler(logging.NullHandler())
55+
_logger = logging.getLogger(__name__)
56+
_logger.addHandler(logging.NullHandler())
5757

5858
__all__ = ("Commit",)
5959

@@ -767,7 +767,7 @@ def _deserialize(self, stream: BytesIO) -> "Commit":
767767
self.author_tz_offset,
768768
) = parse_actor_and_date(author_line.decode(self.encoding, "replace"))
769769
except UnicodeDecodeError:
770-
log.error(
770+
_logger.error(
771771
"Failed to decode author line '%s' using encoding %s",
772772
author_line,
773773
self.encoding,
@@ -781,7 +781,7 @@ def _deserialize(self, stream: BytesIO) -> "Commit":
781781
self.committer_tz_offset,
782782
) = parse_actor_and_date(committer_line.decode(self.encoding, "replace"))
783783
except UnicodeDecodeError:
784-
log.error(
784+
_logger.error(
785785
"Failed to decode committer line '%s' using encoding %s",
786786
committer_line,
787787
self.encoding,
@@ -795,7 +795,7 @@ def _deserialize(self, stream: BytesIO) -> "Commit":
795795
try:
796796
self.message = self.message.decode(self.encoding, "replace")
797797
except UnicodeDecodeError:
798-
log.error(
798+
_logger.error(
799799
"Failed to decode message '%s' using encoding %s",
800800
self.message,
801801
self.encoding,

git/objects/submodule/base.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
__all__ = ["Submodule", "UpdateProgress"]
5757

5858

59-
log = logging.getLogger(__name__)
60-
log.addHandler(logging.NullHandler())
59+
_logger = logging.getLogger(__name__)
60+
_logger.addHandler(logging.NullHandler())
6161

6262

6363
class UpdateProgress(RemoteProgress):
@@ -731,7 +731,7 @@ def update(
731731
)
732732
mrepo.head.reference.set_tracking_branch(remote_branch)
733733
except (IndexError, InvalidGitRepositoryError):
734-
log.warning("Failed to checkout tracking branch %s", self.branch_path)
734+
_logger.warning("Failed to checkout tracking branch %s", self.branch_path)
735735
# END handle tracking branch
736736

737737
# NOTE: Have to write the repo config file as well, otherwise the
@@ -761,14 +761,14 @@ def update(
761761
binsha = rcommit.binsha
762762
hexsha = rcommit.hexsha
763763
else:
764-
log.error(
764+
_logger.error(
765765
"%s a tracking branch was not set for local branch '%s'",
766766
msg_base,
767767
mrepo.head.reference,
768768
)
769769
# END handle remote ref
770770
else:
771-
log.error("%s there was no local tracking branch", msg_base)
771+
_logger.error("%s there was no local tracking branch", msg_base)
772772
# END handle detached head
773773
# END handle to_latest_revision option
774774

@@ -786,15 +786,15 @@ def update(
786786
if force:
787787
msg = "Will force checkout or reset on local branch that is possibly in the future of"
788788
msg += " the commit it will be checked out to, effectively 'forgetting' new commits"
789-
log.debug(msg)
789+
_logger.debug(msg)
790790
else:
791791
msg = "Skipping %s on branch '%s' of submodule repo '%s' as it contains un-pushed commits"
792792
msg %= (
793793
is_detached and "checkout" or "reset",
794794
mrepo.head,
795795
mrepo,
796796
)
797-
log.info(msg)
797+
_logger.info(msg)
798798
may_reset = False
799799
# END handle force
800800
# END handle if we are in the future
@@ -834,7 +834,7 @@ def update(
834834
except Exception as err:
835835
if not keep_going:
836836
raise
837-
log.error(str(err))
837+
_logger.error(str(err))
838838
# END handle keep_going
839839

840840
# HANDLE RECURSION

git/objects/submodule/root.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
__all__ = ["RootModule", "RootUpdateProgress"]
2424

25-
log = logging.getLogger(__name__)
26-
log.addHandler(logging.NullHandler())
25+
_logger = logging.getLogger(__name__)
26+
_logger.addHandler(logging.NullHandler())
2727

2828

2929
class RootUpdateProgress(UpdateProgress):
@@ -321,7 +321,7 @@ def update(
321321
# this way, it will be checked out in the next step.
322322
# This will change the submodule relative to us, so
323323
# the user will be able to commit the change easily.
324-
log.warning(
324+
_logger.warning(
325325
"Current sha %s was not contained in the tracking\
326326
branch at the new remote, setting it the the remote's tracking branch",
327327
sm.hexsha,
@@ -393,7 +393,7 @@ def update(
393393
except Exception as err:
394394
if not keep_going:
395395
raise
396-
log.error(str(err))
396+
_logger.error(str(err))
397397
# END handle keep_going
398398

399399
# FINALLY UPDATE ALL ACTUAL SUBMODULES

git/remote.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@
6565
# -------------------------------------------------------------
6666

6767

68-
log = logging.getLogger(__name__)
69-
log.addHandler(logging.NullHandler())
68+
_logger = logging.getLogger(__name__)
69+
_logger.addHandler(logging.NullHandler())
7070

7171

7272
__all__ = ("RemoteProgress", "PushInfo", "FetchInfo", "Remote")
@@ -857,7 +857,7 @@ def _get_fetch_info_from_stderr(
857857
stderr_text = progress.error_lines and "\n".join(progress.error_lines) or ""
858858
proc.wait(stderr=stderr_text)
859859
if stderr_text:
860-
log.warning("Error lines received while fetching: %s", stderr_text)
860+
_logger.warning("Error lines received while fetching: %s", stderr_text)
861861

862862
for line in progress.other_lines:
863863
line = force_text(line)
@@ -878,9 +878,9 @@ def _get_fetch_info_from_stderr(
878878
msg += "length of progress lines %i should be equal to lines in FETCH_HEAD file %i\n"
879879
msg += "Will ignore extra progress lines or fetch head lines."
880880
msg %= (l_fil, l_fhi)
881-
log.debug(msg)
882-
log.debug(b"info lines: " + str(fetch_info_lines).encode("UTF-8"))
883-
log.debug(b"head info: " + str(fetch_head_info).encode("UTF-8"))
881+
_logger.debug(msg)
882+
_logger.debug(b"info lines: " + str(fetch_info_lines).encode("UTF-8"))
883+
_logger.debug(b"head info: " + str(fetch_head_info).encode("UTF-8"))
884884
if l_fil < l_fhi:
885885
fetch_head_info = fetch_head_info[:l_fil]
886886
else:
@@ -892,8 +892,8 @@ def _get_fetch_info_from_stderr(
892892
try:
893893
output.append(FetchInfo._from_line(self.repo, err_line, fetch_line))
894894
except ValueError as exc:
895-
log.debug("Caught error while parsing line: %s", exc)
896-
log.warning("Git informed while fetching: %s", err_line.strip())
895+
_logger.debug("Caught error while parsing line: %s", exc)
896+
_logger.warning("Git informed while fetching: %s", err_line.strip())
897897
return output
898898

899899
def _get_push_info(
@@ -935,7 +935,7 @@ def stdout_handler(line: str) -> None:
935935
if not output:
936936
raise
937937
elif stderr_text:
938-
log.warning("Error lines received while fetching: %s", stderr_text)
938+
_logger.warning("Error lines received while fetching: %s", stderr_text)
939939
output.error = e
940940

941941
return output

git/repo/base.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989

9090
# -----------------------------------------------------------
9191

92-
log = logging.getLogger(__name__)
92+
_logger = logging.getLogger(__name__)
9393

9494
__all__ = ("Repo",)
9595

@@ -772,7 +772,7 @@ def is_valid_object(self, sha: str, object_type: Union[str, None] = None) -> boo
772772
if object_info.type == object_type.encode():
773773
return True
774774
else:
775-
log.debug(
775+
_logger.debug(
776776
"Commit hash points to an object of type '%s'. Requested were objects of type '%s'",
777777
object_info.type.decode(),
778778
object_type,
@@ -781,7 +781,7 @@ def is_valid_object(self, sha: str, object_type: Union[str, None] = None) -> boo
781781
else:
782782
return True
783783
except BadObject:
784-
log.debug("Commit hash is invalid.")
784+
_logger.debug("Commit hash is invalid.")
785785
return False
786786

787787
def _get_daemon_export(self) -> bool:
@@ -1298,7 +1298,7 @@ def _clone(
12981298
cmdline = getattr(proc, "args", "")
12991299
cmdline = remove_password_if_present(cmdline)
13001300

1301-
log.debug("Cmd(%s)'s unused stdout: %s", cmdline, stdout)
1301+
_logger.debug("Cmd(%s)'s unused stdout: %s", cmdline, stdout)
13021302
finalize_process(proc, stderr=stderr)
13031303

13041304
# Our git command could have a different working dir than our actual

git/util.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
"HIDE_WINDOWS_KNOWN_ERRORS",
105105
]
106106

107-
log = logging.getLogger(__name__)
107+
_logger = logging.getLogger(__name__)
108108

109109

110110
def _read_win_env_flag(name: str, default: bool) -> bool:
@@ -124,7 +124,7 @@ def _read_win_env_flag(name: str, default: bool) -> bool:
124124
except KeyError:
125125
return default
126126

127-
log.warning(
127+
_logger.warning(
128128
"The %s environment variable is deprecated. Its effect has never been documented and changes without warning.",
129129
name,
130130
)
@@ -135,7 +135,7 @@ def _read_win_env_flag(name: str, default: bool) -> bool:
135135
return False
136136
if adjusted_value in {"1", "true", "yes"}:
137137
return True
138-
log.warning("%s has unrecognized value %r, treating as %r.", name, value, default)
138+
_logger.warning("%s has unrecognized value %r, treating as %r.", name, value, default)
139139
return default
140140

141141

@@ -466,7 +466,7 @@ def is_cygwin_git(git_executable: Union[None, PathLike]) -> bool:
466466
# retcode = process.poll()
467467
is_cygwin = "CYGWIN" in uname_out
468468
except Exception as ex:
469-
log.debug("Failed checking if running in CYGWIN due to: %r", ex)
469+
_logger.debug("Failed checking if running in CYGWIN due to: %r", ex)
470470
_is_cygwin_cache[git_executable] = is_cygwin
471471

472472
return is_cygwin

0 commit comments

Comments
 (0)