Set blame.ignoreRevsFile to .git-blame-ignore-revs if present

blame.ignoreRevsFile was set unconditionally in
https://crrev.com/c/5838110, and that broke blame for repositories
without .git-blame-ignore-revs file. This change explicitly checks for
that file before it sets git config. It also removes this config if file
is not present, and effectively fixing broken git blame operations.

The check should remain there forever since .git-blame-ignore-revs can
be removed from a repository.

Bug: 368562244
Change-Id: Id8365045635eb9623b0712b14bb3e7e3206b8795
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5888125
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Josip Sokcevic <sokcevic@chromium.org>
changes/25/5888125/3
Josip Sokcevic 7 months ago committed by LUCI CQ
parent ec715a4dac
commit 97e4c6ab63

@ -662,7 +662,8 @@ class GitWrapper(SCMWrapper):
def set_config(f):
def wrapper(*args):
return_val = f(*args)
if os.path.exists(os.path.join(args[0].checkout_path, '.git')):
checkout_path = args[0].checkout_path
if os.path.exists(os.path.join(checkout_path, '.git')):
# The config updates to the project are stored in this list
# and updated consecutively after the reads. The updates
# are done this way because `scm.GIT.GetConfig` caches
@ -671,7 +672,30 @@ class GitWrapper(SCMWrapper):
# the cache to set and unset consecutively.
config_updates = []
ignore_submodules = scm.GIT.GetConfig(args[0].checkout_path,
blame_ignore_revs_cfg = scm.GIT.GetConfig(
checkout_path, 'blame.ignorerevsfile')
blame_ignore_revs_cfg_set = \
blame_ignore_revs_cfg == \
git_common.GIT_BLAME_IGNORE_REV_FILE
blame_ignore_revs_exists = os.path.isfile(
os.path.join(checkout_path,
git_common.GIT_BLAME_IGNORE_REV_FILE))
if not blame_ignore_revs_cfg_set and blame_ignore_revs_exists:
config_updates.append(
('blame.ignoreRevsFile',
git_common.GIT_BLAME_IGNORE_REV_FILE))
elif blame_ignore_revs_cfg_set and not blame_ignore_revs_exists:
# Some repos may have incorrect config set, unset this
# value. Moreover, some repositories may decide to remove
# git_common.GIT_BLAME_IGNORE_REV_FILE, which would break
# blame without this check.
# See https://crbug.com/368562244 for more details.
config_updates.append(('blame.ignoreRevsFile', None))
ignore_submodules = scm.GIT.GetConfig(checkout_path,
'diff.ignoresubmodules',
None, 'local')
@ -693,11 +717,11 @@ class GitWrapper(SCMWrapper):
gclient_utils.AddWarning(warning_message)
if scm.GIT.GetConfig(args[0].checkout_path,
if scm.GIT.GetConfig(checkout_path,
'fetch.recursesubmodules') != 'off':
config_updates.append(('fetch.recurseSubmodules', 'off'))
if scm.GIT.GetConfig(args[0].checkout_path,
if scm.GIT.GetConfig(checkout_path,
'push.recursesubmodules') != 'off':
# The default is off, but if user sets submodules.recurse to
# on, this becomes on too. We never want to push submodules
@ -706,7 +730,7 @@ class GitWrapper(SCMWrapper):
config_updates.append(('push.recurseSubmodules', 'off'))
for update in config_updates:
scm.GIT.SetConfig(args[0].checkout_path,
scm.GIT.SetConfig(checkout_path,
update[0],
update[1],
modify_all=True)

@ -84,6 +84,8 @@ GIT_EXE = 'git' if not IS_WIN else win_find_git()
# The recommended minimum version of Git, as (<major>, <minor>, <patch>).
GIT_MIN_VERSION = (2, 26, 0)
GIT_BLAME_IGNORE_REV_FILE = '.git-blame-ignore-revs'
FREEZE = 'FREEZE'
FREEZE_SECTIONS = {'indexed': 'soft', 'unindexed': 'mixed'}
FREEZE_MATCHER = re.compile(r'%s.(%s)' % (FREEZE, '|'.join(FREEZE_SECTIONS)))

Loading…
Cancel
Save