From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1S6Xm6-0006vc-TO for garchives@archives.gentoo.org; Sun, 11 Mar 2012 01:40:43 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 082D0E05D9; Sun, 11 Mar 2012 01:40:35 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id B7190E05D9 for ; Sun, 11 Mar 2012 01:40:35 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id EF32F1B400F for ; Sun, 11 Mar 2012 01:40:34 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id AE209E5428 for ; Sun, 11 Mar 2012 01:40:33 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1331430029.3467a10ba5eb37f67899e772c2951992dc28f46c.vapier@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: bin/, pym/portage/ X-VCS-Repository: proj/portage X-VCS-Files: bin/dispatch-conf pym/portage/dispatch_conf.py X-VCS-Directories: bin/ pym/portage/ X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: 3467a10ba5eb37f67899e772c2951992dc28f46c X-VCS-Branch: master Date: Sun, 11 Mar 2012 01:40:33 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: 1f45070b-58b5-4a47-8edc-0f002ad4fbb7 X-Archives-Hash: b6ab0cf8f9fab353b3637fdaf1fd1017 commit: 3467a10ba5eb37f67899e772c2951992dc28f46c Author: Mike Frysinger gentoo org> AuthorDate: Thu Mar 8 21:47:16 2012 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Sun Mar 11 01:40:29 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/portage.git;a= =3Dcommit;h=3D3467a10b dispatch-conf: do regex matching ourselves This avoids having to pipe through multiple greps, as well as running diff multiple times on the same set of files. Signed-off-by: Mike Frysinger gentoo.org> --- bin/dispatch-conf | 37 ++++++++++++++++++++++++------------= - pym/portage/dispatch_conf.py | 8 ++++---- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/bin/dispatch-conf b/bin/dispatch-conf index a778118..139a001 100755 --- a/bin/dispatch-conf +++ b/bin/dispatch-conf @@ -27,13 +27,11 @@ except ImportError: from portage import os from portage import dispatch_conf from portage import _unicode_decode -from portage.dispatch_conf import diffstatusoutput_len +from portage.dispatch_conf import diffstatusoutput from portage.process import find_binary =20 FIND_EXTANT_CONFIGS =3D "find '%s' %s -name '._cfg????_%s' ! -name '.*~= ' ! -iname '.*.bak' -print" DIFF_CONTENTS =3D "diff -Nu '%s' '%s'" -DIFF_CVS_INTERP =3D "diff -Nu '%s' '%s' | grep '^[+-][^+-]' | grep = -v '# .Header:.*'" -DIFF_WSCOMMENTS =3D "diff -Nu '%s' '%s' | grep '^[+-][^+-]' | grep = -v '^[-+]#' | grep -v '^[-+][[:space:]]*$'" =20 # We need a secure scratch dir and python does silly verbose errors on t= he use of tempnam oldmask =3D os.umask(0o077) @@ -62,7 +60,7 @@ def cleanup(mydir=3DSCRATCH_DIR): shutil.rmtree(mydir) atexit.register(cleanup) =20 -MANDATORY_OPTS =3D [ 'archive-dir', 'diff', 'replace-cvs', 'replace-wsc= omments', 'merge' ] +MANDATORY_OPTS =3D [ 'archive-dir', 'diff', 'replace-cvs', 'replace-wsco= mments', 'merge' ] =20 def cmd_var_is_valid(cmd): """ @@ -152,6 +150,9 @@ class dispatch: portage.util.shlex_split( portage.settings.get('CONFIG_PROTECT_MASK', ''))) =20 + def diff(file1, file2): + return diffstatusoutput(DIFF_CONTENTS, file1, file2) + # # Remove new configs identical to current # and @@ -168,11 +169,11 @@ class dispatch: else: mrgfail =3D portage.dispatch_conf.file_archive(archive, = conf['current'], conf['new'], mrgconf) if os.path.exists(archive + '.dist'): - unmodified =3D diffstatusoutput_len(DIFF_CONTENTS % (con= f['current'], archive + '.dist'))[1] =3D=3D 0 + unmodified =3D len(diff(conf['current'], archive + '.dis= t')[1]) =3D=3D 0 else: unmodified =3D 0 if os.path.exists(mrgconf): - if mrgfail or diffstatusoutput_len(DIFF_CONTENTS % (conf= ['new'], mrgconf))[1] =3D=3D 0: + if mrgfail or len(diff(conf['new'], mrgconf)[1]) =3D=3D = 0: os.unlink(mrgconf) newconf =3D conf['new'] else: @@ -183,24 +184,34 @@ class dispatch: if newconf =3D=3D mrgconf and \ self.options.get('ignore-previously-merged') !=3D 'yes' = and \ os.path.exists(archive+'.dist') and \ - diffstatusoutput_len(DIFF_CONTENTS % (archive+'.dist', c= onf['new']))[1] =3D=3D 0: + len(diff(archive+'.dist', conf['new'])[1]) =3D=3D 0: # The current update is identical to the archived .dist # version that has previously been merged. os.unlink(mrgconf) newconf =3D conf['new'] =20 - mystatus, myoutput_len =3D diffstatusoutput_len( - DIFF_CONTENTS % (conf ['current'], newconf)) + mystatus, myoutput =3D diff(conf['current'], newconf) + myoutput_len =3D len(myoutput) same_file =3D 0 =3D=3D myoutput_len if mystatus >> 8 =3D=3D 2: # Binary files differ same_cvs =3D False same_wsc =3D False else: - same_cvs =3D 0 =3D=3D diffstatusoutput_len( - DIFF_CVS_INTERP % (conf ['current'], newconf))[1] - same_wsc =3D 0 =3D=3D diffstatusoutput_len( - DIFF_WSCOMMENTS % (conf ['current'], newconf))[1] + # Extract all the normal diff lines (ignore the headers)= . + mylines =3D re.findall('^[+-][^\n+-].*$', myoutput, re.M= ULTILINE) + + # Filter out all the cvs headers + cvs_header =3D re.compile('# [$]Header:') + cvs_lines =3D list(filter(cvs_header.search, mylines)) + same_cvs =3D len(mylines) =3D=3D len(cvs_lines) + + # Filter out comments and whitespace-only changes. + # Note: be nice to also ignore lines that only differ in= whitespace... + wsc_lines =3D [] + for x in ['^[-+]\s*#', '^[-+]\s*$']: + wsc_lines +=3D list(filter(re.compile(x).match, mylin= es)) + same_wsc =3D len(mylines) =3D=3D len(wsc_lines) =20 # Do options permit? same_cvs =3D same_cvs and self.options['replace-cvs'] =3D=3D= 'yes' diff --git a/pym/portage/dispatch_conf.py b/pym/portage/dispatch_conf.py index 7f407ff..6e8de0f 100644 --- a/pym/portage/dispatch_conf.py +++ b/pym/portage/dispatch_conf.py @@ -23,18 +23,18 @@ RCS_MERGE =3D "rcsmerge -p -r" + RCS_BRANCH + " '%s' = > '%s'" =20 DIFF3_MERGE =3D "diff3 -mE '%s' '%s' '%s' > '%s'" =20 -def diffstatusoutput_len(cmd): +def diffstatusoutput(cmd, file1, file2): """ Execute the string cmd in a shell with getstatusoutput() and return = a - 2-tuple (status, output_length). If getstatusoutput() raises + 2-tuple (status, output). If getstatusoutput() raises UnicodeDecodeError (known to happen with python3.1), return a 2-tuple (1, 1). This provides a simple way to check for non-zero output length of diff commands, while providing simple handling of UnicodeDecodeError when necessary. """ try: - status, output =3D portage.subprocess_getstatusoutput(cmd) - return (status, len(output)) + status, output =3D portage.subprocess_getstatusoutput(cmd % (fil= e1, file2)) + return (status, output) except UnicodeDecodeError: return (1, 1) =20