From b78397a6df612ba97a5b3b076f038be5252922ae Mon Sep 17 00:00:00 2001 From: hyokeun Date: Mon, 16 Apr 2018 13:58:21 +0900 Subject: [PATCH] Snapdiff - Use public git cache if local is not exists Change-Id: I204465c3786643a51a561bcc3f1b3731f8704d19 --- snapdiff/__init__.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/snapdiff/__init__.py b/snapdiff/__init__.py index 785ca8c..6501d2e 100644 --- a/snapdiff/__init__.py +++ b/snapdiff/__init__.py @@ -74,8 +74,9 @@ def diff_to_json(old_url, new_url, **kwargs): added, removed, modified, rebuilded = [], [], [], [] package_names = set(old.__dict__.keys() + new.__dict__.keys()) - def _get_commit_log_delta(old_proj, new_proj, old_commit_id, new_commit_id): - cache_dir = os.getenv('GIT_CACHE_DIR') + def _get_commit_log_delta_internal(old_proj, new_proj, old_commit_id, new_commit_id, cache_dir): + if cache_dir is None: + cache_dir = os.getenv('GIT_CACHE_DIR') git_dir = os.path.join(cache_dir, new_proj) log_filename = 'git_log' @@ -110,6 +111,17 @@ def diff_to_json(old_url, new_url, **kwargs): f.close() return data + def _get_commit_log_delta(old_proj, new_proj, old_commit_id, new_commit_id): + cache_dir = os.getenv('GIT_CACHE_DIR') + logs = _get_commit_log_delta_internal(old_proj, new_proj, old_commit_id, new_commit_id, cache_dir) + if not logs or len(logs) <= 0: + cache_dir_public = os.getenv('PUBLIC_GIT_CACHE_DIR') + if cache_dir_public is None or cache_dir == cache_dir_public: + return logs + logs2 = _get_commit_log_delta_internal(old_proj, new_proj, old_commit_id, new_commit_id, cache_dir_public) + return logs2 + return logs + def _get_git_web(url): matchdomain = re.match(r"http[s]?://[a-z0-9\.]*", url) if not matchdomain: @@ -550,3 +562,4 @@ def diff_to_dist(old_url, new_url, dist_path, **kwargs): with io.open(os.path.join(dist_path, '%s.csv' % diff_name), 'w', encoding='utf-8', errors='ignore') as fname: fname.write(output) return dist_path + -- 2.7.4