Skip to content

Commit

Permalink
fix: stop recording the git log in the metadata (#477)
Browse files Browse the repository at this point in the history
Nothing consumes the log, and there's no design for anything to consume the
log. Plus, it cluttered up synth.metadata.
  • Loading branch information
SurferJeffAtGoogle authored Apr 15, 2020
1 parent bb812f7 commit 6980131
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 40 deletions.
32 changes: 0 additions & 32 deletions synthtool/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,44 +174,12 @@ def __enter__(self):
_add_self_git_source()

def __exit__(self, type, value, traceback):
_append_git_logs(self.old_metadata, get())
_clear_local_paths(get())
_metadata.sources.sort(key=_source_key)
if _enable_write_metadata:
write(self.metadata_file_path)


def _append_git_logs(old_metadata, new_metadata):
"""Adds git logs to git sources in new_metadata.
Parameters:
old_metadata: instance of metadata_pb2.Metadata
old_metadata: instance of metadata_pb2.Metadata
"""
old_map = _get_git_source_map(old_metadata)
new_map = _get_git_source_map(new_metadata)
git = shutil.which("git")
for name, git_source in new_map.items():
# Get the git history since the last run:
old_source = old_map.get(name, metadata_pb2.GitSource())
if not old_source.sha or not git_source.local_path:
continue
output = subprocess.run(
[
git,
"-C",
git_source.local_path,
"log",
"--pretty=%H%n%B",
"--no-decorate",
f"{old_source.sha}..HEAD",
],
stdout=subprocess.PIPE,
universal_newlines=True,
).stdout
git_source.log = output


def _get_git_source_map(metadata) -> Dict[str, object]:
"""Gets the git sources from the metadata.
Expand Down
15 changes: 7 additions & 8 deletions tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import os
import pathlib
import pytest
import re
import shutil
import subprocess

Expand Down Expand Up @@ -161,7 +160,11 @@ def test_track_obsolete_files_defaults_to_false(preserve_track_obsolete_file_fla
assert not metadata.should_track_obsolete_files()


def test_append_git_log_to_metadata(source_tree):
def test_used_to_append_git_log_to_metadata(source_tree):
"""Synthtool used to append the git log for each git source. But nothing
consumes the log, and there's no design for anything to consume the log.
Plus, it cluttered up synth.metadata.
"""
with metadata.MetadataTrackerAndWriter(source_tree.tmpdir / "synth.metadata"):
# Create one commit that will be recorded in the metadata.
source_tree.write("a")
Expand Down Expand Up @@ -195,12 +198,8 @@ def test_append_git_log_to_metadata(source_tree):

# Read the metadata that we just wrote.
mdata = metadata._read_or_empty(source_tree.tmpdir / "synth.metadata")
# Match 2 log lines.
assert re.match(
r"[0-9A-Fa-f]+\ncode/c\n+[0-9A-Fa-f]+\ncode/b\n+",
mdata.sources[1].git.log,
re.MULTILINE,
)
# The log should be empty.
assert "" == mdata.sources[1].git.log
# Make sure the local path field is not recorded.
assert not mdata.sources[0].git.local_path is None

Expand Down

0 comments on commit 6980131

Please sign in to comment.