From 962cb775d906cd4ef6465bbe29dcfbf597e1c26d Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Wed, 18 Nov 2020 15:39:30 +0100 Subject: [PATCH] improve compare speed --- dotdrop/dotdrop.py | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index 442f862..ef30e0d 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -133,19 +133,23 @@ def _dotfile_compare(o, dotfile, tmp): LOG.dbg('points to itself') return True - # install dotfile to temporary dir and compare - ret, err, insttmp = inst.install_to_temp(t, tmp, src, dotfile.dst, - template=dotfile.template, - chmod=dotfile.chmod) - if not ret: - # failed to install to tmp - line = '=> compare {}: error' - LOG.log(line.format(dotfile.key, err)) - LOG.err(err) - return False + if dotfile.template or Templategen.is_template(src): + # install dotfile to temporary dir for compare + ret, err, insttmp = inst.install_to_temp(t, tmp, src, dotfile.dst, + template=dotfile.template, + chmod=dotfile.chmod) + if not ret: + # failed to install to tmp + line = '=> compare {} error: {}' + LOG.log(line.format(dotfile.key, err)) + LOG.err(err) + return False + src = insttmp + + # compare ignores = list(set(o.compare_ignore + dotfile.cmpignore)) ignores = patch_ignores(ignores, dotfile.dst, debug=o.debug) - diff = comp.compare(insttmp, dotfile.dst, ignore=ignores) + diff = comp.compare(src, dotfile.dst, ignore=ignores) # clean tmp transformed dotfile if any if tmpsrc: @@ -153,6 +157,11 @@ def _dotfile_compare(o, dotfile, tmp): if os.path.exists(tmpsrc): removepath(tmpsrc, LOG) + # clean tmp template dotfile if any + if insttmp: + if os.path.exists(insttmp): + removepath(insttmp, LOG) + if diff != '': # print diff results line = '=> compare {}: diffing with \"{}\"'