File: diffSources.py

package info (click to toggle)
lucene-solr 3.6.2%2Bdfsg-27
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 91,144 kB
  • sloc: java: 465,555; xml: 24,939; javascript: 5,291; ruby: 3,453; jsp: 2,637; python: 1,619; sh: 1,556; perl: 1,407; cpp: 305; makefile: 41
file content (61 lines) | stat: -rw-r--r-- 2,285 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# 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.

import subprocess
import sys

# recursive, unified output format, treat missing files as present but empty
DIFF_FLAGS = '-ruN'

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.
'''
  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)

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 '):
    keep = l.lower().find('/build/') == -1 and (l.lower().startswith('Only in') or ((l.lower().endswith('.java') or l.lower().endswith('.txt') or l.lower().endswith('.xml') or l.lower().endswith('.iml')) and l.find('/.svn/') == -1))
    if keep:
      print
      print
      print l.strip()
  elif keep:
    print l
  elif l.startswith('Only in'):
    print l.strip()