From: "Mike Frysinger" <vapier@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: bin/, pym/portage/
Date: Sun, 11 Mar 2012 01:40:33 +0000 (UTC) [thread overview]
Message-ID: <1331430029.3467a10ba5eb37f67899e772c2951992dc28f46c.vapier@gentoo> (raw)
commit: 3467a10ba5eb37f67899e772c2951992dc28f46c
Author: Mike Frysinger <vapier <AT> gentoo <DOT> org>
AuthorDate: Thu Mar 8 21:47:16 2012 +0000
Commit: Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Sun Mar 11 01:40:29 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=3467a10b
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 <vapier <AT> 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
FIND_EXTANT_CONFIGS = "find '%s' %s -name '._cfg????_%s' ! -name '.*~' ! -iname '.*.bak' -print"
DIFF_CONTENTS = "diff -Nu '%s' '%s'"
-DIFF_CVS_INTERP = "diff -Nu '%s' '%s' | grep '^[+-][^+-]' | grep -v '# .Header:.*'"
-DIFF_WSCOMMENTS = "diff -Nu '%s' '%s' | grep '^[+-][^+-]' | grep -v '^[-+]#' | grep -v '^[-+][[:space:]]*$'"
# We need a secure scratch dir and python does silly verbose errors on the use of tempnam
oldmask = os.umask(0o077)
@@ -62,7 +60,7 @@ def cleanup(mydir=SCRATCH_DIR):
shutil.rmtree(mydir)
atexit.register(cleanup)
-MANDATORY_OPTS = [ 'archive-dir', 'diff', 'replace-cvs', 'replace-wscomments', 'merge' ]
+MANDATORY_OPTS = [ 'archive-dir', 'diff', 'replace-cvs', 'replace-wscomments', 'merge' ]
def cmd_var_is_valid(cmd):
"""
@@ -152,6 +150,9 @@ class dispatch:
portage.util.shlex_split(
portage.settings.get('CONFIG_PROTECT_MASK', '')))
+ 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 = portage.dispatch_conf.file_archive(archive, conf['current'], conf['new'], mrgconf)
if os.path.exists(archive + '.dist'):
- unmodified = diffstatusoutput_len(DIFF_CONTENTS % (conf['current'], archive + '.dist'))[1] == 0
+ unmodified = len(diff(conf['current'], archive + '.dist')[1]) == 0
else:
unmodified = 0
if os.path.exists(mrgconf):
- if mrgfail or diffstatusoutput_len(DIFF_CONTENTS % (conf['new'], mrgconf))[1] == 0:
+ if mrgfail or len(diff(conf['new'], mrgconf)[1]) == 0:
os.unlink(mrgconf)
newconf = conf['new']
else:
@@ -183,24 +184,34 @@ class dispatch:
if newconf == mrgconf and \
self.options.get('ignore-previously-merged') != 'yes' and \
os.path.exists(archive+'.dist') and \
- diffstatusoutput_len(DIFF_CONTENTS % (archive+'.dist', conf['new']))[1] == 0:
+ len(diff(archive+'.dist', conf['new'])[1]) == 0:
# The current update is identical to the archived .dist
# version that has previously been merged.
os.unlink(mrgconf)
newconf = conf['new']
- mystatus, myoutput_len = diffstatusoutput_len(
- DIFF_CONTENTS % (conf ['current'], newconf))
+ mystatus, myoutput = diff(conf['current'], newconf)
+ myoutput_len = len(myoutput)
same_file = 0 == myoutput_len
if mystatus >> 8 == 2:
# Binary files differ
same_cvs = False
same_wsc = False
else:
- same_cvs = 0 == diffstatusoutput_len(
- DIFF_CVS_INTERP % (conf ['current'], newconf))[1]
- same_wsc = 0 == diffstatusoutput_len(
- DIFF_WSCOMMENTS % (conf ['current'], newconf))[1]
+ # Extract all the normal diff lines (ignore the headers).
+ mylines = re.findall('^[+-][^\n+-].*$', myoutput, re.MULTILINE)
+
+ # Filter out all the cvs headers
+ cvs_header = re.compile('# [$]Header:')
+ cvs_lines = list(filter(cvs_header.search, mylines))
+ same_cvs = len(mylines) == len(cvs_lines)
+
+ # Filter out comments and whitespace-only changes.
+ # Note: be nice to also ignore lines that only differ in whitespace...
+ wsc_lines = []
+ for x in ['^[-+]\s*#', '^[-+]\s*$']:
+ wsc_lines += list(filter(re.compile(x).match, mylines))
+ same_wsc = len(mylines) == len(wsc_lines)
# Do options permit?
same_cvs = same_cvs and self.options['replace-cvs'] == '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 = "rcsmerge -p -r" + RCS_BRANCH + " '%s' > '%s'"
DIFF3_MERGE = "diff3 -mE '%s' '%s' '%s' > '%s'"
-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 = portage.subprocess_getstatusoutput(cmd)
- return (status, len(output))
+ status, output = portage.subprocess_getstatusoutput(cmd % (file1, file2))
+ return (status, output)
except UnicodeDecodeError:
return (1, 1)
next reply other threads:[~2012-03-11 1:40 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-11 1:40 Mike Frysinger [this message]
-- strict thread matches above, loose matches on Subject: below --
2014-11-17 17:43 [gentoo-commits] proj/portage:master commit in: bin/, pym/portage/ Zac Medico
2013-11-29 23:24 Mike Frysinger
2013-06-25 7:48 Zac Medico
2013-06-23 22:57 Zac Medico
2013-06-23 22:40 Zac Medico
2013-02-11 9:39 Zac Medico
2013-01-19 5:16 Zac Medico
2013-01-19 5:00 Zac Medico
2013-01-19 3:23 Zac Medico
2013-01-19 3:23 Zac Medico
2013-01-19 2:27 Zac Medico
2013-01-19 1:53 Zac Medico
2012-10-18 0:05 Zac Medico
2012-03-17 16:44 Zac Medico
2011-12-08 7:26 Zac Medico
2011-06-17 22:35 Zac Medico
2011-06-04 1:39 Zac Medico
2011-02-20 0:00 Zac Medico
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1331430029.3467a10ba5eb37f67899e772c2951992dc28f46c.vapier@gentoo \
--to=vapier@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox