1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-12-25 17:36:13 +01:00

- get_diff: don't diff binary files

This commit is contained in:
Marcus Huewe 2010-08-31 11:20:34 +02:00
parent 9c2f1d85ca
commit 9c5c329a04
21 changed files with 64 additions and 6 deletions

View File

@ -1340,8 +1340,9 @@ class Package:
deleted = []
def diff_add_delete(fname, add, revision):
diff = []
diff.append(diff_hdr % f)
diff.append(diff_hdr % fname)
tmpfile = None
origname = fname
if add:
diff.append('--- %s\t(revision 0)\n' % fname)
rev = 'revision 0'
@ -1357,8 +1358,15 @@ class Package:
try:
if revision is not None and not add:
(fd, tmpfile) = tempfile.mkstemp(prefix='osc_diff')
get_source_file(self.apiurl, self.prjname, self.name, os.path.basename(f), tmpfile, revision)
get_source_file(self.apiurl, self.prjname, self.name, origname, tmpfile, revision)
fname = tmpfile
if binary_file(fname):
what = 'added'
if not add:
what = 'deleted'
diff = diff[:1]
diff.append('Binary file \'%s\' %s.\n' % (origname, what))
return diff
tmpl = '+%s'
ltmpl = '@@ -0,0 +1,%d @@\n'
if not add:
@ -3357,7 +3365,7 @@ def get_source_file_diff(dir, filename, rev, oldfilename = None, olddir = None,
file1 = os.path.join(olddir, oldfilename) # old/stored original
file2 = os.path.join(dir, filename) # working copy
if binary_file(file1) or binary_file(file2):
return ['Binary file %s has changed\n' % origfilename]
return ['Binary file \'%s\' has changed.\n' % origfilename]
f1 = f2 = None
try:

View File

@ -0,0 +1 @@
http://localhost

View File

@ -0,0 +1,4 @@
<directory name="binary" rev="2" srcmd5="2df1eacfe03a3bec2112529e7f4dc39a" vrev="2">
<entry md5="8f618462e00017108b4146a29e074bdf" mtime="1111111111" name="binary" size="18" />
<entry md5="ee813c93cb5730dce38976695634482f" mtime="1111111111" name="binary_deleted" size="26" />
</directory>

View File

@ -0,0 +1 @@
1.0

View File

@ -0,0 +1 @@
binary

View File

@ -0,0 +1 @@
osctest

View File

@ -0,0 +1 @@
binary_added

View File

@ -0,0 +1 @@
binary_deleted

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -2,4 +2,5 @@
<entry md5="0d62ceea6020d75154078a20d8c9f9ba" mtime="1282047302" name="foo" size="23" />
<entry md5="17b9e9e1a032ed44e7a584dc6303ffa8" mtime="1282047303" name="merge" size="48" />
<entry md5="7efa70f68983fad1cf487f69dedf93e9" mtime="1282047303" name="nochange" size="25" />
</directory>
<entry md5="b1b642cdbacf9956104f8565e297ed00" mtime="1283246089" name="binary" size="27" />
</directory>

Binary file not shown.

View File

@ -3,4 +3,5 @@
<entry md5="17b9e9e1a032ed44e7a584dc6303ffa8" mtime="1282047303" name="merge" size="48" />
<entry md5="7efa70f68983fad1cf487f69dedf93e9" mtime="1282047303" name="nochange" size="25" />
<entry md5="136a96e1470ec7424bc8ae47612977db" mtime="1282914026" name="foobar" size="14" />
<entry md5="9b55c93ffec5ef8850c84882de7ef6b5" mtime="1283242538" name="binary" size="7" />
</directory>

View File

@ -2,4 +2,5 @@
<entry md5="0d62ceea6020d75154078a20d8c9f9ba" mtime="1282047302" name="foo" size="23" />
<entry md5="17b9e9e1a032ed44e7a584dc6303ffa8" mtime="1282047303" name="merge" size="48" />
<entry md5="7efa70f68983fad1cf487f69dedf93e9" mtime="1282047303" name="nochange" size="25" />
<entry md5="b1b642cdbacf9956104f8565e297ed00" mtime="1283246089" name="binary" size="27" />
</directory>

View File

@ -133,6 +133,37 @@ class TestDiffFiles(OscTestCase):
@@ -1,1 +0,0 @@
-some content
""" % (TestDiffFiles.diff_hdr % 'nochange', TestDiffFiles.diff_hdr % 'somefile')
self.__check_diff(p, exp, None)
def testDiffBinaryAdded(self):
"""diff an added binary file"""
self._change_to_pkg('binary')
p = osc.core.Package('.')
p.todo = ['binary_added']
exp = """%s
Binary file 'binary_added' added.
""" % (TestDiffFiles.diff_hdr % 'binary_added')
self.__check_diff(p, exp, None)
def testDiffBinaryDeleted(self):
"""diff a deleted binary file"""
self._change_to_pkg('binary')
p = osc.core.Package('.')
p.todo = ['binary_deleted']
exp = """%s
Binary file 'binary_deleted' deleted.
""" % (TestDiffFiles.diff_hdr % 'binary_deleted')
self.__check_diff(p, exp, None)
def testDiffBinaryModified(self):
"""diff a modified binary file"""
self._change_to_pkg('binary')
p = osc.core.Package('.')
p.todo = ['binary']
exp = """%s
Binary file 'binary' has changed.
""" % (TestDiffFiles.diff_hdr % 'binary')
self.__check_diff(p, exp, None)
# diff with revision
@GET('http://localhost/source/osctest/remote_simple_noadd?rev=3', file='testDiffRemoteNoChange_files')
@ -182,6 +213,7 @@ class TestDiffFiles(OscTestCase):
@GET('http://localhost/source/osctest/remote_simple_noadd?rev=3', file='testDiffRemoteExistingLocalNotExisting_files')
@GET('http://localhost/source/osctest/remote_simple_noadd/foobar?rev=3', file='testDiffRemoteExistingLocalNotExisting_foobar')
@GET('http://localhost/source/osctest/remote_simple_noadd/binary?rev=3', file='testDiffRemoteExistingLocalNotExisting_binary')
def testDiffRemoteExistingLocalNotExisting(self):
"""
a file doesn't exist in the local wc but exists
@ -195,11 +227,14 @@ class TestDiffFiles(OscTestCase):
@@ -1,2 +0,0 @@
-foobar
-barfoo
""" % (TestDiffFiles.diff_hdr % 'foobar')
%s
Binary file 'binary' deleted.
""" % (TestDiffFiles.diff_hdr % 'foobar', TestDiffFiles.diff_hdr % 'binary')
self.__check_diff(p, exp, 3)
@GET('http://localhost/source/osctest/remote_localmodified?rev=3', file='testDiffRemoteUnchangedLocalModified_files')
@GET('http://localhost/source/osctest/remote_localmodified/nochange?rev=3', file='testDiffRemoteUnchangedLocalModified_nochange')
@GET('http://localhost/source/osctest/remote_localmodified/binary?rev=3', file='testDiffRemoteUnchangedLocalModified_binary')
def testDiffRemoteUnchangedLocalModified(self):
"""remote revision didn't change, local file is modified"""
self._change_to_pkg('remote_localmodified')
@ -210,7 +245,9 @@ class TestDiffFiles(OscTestCase):
@@ -1,1 +1,2 @@
This file didn't change.
+oh it does
""" % (TestDiffFiles.diff_hdr % 'nochange')
%s
Binary file 'binary' has changed.
""" % (TestDiffFiles.diff_hdr % 'nochange', TestDiffFiles.diff_hdr % 'binary')
self.__check_diff(p, exp, 3)
@GET('http://localhost/source/osctest/remote_simple_noadd?rev=3', file='testDiffRemoteMissingLocalExisting_files')