You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rj...@apache.org on 2014/09/22 22:46:09 UTC
svn commit: r1626890 - in /lucene/dev/trunk:
dev-tools/scripts/createPatch.py dev-tools/scripts/diffSources.py
lucene/CHANGES.txt
Author: rjernst
Date: Mon Sep 22 20:46:08 2014
New Revision: 1626890
URL: http://svn.apache.org/r1626890
Log:
LUCENE-5962: Rename diffSources.py to createPatch.py and make work it work with all text file types
Added:
lucene/dev/trunk/dev-tools/scripts/createPatch.py
- copied, changed from r1626821, lucene/dev/trunk/dev-tools/scripts/diffSources.py
Removed:
lucene/dev/trunk/dev-tools/scripts/diffSources.py
Modified:
lucene/dev/trunk/lucene/CHANGES.txt
Copied: lucene/dev/trunk/dev-tools/scripts/createPatch.py (from r1626821, lucene/dev/trunk/dev-tools/scripts/diffSources.py)
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/dev-tools/scripts/createPatch.py?p2=lucene/dev/trunk/dev-tools/scripts/createPatch.py&p1=lucene/dev/trunk/dev-tools/scripts/diffSources.py&r1=1626821&r2=1626890&rev=1626890&view=diff
==============================================================================
--- lucene/dev/trunk/dev-tools/scripts/diffSources.py (original)
+++ lucene/dev/trunk/dev-tools/scripts/createPatch.py Mon Sep 22 20:46:08 2014
@@ -12,61 +12,120 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
+'''
+Creates a unified diff, applyable by the patch tool, between two source checkouts.
-import subprocess
-import sys
-import os
-
-# recursive, unified output format, treat missing files as present but empty
-DIFF_FLAGS = '-ruN'
+Note that .gitignore or svn:ignore rules are used to filter out files that would normally
+not be checked in.
-if '-skipWhitespace' in sys.argv:
- sys.argv.remove('-skipWhitespace')
- # ignores only whitespace changes
- DIFF_FLAGS += 'bBw'
-
-if len(sys.argv) != 3:
- print
- print 'Usage: python -u diffSources.py <dir1> <dir2> [-skipWhitespace]'
- print
- print '''This tool creates an applying patch between two directories.
-
-While you could use this to make a committable patch from a branch, that approach loses
-the svn history from the branch (better to use "svn merge --reintegrate", for example). This
-diff output should not be considered "authoritative" from a merging standpoint as it does
-not reflect what svn will do on merge.
+While you could use this to make a committable patch from a branch,
+that approach loses the svn history from the branch (better to use
+"svn merge --reintegrate", for example). This diff output should
+not be considered "authoritative" from a merging standpoint as it
+does not reflect what svn will do on merge.
'''
- print
- sys.exit(0)
-p = subprocess.Popen(['diff', DIFF_FLAGS, '-x', '.svn', '-x', 'build', sys.argv[1], sys.argv[2]], shell=False, stdout=subprocess.PIPE)
+from argparse import ArgumentParser, RawTextHelpFormatter
+import os
+import subprocess
+import sys
+
+def make_filter_func(src_dir):
+ if os.path.exists(os.path.join(src_dir, '.git')):
+ def git_filter(filename):
+ rc = subprocess.call('git --git-dir=%s check-ignore %s' % (src_dir, filename), shell=True)
+ return rc == 0
+ return git_filter
+
+ else:
+ def svn_filter(filename):
+ # we can't find if svn will ignore a file unless it exists...
+ created = False
+ if not os.path.exists(filename):
+ head,tail = os.path.split(filename)
+ # find a parent directory that already exists, so we
+ # can see if that is ignored by svn
+ while not os.path.exists(head):
+ filename = head
+ head,tail = os.path.split(filename)
+ created = True
+ subprocess.check_call('touch %s' % filename, shell=True)
+ try:
+ output = subprocess.check_output('svn status %s' % filename,
+ shell=True, stderr=subprocess.STDOUT).strip()
+ return output.startswith(b'I')
+ finally:
+ if created and os.path.exists(filename):
+ os.remove(filename)
+
+ return svn_filter
+
+def print_filtered_output(output, should_filter):
+ filtering = False
+ line = output.readline()
+ while line:
+
+ if line.startswith(b'diff '):
+ fromfile, tofile = line.decode('utf-8').split()[-2:]
+ if os.path.exists(fromfile) or \
+ os.path.exists(tofile):
+ filtering = should_filter(fromfile)
+ else:
+ # If both files do not exist, then the filename must contain spaces,
+ # which breaks our split logic. In this case, just ignore, since
+ # patch cannot handle filenames with spaces anyways.
+ filtering = True
+ elif line.startswith(b'Binary files'):
+ filtering = True
+
+ if not filtering:
+ print(line.decode('utf-8'), end='')
+
+ line = output.readline()
+
+def run_diff(from_dir, to_dir, skip_whitespace):
+ flags = '-ruN'
+ if skip_whitespace:
+ flags += 'bBw'
+
+ args = ['diff', flags]
+ for ignore in ('.svn', '.git', 'build', '.caches'):
+ args.append('-x')
+ args.append(ignore)
+ args.append(from_dir)
+ args.append(to_dir)
+
+ return subprocess.Popen(args, shell=False, stdout=subprocess.PIPE)
+
+def parse_config():
+ parser = ArgumentParser(description=__doc__, formatter_class=RawTextHelpFormatter)
+ parser.add_argument('--skip-whitespace', action='store_true', default=False,
+ help='Ignore whitespace differences')
+ parser.add_argument('from_dir', help='Source directory to diff from')
+ parser.add_argument('to_dir', help='Source directory to diff to')
+ c = parser.parse_args()
+
+ if not os.path.isdir(c.from_dir):
+ parser.error('\'from\' path %s is not a valid directory' % c.from_dir)
+ if not os.path.exists(os.path.join(c.from_dir, 'lucene', 'CHANGES.txt')):
+ parser.error('\'from\' path %s is not a valid lucene/solr checkout' % c.from_dir)
+ if not os.path.isdir(c.to_dir):
+ parser.error('\'to\' path %s is not a valid directory' % c.to_dir)
+ if not os.path.exists(os.path.join(c.to_dir, 'lucene', 'CHANGES.txt')):
+ parser.error('\'to\' path %s is not a valid lucene/solr checkout' % c.to_dir)
+
+ return c
+
+def main():
+ c = parse_config()
+
+ p = run_diff(c.from_dir, c.to_dir, c.skip_whitespace)
+ should_filter = make_filter_func(c.from_dir)
+ print_filtered_output(p.stdout, should_filter)
+
+if __name__ == '__main__':
+ try:
+ main()
+ except KeyboardInterrupt:
+ print('\nReceived Ctrl-C, exiting early')
-keep = False
-while True:
- l = p.stdout.readline()
- if l == '':
- break
- if l.endswith('\r\n'):
- l = l[:-2]
- elif l.endswith('\n'):
- l = l[:-1]
- if l.startswith('diff ') or l.startswith('Binary files '):
-
- if l.endswith('timehints.txt') or l.find('/build/') != -1 or l.find('/.svn/') != -1:
- keep = False
- elif l.lower().startswith('Only in'):
- keep = True
- elif l.find('/META-INF/') != -1:
- keep = True
- else:
- ext = os.path.splitext(l)[-1]
- keep = ext in ('.xml', '.iml', '.html', '.template', '.py', '.g', '.properties', '.java')
-
- if keep:
- print
- print
- print l.strip()
- elif keep:
- print l
- elif l.startswith('Only in'):
- print l.strip()
Modified: lucene/dev/trunk/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/CHANGES.txt?rev=1626890&r1=1626889&r2=1626890&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/CHANGES.txt (original)
+++ lucene/dev/trunk/lucene/CHANGES.txt Mon Sep 22 20:46:08 2014
@@ -193,6 +193,9 @@ Build
* LUCENE-5902: Add bumpVersion.py script to manage version increase after release branch is cut.
+* LUCENE-5962: Rename diffSources.py to createPatch.py and make it work with all text file types.
+ (Ryan Ernst)
+
Other
* LUCENE-5563: Removed sep layout: which has fallen behind on features and doesn't