diff --git a/createrepo-head.patch b/createrepo-head.patch
index a4479f1..a91f162 100644
--- a/createrepo-head.patch
+++ b/createrepo-head.patch
@@ -1,5 +1,5 @@
diff --git a/createrepo/__init__.py b/createrepo/__init__.py
-index 744bb67..970ccb2 100644
+index 744bb67..dcf08b1 100644
--- a/createrepo/__init__.py
+++ b/createrepo/__init__.py
@@ -25,7 +25,7 @@ from bz2 import BZ2File
@@ -133,19 +133,17 @@ index 744bb67..970ccb2 100644
# otherwise do it individually
if not recycled:
-@@ -462,6 +497,11 @@ class MetaDataGenerator:
+@@ -462,6 +497,9 @@ class MetaDataGenerator:
# need to say something here
self.callback.errorlog("\nError %s: %s\n" % (pkg, e))
continue
+ # we can use deltas:
-+ presto_md = self._do_delta_rpm_package(po)
-+ if presto_md:
-+ self.deltafile.write(presto_md)
++ self._do_delta_rpm_package(po)
+
else:
po = pkg
-@@ -492,6 +532,9 @@ class MetaDataGenerator:
+@@ -492,6 +530,9 @@ class MetaDataGenerator:
outfile.write('\n')
self.oldData.freeNodes(pkg)
@@ -155,13 +153,14 @@ index 744bb67..970ccb2 100644
if not self.conf.quiet:
if self.conf.verbose:
-@@ -532,6 +575,88 @@ class MetaDataGenerator:
+@@ -532,6 +573,94 @@ class MetaDataGenerator:
self.otherfile.write('\n')
self.otherfile.close()
+ if self.conf.deltas:
+ if not self.conf.quiet:
+ self.callback.log(_('Saving delta metadata'))
++ self.deltafile.write(self.generate_delta_xml())
+ self.deltafile.write('\n')
+ self.deltafile.close()
+
@@ -170,81 +169,86 @@ index 744bb67..970ccb2 100644
+ returns the presto/delta xml metadata as a string
+ """
+
-+ results = u""
-+ thisdeltastart = u""" \n""" % (pkg.name,
-+ pkg.epoch, pkg.ver, pkg.release, pkg.arch)
-+ thisdeltaend = u""" \n"""
-+
+ # generate a list of all the potential 'old rpms'
-+ opl = self._get_old_package_list()
-+ # get list of potential candidates which are likely to match
-+ pot_cand = []
-+ for fn in opl:
-+ if os.path.basename(fn).startswith(pkg.name):
-+ pot_cand.append(fn)
++ opd = self._get_old_package_dict() # yes I could make this a property but
+
-+ candidates = []
-+ for fn in pot_cand:
-+ try:
-+ thispo = yumbased.CreateRepoPackage(self.ts, fn)
-+ except Errors.MiscError, e:
-+ continue
-+ if (thispo.name, thispo.arch) != (pkg.name, pkg.arch):
-+ # not the same, doesn't matter
-+ continue
-+ if thispo == pkg: #exactly the same, doesn't matter
-+ continue
-+ if thispo.EVR >= pkg.EVR: # greater or equal, doesn't matter
-+ continue
-+ candidates.append(thispo)
-+ candidates.sort()
-+ candidates.reverse()
-+
-+ drpm_results = u""
-+ for delta_p in candidates[0:self.conf.num_deltas]:
-+ #make drpm of pkg and delta_p
-+ drpmfn = deltarpms.create_drpm(delta_p, pkg, self.conf.deltadir)
-+
-+ if drpmfn:
-+ # TODO more sanity check the drpm for size, etc
-+ # make xml of drpm
++ # for each of our old_package_paths - make a drpm from the newest of that pkg
++ # get list of potential candidates which are likely to match
++ for d in self.conf.oldpackage_paths:
++ pot_cand = []
++ for fn in opd[d]:
++ if os.path.basename(fn).startswith(pkg.name):
++ pot_cand.append(fn)
++
++ candidates = []
++ for fn in pot_cand:
+ try:
-+ drpm_po = yumbased.CreateRepoPackage(self.ts, drpmfn)
++ thispo = yumbased.CreateRepoPackage(self.ts, fn)
+ except Errors.MiscError, e:
-+ os.unlink(drpmfn)
+ continue
-+ rel_drpmfn = drpmfn.replace(self.conf.outputdir, '')
-+ if rel_drpmfn[0] == '/':
-+ rel_drpmfn = rel_drpmfn[1:]
-+ if not self.conf.quiet:
-+ if self.conf.verbose:
-+ self.callback.log('created drpm from %s to %s: %s' % (
-+ delta_p, pkg, drpmfn))
++ if (thispo.name, thispo.arch) != (pkg.name, pkg.arch):
++ # not the same, doesn't matter
++ continue
++ if thispo == pkg: #exactly the same, doesn't matter
++ continue
++ if thispo.EVR >= pkg.EVR: # greater or equal, doesn't matter
++ continue
++ candidates.append(thispo)
++ candidates.sort()
++ candidates.reverse()
+
-+ drpm = deltarpms.DeltaRPMPackage(drpm_po, self.conf.outputdir, rel_drpmfn)
-+ drpm_results += to_unicode(drpm.xml_dump_metadata())
-+
-+ if drpm_results:
-+ results = thisdeltastart + drpm_results + thisdeltaend
-+
-+ return results
++ for delta_p in candidates[0:self.conf.num_deltas]:
++ #make drpm of pkg and delta_p
++ drpmfn = deltarpms.create_drpm(delta_p, pkg, self.conf.deltadir)
++ self.callback.log('created drpm from %s to %s: %s' % (
++ delta_p, pkg, drpmfn))
+
-+ def _get_old_package_list(self):
-+ if hasattr(self, '_old_package_list'):
-+ return self._old_package_list
++ def _get_old_package_dict(self):
++ if hasattr(self, '_old_package_dict'):
++ return self._old_package_dict
+
++ self._old_package_dict = {}
+ opl = []
+ for d in self.conf.oldpackage_paths:
+ for f in self.getFileList(d, 'rpm'):
-+ opl.append(d + '/' + f)
++ if not self._old_package_dict.has_key(d):
++ self._old_package_dict[d] = []
++ self._old_package_dict[d].append(d + '/' + f)
+
-+ self._old_package_list = opl
-+ return self._old_package_list
++ return self._old_package_dict
++
++ def generate_delta_xml(self):
++ """take the delta rpm output dir, process all the drpm files
++ produce the text output for the presto/delta xml metadata"""
++ # go through the drpm dir
++ # for each file -store the drpm info in a dict based on its target. Just
++ # appending the output. for each of the keys in the dict, return
++ # the tag for the target + each of the drpm infos + closure for the target
++ # tag
++ targets = {}
++ result = u''
++ for drpm_fn in self.getFileList(self.conf.deltadir, 'drpm'):
++ drpm_rel_fn = os.path.normpath(self.conf.delta_relative + '/' + drpm_fn) # this is annoying
++ drpm_po = yumbased.CreateRepoPackage(self.ts, self.conf.deltadir + '/' + drpm_fn)
++
++ drpm = deltarpms.DeltaRPMPackage(drpm_po, self.conf.outputdir, drpm_rel_fn)
++ if not targets.has_key(drpm_po.pkgtup):
++ targets[drpm_po.pkgtup] = u''
++ targets[drpm_po.pkgtup] += drpm.xml_dump_metadata()
++
++ for (n,e,v,r,a) in targets.keys():
++ result += """ \n"""
++
++ return result
+
def addArbitraryMetadata(self, mdfile, mdtype, xml_node, compress=True,
compress_type='gzip', attribs={}):
"""add random metadata to the repodata dir and repomd.xml
-@@ -630,6 +755,8 @@ class MetaDataGenerator:
+@@ -630,6 +759,8 @@ class MetaDataGenerator:
db_workfiles = []
repoid='garbageid'
@@ -255,10 +259,10 @@ index 744bb67..970ccb2 100644
try:
diff --git a/createrepo/deltarpms.py b/createrepo/deltarpms.py
new file mode 100644
-index 0000000..4b4acaf
+index 0000000..f201ab7
--- /dev/null
+++ b/createrepo/deltarpms.py
-@@ -0,0 +1,140 @@
+@@ -0,0 +1,144 @@
+#!/usr/bin/python -tt
+# util functions for deltarpms
+# This program is free software; you can redistribute it and/or modify
@@ -280,6 +284,8 @@ index 0000000..4b4acaf
+import commands
+from yum import misc
+import gzip
++import yumbased
++from utils import _, errorprint, MDError
+
+class DeltaRPMPackage:
+ """each drpm is one object, you pass it a drpm file
@@ -288,17 +294,17 @@ index 0000000..4b4acaf
+
+ mode_cache = {}
+
-+ def __init__(self, pkgobj, basedir, filename):
++ def __init__(self, po, basedir, filename):
+ try:
+ stats = os.stat(os.path.join(basedir, filename))
+ self.size = stats[6]
+ self.mtime = stats[8]
+ del stats
+ except OSError, e:
-+ raise MDError, "Error Stat'ing file %s %s" % (basedir, filename)
++ raise MDError, "Error Stat'ing file %s%s" % (basedir, filename)
+ self.csum_type = 'sha256'
+ self.relativepath = filename
-+ self.po = pkgobj
++ self.po = po
+
+ fd = os.open(self.po.localpath, os.O_RDONLY)
+ os.lseek(fd, 0, 0)
@@ -371,8 +377,7 @@ index 0000000..4b4acaf
+ (oldname, oldepoch, oldver, oldrel) = self.oldnevr
+ sequence = "%s-%s" % (self.oldnevrstring, self.sequence)
+
-+ delta_tag = """
-+
++ delta_tag = """
+ %s
+ %s
+ %s
@@ -399,6 +404,9 @@ index 0000000..4b4acaf
+ return None
+
+ return delta_rpm_path
++
++
++
diff --git a/createrepo/merge.py b/createrepo/merge.py
index d096c61..d4b8359 100644
--- a/createrepo/merge.py
diff --git a/createrepo.spec b/createrepo.spec
index 6cc13fa..dca7af1 100644
--- a/createrepo.spec
+++ b/createrepo.spec
@@ -3,7 +3,7 @@
Summary: Creates a common metadata repository
Name: createrepo
Version: 0.9.6
-Release: 10%{?dist}
+Release: 11%{?dist}
License: GPLv2
Group: System Environment/Base
Source: %{name}-%{version}.tar.gz
@@ -46,6 +46,9 @@ rm -rf $RPM_BUILD_ROOT
%{python_sitelib}/createrepo
%changelog
+* Tue Feb 10 2009 Seth Vidal - 0.9.6-11
+- change the order of deltarpms
+
* Wed Feb 4 2009 Seth Vidal - 0.9.6-10
- working mergerepo again