Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=f824752fed7bd4a097dffe93fc80fc36aab3f6bc

commit f824752fed7bd4a097dffe93fc80fc36aab3f6bc
Author: Michel Hermier <[email protected]>
Date:   Tue May 6 19:37:15 2014 +0200

libpacman: Merge _pacman_trans_init in __pmtrans_t constructor.

diff --git a/lib/libpacman/pacman.cpp b/lib/libpacman/pacman.cpp
index f49a32b..86c2771 100644
--- a/lib/libpacman/pacman.cpp
+++ b/lib/libpacman/pacman.cpp
@@ -1115,19 +1115,18 @@ int pacman_trans_init(unsigned char type, unsigned int 
flags, pacman_trans_cb_ev
return -1;
}

-       handle->trans = new __pmtrans_t();
-       if(handle->trans == NULL) {
-               RET_ERR(PM_ERR_MEMORY, -1);
-       }
-
pmtrans_cbs_t cbs = {
.event = event,
.conv = conv,
.progress = progress
};

-       _pacman_packages_transaction_init(handle->trans);
-       return(_pacman_trans_init(handle->trans, type, flags, cbs));
+       handle->trans = new __pmtrans_t((pmtranstype_t)type, flags, cbs);
+       if(handle->trans == NULL) {
+               RET_ERR(PM_ERR_MEMORY, -1);
+       }
+
+       return _pacman_packages_transaction_init(handle->trans);
}

/** Search for packages to upgrade and add them to the transaction.
diff --git a/lib/libpacman/sync.cpp b/lib/libpacman/sync.cpp
index 45df037..9266533 100644
--- a/lib/libpacman/sync.cpp
+++ b/lib/libpacman/sync.cpp
@@ -628,18 +628,12 @@ int _pacman_sync_commit(pmtrans_t *trans, pmlist_t **data)
_pacman_runhook("pre_sysupgrade", trans);
}
/* remove conflicting and to-be-replaced packages */
-       tr = new __pmtrans_t();
+       tr = new __pmtrans_t(PM_TRANS_TYPE_REMOVE, PM_TRANS_FLAG_NODEPS, 
trans->cbs);
if(tr == NULL) {
_pacman_log(PM_LOG_ERROR, _("could not create removal transaction"));
pm_errno = PM_ERR_MEMORY;
goto error;
}
-
-       if(_pacman_trans_init(tr, PM_TRANS_TYPE_REMOVE, PM_TRANS_FLAG_NODEPS, 
trans->cbs) == -1) {
-               _pacman_log(PM_LOG_ERROR, _("could not initialize the removal 
transaction"));
-               goto error;
-       }
-
for(i = trans->syncpkgs; i; i = i->next) {
pmsyncpkg_t *ps = i->data;
if(ps->type == PM_SYNC_TYPE_REPLACE) {
@@ -671,16 +665,12 @@ int _pacman_sync_commit(pmtrans_t *trans, pmlist_t **data)

/* install targets */
_pacman_log(PM_LOG_FLOW1, _("installing packages"));
-       tr = new __pmtrans_t();
+       tr = new __pmtrans_t(PM_TRANS_TYPE_UPGRADE, trans->flags | 
PM_TRANS_FLAG_NODEPS, trans->cbs);
if(tr == NULL) {
_pacman_log(PM_LOG_ERROR, _("could not create transaction"));
pm_errno = PM_ERR_MEMORY;
goto error;
}
-       if(_pacman_trans_init(tr, PM_TRANS_TYPE_UPGRADE, trans->flags | 
PM_TRANS_FLAG_NODEPS, trans->cbs) == -1) {
-               _pacman_log(PM_LOG_ERROR, _("could not initialize 
transaction"));
-               goto error;
-       }
for(i = trans->syncpkgs; i; i = i->next) {
pmsyncpkg_t *ps = i->data;
Package *spkg = ps->pkg;
diff --git a/lib/libpacman/trans.cpp b/lib/libpacman/trans.cpp
index d7fcd47..c266b02 100644
--- a/lib/libpacman/trans.cpp
+++ b/lib/libpacman/trans.cpp
@@ -77,47 +77,37 @@ static int check_oldcache(void)
return(0);
}

-__pmtrans_t::__pmtrans_t()
+__pmtrans_t::__pmtrans_t(pmtranstype_t type, unsigned int flags, pmtrans_cbs_t 
cbs)
: state(STATE_IDLE)
{
-}
-
-int _pacman_trans_init(pmtrans_t *trans, pmtranstype_t type, unsigned int 
flags, pmtrans_cbs_t cbs)
-{
-       /* Sanity checks */
-       ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
-
switch(type) {
case PM_TRANS_TYPE_ADD:
case PM_TRANS_TYPE_UPGRADE:
case PM_TRANS_TYPE_REMOVE:
-                       trans->ops = NULL;
+                       ops = NULL;
break;
case PM_TRANS_TYPE_SYNC:
-                       trans->ops = &_pacman_sync_pmtrans_opts;
+                       ops = &_pacman_sync_pmtrans_opts;
break;
default:
-                       trans->ops = NULL;
+                       ops = NULL;
// Be more verbose about the trans type
_pacman_log(PM_LOG_ERROR,
_("could not initialize transaction: Unknown Transaction Type %d"), type);
-                       return(-1);
}

-       trans->handle = handle;
-       trans->type = type;
-       trans->flags = flags;
-       trans->cbs = cbs;
-//     trans->packages = f_ptrlist_new();
-       trans->targets = f_stringlist_new();
-       trans->skiplist = f_stringlist_new();
-       trans->triggers = f_stringlist_new();
+       this->handle = ::handle;
+       this->type = type;
+       this->flags = flags;
+       this->cbs = cbs;
+//     packages = f_ptrlist_new();
+       targets = f_stringlist_new();
+       skiplist = f_stringlist_new();
+       triggers = f_stringlist_new();

-       trans->state = STATE_INITIALIZED;
+       state = STATE_INITIALIZED;

check_oldcache();
-
-       return(0);
}

__pmtrans_t::~__pmtrans_t()
@@ -1095,16 +1085,13 @@ int _pacman_add_commit(pmtrans_t *trans, pmlist_t 
**data)

if(oldpkg) {
pmtrans_t *tr;
+                                       pmtrans_cbs_t null_cbs = { NULL };
+
_pacman_log(PM_LOG_FLOW1, _("removing old package first (%s-%s)"), 
oldpkg->name(), oldpkg->version());
-                                       tr = new __pmtrans_t();
+                                       tr = new 
__pmtrans_t(PM_TRANS_TYPE_UPGRADE, trans->flags, null_cbs);
if(tr == NULL) {
RET_ERR(PM_ERR_TRANS_ABORT, -1);
}
-                                       pmtrans_cbs_t null_cbs = { NULL };
-                                       if(_pacman_trans_init(tr, 
PM_TRANS_TYPE_UPGRADE, trans->flags, null_cbs) == -1) {
-                                               FREETRANS(tr);
-                                               RET_ERR(PM_ERR_TRANS_ABORT, -1);
-                                       }
if(_pacman_remove_addtarget(tr, pkg_new->name()) == -1) {
FREETRANS(tr);
RET_ERR(PM_ERR_TRANS_ABORT, -1);
diff --git a/lib/libpacman/trans.h b/lib/libpacman/trans.h
index 560c597..6e9bbe7 100644
--- a/lib/libpacman/trans.h
+++ b/lib/libpacman/trans.h
@@ -62,7 +62,7 @@ typedef struct __pmtrans_cbs_t {
struct __pmtrans_t
: public libpacman::Object
{
-       __pmtrans_t();
+       __pmtrans_t(pmtranstype_t type, unsigned int flags, pmtrans_cbs_t cbs);
~__pmtrans_t();

const pmtrans_ops_t *ops;
@@ -101,8 +101,6 @@ do { \
} \
} while(0)

-int _pacman_trans_init(pmtrans_t *trans, pmtranstype_t type, unsigned int 
flags, pmtrans_cbs_t cbs);
-
int _pacman_trans_event(pmtrans_t *trans, unsigned char, void *, void *);
pmsyncpkg_t *_pacman_trans_find(const pmtrans_t *trans, const char *pkgname);
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to