1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-09-20 01:06:17 +02:00

- rewrote "def commit"

- the upload revision isn't used anymore instead we commit via
  cmd=commitfilelist
- extended and adjusted testcases
This commit is contained in:
Marcus Huewe 2010-09-03 17:46:01 +02:00
parent 5c8b258a6b
commit 57a3832a8e
61 changed files with 377 additions and 117 deletions

View File

@ -923,28 +923,77 @@ class Package:
u = makeurl(self.apiurl, ['source', self.prjname, self.name, pathname2url(n)], query=query)
http_DELETE(u)
def put_source_file(self, n):
# escaping '+' in the URL path (note: not in the URL query string) is
# only a workaround for ruby on rails, which swallows it otherwise
query = 'rev=upload'
u = makeurl(self.apiurl, ['source', self.prjname, self.name, pathname2url(n)], query=query)
http_PUT(u, file = os.path.join(self.dir, n))
shutil.copyfile(os.path.join(self.dir, n), os.path.join(self.storedir, n))
def put_source_file(self, n, copy_only=False):
cdir = os.path.join(self.storedir, '_in_commit')
try:
if not os.path.isdir(cdir):
os.mkdir(cdir)
query = 'rev=repository'
tmpfile = os.path.join(cdir, n)
shutil.copyfile(os.path.join(self.dir, n), tmpfile)
# escaping '+' in the URL path (note: not in the URL query string) is
# only a workaround for ruby on rails, which swallows it otherwise
if not copy_only:
u = makeurl(self.apiurl, ['source', self.prjname, self.name, pathname2url(n)], query=query)
http_PUT(u, file = os.path.join(self.dir, n))
os.rename(tmpfile, os.path.join(self.storedir, n))
finally:
if os.path.isdir(cdir):
shutil.rmtree(cdir)
if n in self.to_be_added:
self.to_be_added.remove(n)
def __generate_commitlist(self, todo_send):
root = ET.Element('directory')
keys = todo_send.keys()
keys.sort()
for i in keys:
ET.SubElement(root, 'entry', name=i, md5=todo_send[i])
return root
def __send_commitlog(self, msg, local_filelist):
"""send the commitlog and the local filelist to the server"""
query = {'cmd' : 'commitfilelist',
'user' : conf.get_apiurl_usr(self.apiurl),
'comment': msg}
if self.islink() and self.isexpanded():
query['keeplink'] = '1'
if conf.config['linkcontrol'] or self.isfrozen():
query['linkrev'] = self.linkinfo.srcmd5
if self.ispulled():
query['repairlink'] = '1'
query['linkrev'] = self.get_pulled_srcmd5()
if self.islinkrepair():
query['repairlink'] = '1'
u = makeurl(self.apiurl, ['source', self.prjname, self.name], query=query)
f = http_POST(u, data=ET.tostring(local_filelist))
root = ET.parse(f).getroot()
return root
def __get_todo_send(self, server_filelist):
"""parse todo from a previous __send_commitlog call"""
error = server_filelist.get('error')
if error is None:
return []
elif error != 'missing':
raise oscerr.PackageInternalError(self.prjname, self.name,
'__get_todo_send: unexpected \'error\' attr: \'%s\'' % error)
todo = []
for n in server_filelist.findall('entry'):
name = n.get('name')
if name is None:
raise oscerr.APIError('missing \'name\' attribute:\n%s\n' % ET.tostring(server_filelist))
todo.append(n.get('name'))
return todo
def commit(self, msg='', validators=None, verbose_validation=None):
todo_send = []
todo_delete = []
# commit only if the upstream revision is the same as the working copy's
upstream_rev = self.latest_rev()
if self.rev != upstream_rev:
raise oscerr.WorkingCopyOutdated((self.absdir, self.rev, upstream_rev))
if not self.todo:
self.todo = self.filenamelist_unvers + self.filenamelist
self.todo = [i for i in self.to_be_added if not i in self.filenamelist] + self.filenamelist
pathn = getTransActPath(self.dir)
@ -965,74 +1014,69 @@ class Package:
if p.wait() != 0:
raise oscerr.ExtRuntimeError(p.stdout, validator )
have_conflicts = False
for filename in self.todo:
if not filename.startswith('_service:') and not filename.startswith('_service_'):
st = self.status(filename)
if st == 'A' or st == 'M' or st == 'R':
todo_send.append(filename)
todo_send = {}
todo_delete = []
real_send = []
for filename in self.filenamelist + [i for i in self.to_be_added if not i in self.filenamelist]:
if filename.startswith('_service:') or filename.startswith('_service_'):
continue
st = self.status(filename)
if st == 'C':
print 'Please resolve all conflicts before committing using "osc resolved FILE"!'
return 1
elif filename in self.todo:
if st in ('A', 'R', 'M'):
todo_send[filename] = dgst(os.path.join(self.absdir, filename))
real_send.append(filename)
print statfrmt('Sending', os.path.join(pathn, filename))
elif st in (' ', '!', 'S'):
f = self.findfilebyname(filename)
if f is None:
raise oscerr.PackageInternalError(self.prjname, self.name,
'error: file \'%s\' with state \'%s\' is not known by meta' \
% (filename, st))
todo_send[filename] = f.md5
elif st == 'D':
todo_delete.append(filename)
print statfrmt('Deleting', os.path.join(pathn, filename))
elif st == 'C':
have_conflicts = True
elif st in ('R', 'M', 'D', ' ', '!', 'S'):
f = self.findfilebyname(filename)
if f is None:
raise oscerr.PackageInternalError(self.prjname, self.name,
'error: file \'%s\' with state \'%s\' is not known by meta' \
% (filename, st))
todo_send[filename] = f.md5
if have_conflicts:
print 'Please resolve all conflicts before committing using "osc resolved FILE"!'
return 1
if not todo_send and not todo_delete and not self.rev == "upload" and not self.islinkrepair() and not self.ispulled():
if not real_send and not todo_delete and not self.islinkrepair() and not self.ispulled():
print 'nothing to do for package %s' % self.name
return 1
if self.islink() and self.isexpanded():
# resolve the link into the upload revision
# XXX: do this always?
query = { 'cmd': 'copy', 'rev': 'upload', 'orev': self.rev }
u = makeurl(self.apiurl, ['source', self.prjname, self.name], query=query)
f = http_POST(u)
print 'Transmitting file data ',
try:
for filename in todo_delete:
# do not touch local files on commit --
# delete remotely instead
self.delete_remote_source_file(filename)
self.to_be_deleted.remove(filename)
for filename in todo_send:
filelist = self.__generate_commitlist(todo_send)
sfilelist = self.__send_commitlog(msg, filelist)
send = self.__get_todo_send(sfilelist)
real_send = [i for i in real_send if not i in send]
# abort after 3 tries
tries = 3
while len(send) and tries:
for filename in send[:]:
sys.stdout.write('.')
sys.stdout.flush()
self.put_source_file(filename)
send.remove(filename)
tries -= 1
sfilelist = self.__send_commitlog(msg, filelist)
send = self.__get_todo_send(sfilelist)
if len(send):
raise oscerr.PackageInternalError(self.prjname, self.name,
'server does not accept filelist:\n%s\nmissing:\n%s\n' \
% (ET.tostring(filelist), ET.tostring(sfilelist)))
# these files already exist on the server
# just copy them into the storedir
for filename in real_send:
self.put_source_file(filename, copy_only=True)
# all source files are committed - now comes the log
query = { 'cmd' : 'commit',
'rev' : 'upload',
'user' : conf.get_apiurl_usr(self.apiurl),
'comment': msg }
if self.islink() and self.isexpanded():
query['keeplink'] = '1'
if conf.config['linkcontrol'] or self.isfrozen():
query['linkrev'] = self.linkinfo.srcmd5
if self.ispulled():
query['repairlink'] = '1'
query['linkrev'] = self.get_pulled_srcmd5()
if self.islinkrepair():
query['repairlink'] = '1'
u = makeurl(self.apiurl, ['source', self.prjname, self.name], query=query)
f = http_POST(u)
except Exception, e:
# delete upload revision
try:
query = { 'cmd': 'deleteuploadrev' }
u = makeurl(self.apiurl, ['source', self.prjname, self.name], query=query)
f = http_POST(u)
except:
pass
raise e
root = ET.parse(f).getroot()
self.rev = int(root.get('rev'))
self.rev = sfilelist.get('rev')
print
print 'Committed revision %s.' % self.rev
@ -1043,17 +1087,24 @@ class Package:
self.linkrepair = False
# XXX: mark package as invalid?
print 'The source link has been repaired. This directory can now be removed.'
if self.islink() and self.isexpanded():
self.update_local_filesmeta(revision=self.latest_rev())
else:
self.update_local_filesmeta(self.rev)
li = Linkinfo()
li.read(sfilelist.find('linkinfo'))
if li.xsrcmd5 is None:
raise oscerr.APIError('linkinfo has no xsrcmd5 attr:\n%s\n' % ET.tostring(sfilelist))
sfilelist = ET.fromstring(self.get_files_meta(revision=li.xsrcmd5))
for i in sfilelist.findall('entry'):
if i.get('name') in self.skipped:
i.set('skipped', 'true')
store_write_string(self.absdir, '_files', ET.tostring(sfilelist) + '\n')
for filename in todo_delete:
self.to_be_deleted.remove(filename)
self.delete_storefile(filename)
self.write_deletelist()
self.write_addlist()
self.update_datastructs()
for filename in todo_delete:
self.delete_storefile(filename)
if self.filenamelist.count('_service'):
print 'The package contains a source service.'
for filename in self.todo:

View File

@ -1,4 +1,4 @@
<directory name="simple" rev="1" srcmd5="2df1eacfe03a3bec2112529e7f4dc39a" vrev="1">
<directory name="add" rev="1" srcmd5="2df1eacfe03a3bec2112529e7f4dc39a" vrev="1">
<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" />

View File

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

View File

@ -0,0 +1,8 @@
<directory name="allstates" rev="1" srcmd5="2df1eacfe03a3bec2112529e7f4dc39a" vrev="1">
<entry md5="0d62ceea6020d75154078a20d8c9f9ba" mtime="1282047302" name="foo" size="23" />
<entry md5="17b9e9e1a032ed44e7a584dc6303ffa8" mtime="1282047303" name="merge" size="48" />
<entry md5="676513fde5797c3785164942c97dfec1" mtime="1283506309" name="missing" size="8" />
<entry md5="7efa70f68983fad1cf487f69dedf93e9" mtime="1282047303" name="nochange" size="25" />
<entry md5="d8e8fca2dc0f896fd7cb4cb0031ba249" mtime="1283505591" name="test" size="5" />
<entry md5="ffffffffffffffffffffffffffffffff" mtime="1111111111" name="skipped" size="100" skipped="true" />
</directory>

View File

@ -0,0 +1 @@
1.0

View File

@ -0,0 +1 @@
allstates

View File

@ -0,0 +1 @@
osctest

View File

@ -0,0 +1,2 @@
add
missing

View File

@ -0,0 +1 @@
foo

View File

@ -0,0 +1 @@
This is a simple test.

View File

@ -0,0 +1,4 @@
Is it
possible to
merge this file?
I hope so...

View File

@ -0,0 +1 @@
missing

View File

@ -0,0 +1 @@
This file didn't change.

View File

@ -0,0 +1 @@
test

View File

@ -0,0 +1 @@
added file

View File

@ -0,0 +1 @@
replaced

View File

@ -0,0 +1 @@
This file did change.

View File

@ -0,0 +1 @@
test

View File

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

View File

@ -0,0 +1,4 @@
<directory name="unix" rev="9afa23b484de05e28364b18de7bb1432" srcmd5="9afa23b484de05e28364b18de7bb1432">
<linkinfo baserev="b63634ab40861fdb8b44e5f4f459c621" lsrcmd5="cd21541fe2442d3d324a6d6103752913" package="unique" project="btest" srcmd5="b63634ab40861fdb8b44e5f4f459c621" />
<entry md5="75d884cf1d235180faec5acb63063972" mtime="1283525196" name="simple" size="21" />
</directory>

View File

@ -0,0 +1,5 @@
<package project="home:Admin" name="unix">
<title/>
<description>This package was branched from btest in order to ...</description>
<person role="maintainer" userid="Admin"/>
</package>

View File

@ -0,0 +1 @@
1.0

View File

@ -0,0 +1 @@
branch

View File

@ -0,0 +1 @@
osctest

View File

@ -0,0 +1 @@
imple modified file.

View File

@ -0,0 +1,5 @@
<directory name="branch" rev="5" srcmd5="1d4bbfa2655ab3982074226e16e1e5ff" vrev="5">
<linkinfo baserev="b63634ab40861fdb8b44e5f4f459c621" lsrcmd5="1d4bbfa2655ab3982074226e16e1e5ff" package="bar" project="foo" srcmd5="b63634ab40861fdb8b44e5f4f459c621" xsrcmd5="87ea02aede261b0267aabaa97c756e7a" />
<entry md5="542f96b49b64095104d8a9e9dd313a9c" mtime="1283521153" name="_link" size="130" />
<entry md5="75da7f7167c22b2b02c6879366d78ad1" mtime="1283525027" name="simple" size="22" />
</directory>

View File

@ -0,0 +1,4 @@
<directory name="branch" rev="87ea02aede261b0267aabaa97c756e7a" srcmd5="87ea02aede261b0267aabaa97c756e7a">
<linkinfo baserev="b63634ab40861fdb8b44e5f4f459c621" lsrcmd5="1d4bbfa2655ab3982074226e16e1e5ff" package="bar" project="foo" srcmd5="b63634ab40861fdb8b44e5f4f459c621" />
<entry md5="75da7f7167c22b2b02c6879366d78ad1" mtime="1283525027" name="simple" size="22" />
</directory>

View File

@ -0,0 +1,5 @@
<directory name="branch" rev="6" srcmd5="cd21541fe2442d3d324a6d6103752913" vrev="6">
<linkinfo baserev="b63634ab40861fdb8b44e5f4f459c621" lsrcmd5="cd21541fe2442d3d324a6d6103752913" package="bar" project="foo" srcmd5="b63634ab40861fdb8b44e5f4f459c621" xsrcmd5="9afa23b484de05e28364b18de7bb1432" />
<entry md5="542f96b49b64095104d8a9e9dd313a9c" mtime="1283521153" name="_link" size="130" skipped="true" />
<entry md5="75d884cf1d235180faec5acb63063972" mtime="1283525196" name="simple" size="21" />
</directory>

View File

@ -0,0 +1 @@
simple modified file.

View File

@ -1,4 +1,4 @@
<directory name="simple" rev="1" srcmd5="2df1eacfe03a3bec2112529e7f4dc39a" vrev="1">
<directory name="delete" rev="1" srcmd5="2df1eacfe03a3bec2112529e7f4dc39a" vrev="1">
<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" />

View File

@ -1,5 +1,6 @@
<directory name="simple" rev="1" srcmd5="2df1eacfe03a3bec2112529e7f4dc39a" vrev="1">
<directory name="multiple" rev="1" srcmd5="2df1eacfe03a3bec2112529e7f4dc39a" vrev="1">
<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="d8e8fca2dc0f896fd7cb4cb0031ba249" mtime="1283505591" name="test" size="5" />
</directory>

View File

@ -0,0 +1 @@
test

View File

@ -0,0 +1 @@
test

View File

@ -1,4 +1,4 @@
<directory name="simple" rev="1" srcmd5="2df1eacfe03a3bec2112529e7f4dc39a" vrev="1">
<directory name="nochanges" rev="1" srcmd5="2df1eacfe03a3bec2112529e7f4dc39a" vrev="1">
<entry md5="0d62ceea6020d75154078a20d8c9f9ba" mtime="1282047302" name="foo" size="23" skipped="True" />
<entry md5="17b9e9e1a032ed44e7a584dc6303ffa8" mtime="1282047303" name="merge" size="48" />
<entry md5="7efa70f68983fad1cf487f69dedf93e9" mtime="1282047303" name="nochange" size="25" />

View File

@ -0,0 +1 @@
<directory><entry md5="b423d194c75e59ee4d8d2e07ba24323d" name="add" /><entry md5="0d62ceea6020d75154078a20d8c9f9ba" name="foo" /><entry md5="17b9e9e1a032ed44e7a584dc6303ffa8" name="merge" /><entry md5="7efa70f68983fad1cf487f69dedf93e9" name="nochange" /></directory>

View File

@ -0,0 +1,3 @@
<directory error="missing" name="add">
<entry md5="b423d194c75e59ee4d8d2e07ba24323d" name="add" />
</directory>

View File

@ -0,0 +1,8 @@
<directory name="allstates" rev="2" srcmd5="2df1eacfe03a3bec2112529e7f4dc39a" vrev="2">
<entry md5="b423d194c75e59ee4d8d2e07ba24323d" mtime="3333333333" name="add" size="11" />
<entry md5="17b9e9e1a032ed44e7a584dc6303ffa8" mtime="1282047303" name="merge" size="48" />
<entry md5="d908d26cac8092d475f40a5179ca6347" mtime="4444444444" name="missing" size="9" />
<entry md5="2abd19de6a38ff2890af64f453df96b1" mtime="2222222222" name="nochange" size="22" />
<entry md5="d8e8fca2dc0f896fd7cb4cb0031ba249" mtime="1283505591" name="test" size="5" />
<entry md5="ffffffffffffffffffffffffffffffff" mtime="1111111111" name="skipped" size="100" />
</directory>

View File

@ -0,0 +1,8 @@
<directory name="allstates" rev="2" srcmd5="2df1eacfe03a3bec2112529e7f4dc39a" vrev="2">
<entry md5="b423d194c75e59ee4d8d2e07ba24323d" mtime="3333333333" name="add" size="11" />
<entry md5="17b9e9e1a032ed44e7a584dc6303ffa8" mtime="1282047303" name="merge" size="48" />
<entry md5="d908d26cac8092d475f40a5179ca6347" mtime="4444444444" name="missing" size="9" />
<entry md5="2abd19de6a38ff2890af64f453df96b1" mtime="2222222222" name="nochange" size="22" />
<entry md5="d8e8fca2dc0f896fd7cb4cb0031ba249" mtime="1283505591" name="test" size="5" />
<entry md5="ffffffffffffffffffffffffffffffff" mtime="1111111111" name="skipped" size="100" skipped="true" />
</directory>

View File

@ -0,0 +1,8 @@
<directory name="allstates" rev="1" srcmd5="2df1eacfe03a3bec2112529e7f4dc39a" vrev="1">
<entry md5="0d62ceea6020d75154078a20d8c9f9ba" mtime="1282047302" name="foo" size="23" />
<entry md5="17b9e9e1a032ed44e7a584dc6303ffa8" mtime="1282047303" name="merge" size="48" />
<entry md5="676513fde5797c3785164942c97dfec1" mtime="1283506309" name="missing" size="8" />
<entry md5="7efa70f68983fad1cf487f69dedf93e9" mtime="1282047303" name="nochange" size="25" />
<entry md5="d8e8fca2dc0f896fd7cb4cb0031ba249" mtime="1283505591" name="test" size="5" />
<entry md5="ffffffffffffffffffffffffffffffff" mtime="1111111111" name="skipped" size="100" />
</directory>

View File

@ -0,0 +1 @@
<directory><entry md5="b423d194c75e59ee4d8d2e07ba24323d" name="add" /><entry md5="17b9e9e1a032ed44e7a584dc6303ffa8" name="merge" /><entry md5="d908d26cac8092d475f40a5179ca6347" name="missing" /><entry md5="2abd19de6a38ff2890af64f453df96b1" name="nochange" /><entry md5="ffffffffffffffffffffffffffffffff" name="skipped" /><entry md5="d8e8fca2dc0f896fd7cb4cb0031ba249" name="test" /></directory>

View File

@ -0,0 +1,5 @@
<directory error="missing" name="allstates">
<entry md5="b423d194c75e59ee4d8d2e07ba24323d" name="add" />
<entry md5="d908d26cac8092d475f40a5179ca6347" name="missing" />
<entry md5="2abd19de6a38ff2890af64f453df96b1" name="nochange" />
</directory>

View File

@ -0,0 +1 @@
<directory><entry md5="0d62ceea6020d75154078a20d8c9f9ba" name="foo" /><entry md5="17b9e9e1a032ed44e7a584dc6303ffa8" name="merge" /></directory>

View File

@ -0,0 +1,5 @@
<directory name="branch" rev="7" srcmd5="1d4bbfa2655ab3982074226e16e1e5ff" vrev="7">
<linkinfo baserev="b63634ab40861fdb8b44e5f4f459c621" lsrcmd5="1d4bbfa2655ab3982074226e16e1e5ff" package="bar" project="foo" srcmd5="b63634ab40861fdb8b44e5f4f459c621" xsrcmd5="87ea02aede261b0267aabaa97c756e7a" />
<entry md5="542f96b49b64095104d8a9e9dd313a9c" mtime="1283521153" name="_link" size="130" />
<entry md5="75da7f7167c22b2b02c6879366d78ad1" mtime="1283525027" name="simple" size="22" />
</directory>

View File

@ -0,0 +1,4 @@
<directory name="branch" rev="87ea02aede261b0267aabaa97c756e7a" srcmd5="87ea02aede261b0267aabaa97c756e7a">
<linkinfo baserev="b63634ab40861fdb8b44e5f4f459c621" lsrcmd5="1d4bbfa2655ab3982074226e16e1e5ff" package="bar" project="foo" srcmd5="b63634ab40861fdb8b44e5f4f459c621" />
<entry md5="75da7f7167c22b2b02c6879366d78ad1" mtime="1283525027" name="simple" size="22" />
</directory>

View File

@ -0,0 +1,5 @@
<directory name="branch" rev="6" srcmd5="cd21541fe2442d3d324a6d6103752913" vrev="6">
<linkinfo baserev="b63634ab40861fdb8b44e5f4f459c621" lsrcmd5="cd21541fe2442d3d324a6d6103752913" package="bar" project="foo" srcmd5="b63634ab40861fdb8b44e5f4f459c621" xsrcmd5="9afa23b484de05e28364b18de7bb1432" />
<entry md5="542f96b49b64095104d8a9e9dd313a9c" mtime="1283521153" name="_link" size="130" skipped="true" />
<entry md5="75d884cf1d235180faec5acb63063972" mtime="1283525196" name="simple" size="21" />
</directory>

View File

@ -0,0 +1 @@
<directory><entry md5="75da7f7167c22b2b02c6879366d78ad1" name="simple" /></directory>

View File

@ -0,0 +1,3 @@
<directory error="missing" name="branch">
<entry md5="75da7f7167c22b2b02c6879366d78ad1" name="simple" />
</directory>

View File

@ -0,0 +1 @@
<directory><entry md5="0d62ceea6020d75154078a20d8c9f9ba" name="foo" /><entry md5="17b9e9e1a032ed44e7a584dc6303ffa8" name="merge" /><entry md5="382588b92f5976de693f44c4d6df27b7" name="nochange" /></directory>

View File

@ -2,4 +2,5 @@
<entry md5="b423d194c75e59ee4d8d2e07ba24323d" mtime="1111111111" name="add" size="11" />
<entry md5="ea467af882b32a275fe62eb05aba6ee1" mtime="0000000000" name="add2" size="5" />
<entry md5="2abd19de6a38ff2890af64f453df96b1" mtime="2222222222" name="nochange" size="22" />
<entry md5="d8e8fca2dc0f896fd7cb4cb0031ba249" mtime="1283505591" name="test" size="5" />
</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="d8e8fca2dc0f896fd7cb4cb0031ba249" mtime="1283505591" name="test" size="5" />
</directory>

View File

@ -0,0 +1 @@
<directory><entry md5="b423d194c75e59ee4d8d2e07ba24323d" name="add" /><entry md5="ea467af882b32a275fe62eb05aba6ee1" name="add2" /><entry md5="2abd19de6a38ff2890af64f453df96b1" name="nochange" /><entry md5="d8e8fca2dc0f896fd7cb4cb0031ba249" name="test" /></directory>

View File

@ -0,0 +1,5 @@
<directory error="missing" name="add">
<entry md5="2abd19de6a38ff2890af64f453df96b1" name="nochange" />
<entry md5="b423d194c75e59ee4d8d2e07ba24323d" name="add" />
<entry md5="ea467af882b32a275fe62eb05aba6ee1" name="add2" />
</directory>

View File

@ -1,5 +1,6 @@
<directory name="simple" rev="1" srcmd5="2df1eacfe03a3bec2112529e7f4dc39a" vrev="1">
<directory name="simple" rev="2" srcmd5="2df1eacfe03a3bec2112529e7f4dc39a" vrev="2">
<entry md5="b423d194c75e59ee4d8d2e07ba24323d" mtime="1111111111" name="add" size="11" />
<entry md5="17b9e9e1a032ed44e7a584dc6303ffa8" mtime="1282047303" name="merge" size="48" />
<entry md5="2abd19de6a38ff2890af64f453df96b1" mtime="2222222222" name="nochange" size="22" />
<entry md5="d8e8fca2dc0f896fd7cb4cb0031ba249" mtime="1283505591" name="test" size="5" />
</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="d8e8fca2dc0f896fd7cb4cb0031ba249" mtime="1283505591" name="test" size="5" />
</directory>

View File

@ -0,0 +1 @@
<directory><entry md5="b423d194c75e59ee4d8d2e07ba24323d" name="add" /><entry md5="17b9e9e1a032ed44e7a584dc6303ffa8" name="merge" /><entry md5="2abd19de6a38ff2890af64f453df96b1" name="nochange" /><entry md5="d8e8fca2dc0f896fd7cb4cb0031ba249" name="test" /></directory>

View File

@ -0,0 +1,4 @@
<directory error="missing" name="partial">
<entry md5="b423d194c75e59ee4d8d2e07ba24323d" name="add" />
<entry md5="2abd19de6a38ff2890af64f453df96b1" name="nochange" />
</directory>

View File

@ -0,0 +1 @@
<directory><entry md5="0d62ceea6020d75154078a20d8c9f9ba" name="foo" /><entry md5="17b9e9e1a032ed44e7a584dc6303ffa8" name="merge" /><entry md5="382588b92f5976de693f44c4d6df27b7" name="nochange" /></directory>

View File

@ -0,0 +1,3 @@
<directory error="missing" name="simple">
<entry md5="c4eaea5dcaff13418e38e7fea151dd49" name="nochange" />
</directory>

View File

@ -55,9 +55,11 @@ class MyHTTPHandler(urllib2.HTTPHandler):
raise RuntimeError('either specify exp or expfile')
elif kwargs.has_key('expfile'):
exp = open(os.path.join(self.__fixtures_dir, kwargs['expfile']), 'r').read()
elif exp is None:
raise RuntimeError('exp or expfile required')
if exp is not None:
if req.get_data() != exp:
raise RequestDataMismatch(req.get_full_url(), req.get_data(), exp)
raise RequestDataMismatch(req.get_full_url(), repr(req.get_data()), repr(exp))
return self.__get_response(req.get_full_url(), **kwargs)
def __get_response(self, url, **kwargs):

View File

@ -10,18 +10,19 @@ def suite():
import unittest
return unittest.makeSuite(TestCommit)
rev_dummy = '<revision rev="upload">\n <srcmd5>ffffffffffffffffffffffffffffffff</srcmd5>\n</revision>'
rev_dummy = '<revision rev="repository">\n <srcmd5>empty</srcmd5>\n</revision>'
class TestCommit(OscTestCase):
def _get_fixtures_dir(self):
return FIXTURES_DIR
@GET('http://localhost/source/osctest/simple?rev=latest', file='testSimple_filesremote')
@PUT('http://localhost/source/osctest/simple/nochange?rev=upload',
@POST('http://localhost/source/osctest/simple?comment=&cmd=commitfilelist&user=Admin',
file='testSimple_missingfilelist', expfile='testSimple_lfilelist')
@PUT('http://localhost/source/osctest/simple/nochange?rev=repository',
exp='This file didn\'t change but\nis modified.\n', text=rev_dummy)
@POST('http://localhost/source/osctest/simple?comment=&cmd=commit&rev=upload&user=Admin', text='<revision rev="2" />',
exp='')
@GET('http://localhost/source/osctest/simple?rev=2', file='testSimple_cfilesremote')
@POST('http://localhost/source/osctest/simple?comment=&cmd=commitfilelist&user=Admin',
file='testSimple_cfilesremote', expfile='testSimple_lfilelist')
def test_simple(self):
"""a simple commit (only one modified file)"""
self._change_to_pkg('simple')
@ -33,13 +34,16 @@ class TestCommit(OscTestCase):
self.assertTrue(os.path.exists('nochange'))
self.assertEqual(open('nochange', 'r').read(), open(os.path.join('.osc', 'nochange'), 'r').read())
self._check_status(p, 'nochange', ' ')
self._check_status(p, 'foo', ' ')
self._check_status(p, 'merge', ' ')
@GET('http://localhost/source/osctest/add?rev=latest', file='testAddfile_filesremote')
@PUT('http://localhost/source/osctest/add/add?rev=upload',
@POST('http://localhost/source/osctest/add?comment=&cmd=commitfilelist&user=Admin',
file='testAddfile_missingfilelist', expfile='testAddfile_lfilelist')
@PUT('http://localhost/source/osctest/add/add?rev=repository',
exp='added file\n', text=rev_dummy)
@POST('http://localhost/source/osctest/add?comment=&cmd=commit&rev=upload&user=Admin', text='<revision rev="2" />',
exp='')
@GET('http://localhost/source/osctest/add?rev=2', file='testAddfile_cfilesremote')
@POST('http://localhost/source/osctest/add?comment=&cmd=commitfilelist&user=Admin',
file='testAddfile_cfilesremote', expfile='testAddfile_lfilelist')
def test_addfile(self):
"""commit a new file"""
self._change_to_pkg('add')
@ -52,22 +56,26 @@ class TestCommit(OscTestCase):
self.assertEqual(open('add', 'r').read(), open(os.path.join('.osc', 'add'), 'r').read())
self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_added')))
self._check_status(p, 'add', ' ')
self._check_status(p, 'foo', ' ')
self._check_status(p, 'merge', ' ')
self._check_status(p, 'nochange', ' ')
@GET('http://localhost/source/osctest/delete?rev=latest', file='testDeletefile_filesremote')
@DELETE('http://localhost/source/osctest/delete/nochange?rev=upload', text='<status code="ok" />')
@POST('http://localhost/source/osctest/delete?comment=&cmd=commit&rev=upload&user=Admin', text='<revision rev="2" />',
exp='')
@GET('http://localhost/source/osctest/delete?rev=2', file='testDeletefile_cfilesremote')
@POST('http://localhost/source/osctest/delete?comment=&cmd=commitfilelist&user=Admin',
file='testDeletefile_cfilesremote', expfile='testDeletefile_lfilelist')
def test_deletefile(self):
"""delete a file"""
self._change_to_pkg('delete')
osc.core.Package('.').commit()
p = osc.core.Package('.')
p.commit()
exp = 'Deleting nochange\nTransmitting file data \nCommitted revision 2.\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_digests('testDeletefile_cfilesremote')
self.assertFalse(os.path.exists('nochange'))
self.assertFalse(os.path.exists(os.path.join('.osc', 'nochange')))
self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_deleted')))
self._check_status(p, 'foo', ' ')
self._check_status(p, 'merge', ' ')
@GET('http://localhost/source/osctest/conflict?rev=latest', file='testConflictfile_filesremote')
def test_conflictfile(self):
@ -84,27 +92,30 @@ class TestCommit(OscTestCase):
def test_nochanges(self):
"""package has no changes (which can be committed)"""
self._change_to_pkg('nochanges')
ret = osc.core.Package('.').commit()
p = osc.core.Package('.')
ret = p.commit()
self.assertTrue(ret == 1)
exp = 'nothing to do for package nochanges\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_status(p, 'foo', 'S')
self._check_status(p, 'merge', '!')
self._check_status(p, 'nochange', ' ')
@GET('http://localhost/source/osctest/multiple?rev=latest', file='testMultiple_filesremote')
@DELETE('http://localhost/source/osctest/multiple/foo?rev=upload', text='<status code="ok" />')
@DELETE('http://localhost/source/osctest/multiple/merge?rev=upload', text='<status code="ok" />')
@PUT('http://localhost/source/osctest/multiple/add?rev=upload', exp='added file\n', text=rev_dummy)
@PUT('http://localhost/source/osctest/multiple/add2?rev=upload', exp='add2\n', text=rev_dummy)
@PUT('http://localhost/source/osctest/multiple/nochange?rev=upload', exp='This file did change.\n', text=rev_dummy)
@POST('http://localhost/source/osctest/multiple?comment=&cmd=commit&rev=upload&user=Admin', text='<revision rev="2" />',
exp='')
@GET('http://localhost/source/osctest/multiple?rev=2', file='testMultiple_cfilesremote')
@POST('http://localhost/source/osctest/multiple?comment=&cmd=commitfilelist&user=Admin',
file='testMultiple_missingfilelist', expfile='testMultiple_lfilelist')
@PUT('http://localhost/source/osctest/multiple/nochange?rev=repository', exp='This file did change.\n', text=rev_dummy)
@PUT('http://localhost/source/osctest/multiple/add?rev=repository', exp='added file\n', text=rev_dummy)
@PUT('http://localhost/source/osctest/multiple/add2?rev=repository', exp='add2\n', text=rev_dummy)
@POST('http://localhost/source/osctest/multiple?comment=&cmd=commitfilelist&user=Admin',
file='testMultiple_cfilesremote', expfile='testMultiple_lfilelist')
def test_multiple(self):
"""a simple commit (only one modified file)"""
self._change_to_pkg('multiple')
p = osc.core.Package('.')
p.commit()
exp = 'Sending add\nSending add2\nDeleting foo\nDeleting ' \
'merge\nSending nochange\nTransmitting file data ...\nCommitted revision 2.\n'
exp = 'Deleting foo\nDeleting merge\nSending nochange\n' \
'Sending add\nSending add2\nTransmitting file data ...\nCommitted revision 2.\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_digests('testMultiple_cfilesremote')
self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_added')))
@ -118,21 +129,21 @@ class TestCommit(OscTestCase):
self._check_status(p, 'nochange', ' ')
@GET('http://localhost/source/osctest/multiple?rev=latest', file='testPartial_filesremote')
@DELETE('http://localhost/source/osctest/multiple/foo?rev=upload', text='<status code="ok" />')
@PUT('http://localhost/source/osctest/multiple/add?rev=upload', exp='added file\n', text=rev_dummy)
@PUT('http://localhost/source/osctest/multiple/nochange?rev=upload', exp='This file did change.\n', text=rev_dummy)
@POST('http://localhost/source/osctest/multiple?comment=&cmd=commit&rev=upload&user=Admin', text='<revision rev="2" />',
exp='')
@GET('http://localhost/source/osctest/multiple?rev=2', file='testPartial_cfilesremote')
@POST('http://localhost/source/osctest/multiple?comment=&cmd=commitfilelist&user=Admin',
file='testPartial_missingfilelist', expfile='testPartial_lfilelist')
@PUT('http://localhost/source/osctest/multiple/add?rev=repository', exp='added file\n', text=rev_dummy)
@PUT('http://localhost/source/osctest/multiple/nochange?rev=repository', exp='This file did change.\n', text=rev_dummy)
@POST('http://localhost/source/osctest/multiple?comment=&cmd=commitfilelist&user=Admin',
file='testPartial_cfilesremote', expfile='testPartial_lfilelist')
def test_partial(self):
"""commit only some files"""
self._change_to_pkg('multiple')
p = osc.core.Package('.')
p.todo = ['foo', 'add', 'nochange']
p.commit()
exp = 'Sending add\nDeleting foo\n' \
'Sending nochange\nTransmitting file data ...\nCommitted revision 2.\n'
self.assertTrue(sys.stdout.getvalue(), exp)
exp = 'Deleting foo\nSending nochange\n' \
'Sending add\nTransmitting file data ..\nCommitted revision 2.\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_digests('testPartial_cfilesremote')
self._check_addlist('add2\n')
self._check_deletelist('merge\n')
@ -143,21 +154,85 @@ class TestCommit(OscTestCase):
self.assertRaises(osc.oscerr.OscIOError, p.status, 'foo')
@GET('http://localhost/source/osctest/simple?rev=latest', file='testSimple_filesremote')
@PUT('http://localhost/source/osctest/simple/nochange?rev=upload', exp='This file didn\'t change but\nis modified.\n',
@POST('http://localhost/source/osctest/simple?comment=&cmd=commitfilelist&user=Admin',
file='testSimple_missingfilelist', expfile='testSimple_lfilelist')
@PUT('http://localhost/source/osctest/simple/nochange?rev=repository', exp='This file didn\'t change but\nis modified.\n',
exception=IOError('test exception'), text=rev_dummy)
@POST('http://localhost/source/osctest/simple?comment=&cmd=deleteuploadrev&rev=upload&user=Admin', text='<revision rev="2" />',
exp='')
def test_interrupt(self):
"""interrupt a commit"""
self._change_to_pkg('simple')
p = osc.core.Package('.')
self.assertRaises(IOError, p.commit)
exp = 'Sending nochange\nTransmitting file data .'
self.assertEqual(sys.stdout.getvalue(), exp)
self.assertTrue(sys.stdout.getvalue(), exp)
self._check_digests('testSimple_filesremote')
self.assertTrue(os.path.exists('nochange'))
self._check_status(p, 'nochange', 'M')
@GET('http://localhost/source/osctest/allstates?rev=latest', file='testPartial_filesremote')
@POST('http://localhost/source/osctest/allstates?comment=&cmd=commitfilelist&user=Admin',
file='testAllStates_missingfilelist', expfile='testAllStates_lfilelist')
@PUT('http://localhost/source/osctest/allstates/add?rev=repository', exp='added file\n', text=rev_dummy)
@PUT('http://localhost/source/osctest/allstates/missing?rev=repository', exp='replaced\n', text=rev_dummy)
@PUT('http://localhost/source/osctest/allstates/nochange?rev=repository', exp='This file did change.\n', text=rev_dummy)
@POST('http://localhost/source/osctest/allstates?comment=&cmd=commitfilelist&user=Admin',
file='testAllStates_cfilesremote', expfile='testAllStates_lfilelist')
def test_allstates(self):
"""commit all files (all states are available except 'C')"""
self._change_to_pkg('allstates')
p = osc.core.Package('.')
p.commit()
exp = 'Deleting foo\nSending missing\nSending nochange\n' \
'Sending add\nTransmitting file data ...\nCommitted revision 2.\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_digests('testAllStates_expfiles', 'skipped')
self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_added')))
self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_deleted')))
self.assertFalse(os.path.exists('foo'))
self.assertFalse(os.path.exists(os.path.join('.osc', 'foo')))
self._check_status(p, 'add', ' ')
self._check_status(p, 'nochange', ' ')
self._check_status(p, 'merge', '!')
self._check_status(p, 'missing', ' ')
self._check_status(p, 'skipped', 'S')
self._check_status(p, 'test', ' ')
@GET('http://localhost/source/osctest/add?rev=latest', file='testAddfile_filesremote')
@POST('http://localhost/source/osctest/add?comment=&cmd=commitfilelist&user=Admin',
file='testAddfile_cfilesremote', expfile='testAddfile_lfilelist')
def test_remoteexists(self):
"""file 'add' should be committed but already exists on the server"""
self._change_to_pkg('add')
p = osc.core.Package('.')
p.commit()
exp = 'Sending add\nTransmitting file data \nCommitted revision 2.\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_digests('testAddfile_cfilesremote')
self.assertTrue(os.path.exists('add'))
self.assertEqual(open('add', 'r').read(), open(os.path.join('.osc', 'add'), 'r').read())
self.assertFalse(os.path.exists(os.path.join('.osc', '_to_be_added')))
self._check_status(p, 'add', ' ')
self._check_status(p, 'foo', ' ')
self._check_status(p, 'merge', ' ')
self._check_status(p, 'nochange', ' ')
@GET('http://localhost/source/osctest/branch?rev=latest', file='testExpand_filesremote')
@POST('http://localhost/source/osctest/branch?comment=&cmd=commitfilelist&user=Admin&keeplink=1',
file='testExpand_missingfilelist', expfile='testExpand_lfilelist')
@PUT('http://localhost/source/osctest/branch/simple?rev=repository', exp='simple modified file.\n', text=rev_dummy)
@POST('http://localhost/source/osctest/branch?comment=&cmd=commitfilelist&user=Admin&keeplink=1',
file='testExpand_cfilesremote', expfile='testExpand_lfilelist')
@GET('http://localhost/source/osctest/branch?rev=87ea02aede261b0267aabaa97c756e7a', file='testExpand_expandedfilesremote')
def test_expand(self):
"""commit an expanded package"""
self._change_to_pkg('branch')
p = osc.core.Package('.')
p.commit()
exp = 'Sending simple\nTransmitting file data .\nCommitted revision 7.\n'
self.assertEqual(sys.stdout.getvalue(), exp)
self._check_digests('testExpand_expandedfilesremote')
self._check_status(p, 'simple', ' ')
if __name__ == '__main__':
import unittest
unittest.main()