Skip to content

Commit

Permalink
First integration of libgit2
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias Koefferlein committed Oct 24, 2023
1 parent 01c1904 commit 40bdd63
Show file tree
Hide file tree
Showing 17 changed files with 624 additions and 50 deletions.
9 changes: 9 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ HAVE_QT=1
HAVE_PNG=0
HAVE_CURL=0
HAVE_EXPAT=0
HAVE_GIT2=1

RUBYINCLUDE=""
RUBYINCLUDE2=""
Expand Down Expand Up @@ -209,6 +210,9 @@ while [ "$*" != "" ]; do
-libexpat)
HAVE_EXPAT=1
;;
-nolibgit2)
HAVE_GIT2=0
;;
-qt5)
echo "*** WARNING: -qt5 option is ignored - Qt version is auto-detected now."
;;
Expand Down Expand Up @@ -495,6 +499,9 @@ fi
if [ $HAVE_PNG != 0 ]; then
echo " Uses libpng for PNG generation"
fi
if [ $HAVE_GIT2 != 0 ]; then
echo " Uses libgit2 for Git access"
fi
if [ "$RPATH" = "" ]; then
RPATH="$BIN"
fi
Expand Down Expand Up @@ -578,6 +585,7 @@ echo " HAVE_64BIT_COORD=$HAVE_64BIT_COORD"
echo " HAVE_CURL=$HAVE_CURL"
echo " HAVE_PNG=$HAVE_PNG"
echo " HAVE_EXPAT=$HAVE_EXPAT"
echo " HAVE_GIT2=$HAVE_GIT2"
echo " RPATH=$RPATH"

mkdir -p $BUILD
Expand Down Expand Up @@ -650,6 +658,7 @@ qmake_options=(
HAVE_CURL="$HAVE_CURL"
HAVE_EXPAT="$HAVE_EXPAT"
HAVE_PNG="$HAVE_PNG"
HAVE_GIT2="$HAVE_GIT2"
PREFIX="$BIN"
RPATH="$RPATH"
KLAYOUT_VERSION="$KLAYOUT_VERSION"
Expand Down
9 changes: 9 additions & 0 deletions src/klayout.pri
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ equals(HAVE_PTHREADS, "1") {
DEFINES += HAVE_PTHREADS
}

equals(HAVE_GIT2, "1") {
!isEmpty(BITS_PATH) {
include($$BITS_PATH/git2/git2.pri)
} else {
LIBS += -lgit2
}
DEFINES += HAVE_GIT2
}

equals(HAVE_RUBY, "1") {
!isEmpty(BITS_PATH) {
include($$BITS_PATH/ruby/ruby.pri)
Expand Down
2 changes: 1 addition & 1 deletion src/lay/lay/layApplication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ ApplicationBase::init_app ()
size_t local_folders = (lay::get_appdata_path ().empty () ? 0 : 1);

for (std::vector <std::string>::const_iterator p = m_klayout_path.begin (); p != m_klayout_path.end (); ++p) {
if (p - m_klayout_path.begin () < local_folders) {
if (size_t (p - m_klayout_path.begin ()) < local_folders) {
mc->add_path (*p, tl::to_string (QObject::tr ("Local")), std::string (), false);
} else if (m_klayout_path.size () == 1 + local_folders) {
mc->add_path (*p, tl::to_string (QObject::tr ("Global")), std::string (), true);
Expand Down
2 changes: 1 addition & 1 deletion src/lay/lay/layInit.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void init (const std::vector<std::string> &_paths)
try {
s_plugins.push_back (do_load_plugin (imp));
modules.insert (*im);
} catch (tl::Exception (&ex)) {
} catch (tl::Exception &ex) {
tl::error << ex.msg ();
}
}
Expand Down
25 changes: 22 additions & 3 deletions src/lay/lay/laySalt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@
*/

#include "laySalt.h"

#include "tlString.h"
#include "tlFileUtils.h"
#include "tlLog.h"
#include "tlInternational.h"
#include "tlWebDAV.h"
#if defined(HAVE_GIT2)
# include "tlGit.h"
#endif

#include "lymMacro.h"

#include <QFileInfo>
Expand Down Expand Up @@ -485,9 +490,23 @@ Salt::create_grain (const SaltGrain &templ, SaltGrain &target, double timeout, t

if (templ.url ().find ("http:") == 0 || templ.url ().find ("https:") == 0) {

// otherwise download from the URL
tl::info << QObject::tr ("Downloading package from '%1' to '%2' ..").arg (tl::to_qstring (templ.url ())).arg (tl::to_qstring (target.path ()));
res = tl::WebDAVObject::download (templ.url (), target.path (), timeout, callback);
// otherwise download from the URL using Git or SVN

if (templ.protocol () == Git) {

#if defined(HAVE_GIT2)
tl::info << QObject::tr ("Downloading package from '%1' to '%2' using Git protocol ..").arg (tl::to_qstring (templ.url ())).arg (tl::to_qstring (target.path ()));
res = tl::GitObject::download (templ.url (), target.path (), templ.branch (), timeout, callback);
#else
throw tl::Exception (tl::to_string (QObject::tr ("Unable to install package '%1' - git protocol not compiled in").arg (tl::to_qstring (target.name ()))));
#endif

} else if (templ.protocol () == WebDAV || templ.protocol () == DefaultProtocol) {

tl::info << QObject::tr ("Downloading package from '%1' to '%2' using SVN/WebDAV protocol ..").arg (tl::to_qstring (templ.url ())).arg (tl::to_qstring (target.path ()));
res = tl::WebDAVObject::download (templ.url (), target.path (), timeout, callback);

}

} else {

Expand Down
33 changes: 31 additions & 2 deletions src/lay/lay/laySaltController.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,40 @@ SaltController::install_packages (const std::vector<std::string> &packages, bool
}

if (n.find ("http:") == 0 || n.find ("https:") == 0 || n.find ("file:") == 0 || n[0] == '/' || n[0] == '\\') {

// its a URL
manager.register_download (std::string (), std::string (), n, v);
manager.register_download (std::string (), std::string (), n, DefaultProtocol, std::string (), v);

} else if (n.find ("git@") == 0) {

// git protocol:
// "git@<url>"
// "git@<url>[<branch>]"

std::string url (n, 4);
size_t br = url.find ("[");
std::string branch;
if (br != std::string::npos && url.back () == ']') {
branch = std::string (url, br + 1, url.size () - br - 2);
url = std::string (url, 0, br);
}

manager.register_download (std::string (), std::string (), url, Git, branch, v);

} else if (n.find ("svn@") == 0) {

// svn protocol:
// "svn@<url>"

std::string url (n, 4);
// its a URL
manager.register_download (std::string (), std::string (), url, WebDAV, std::string (), v);

} else {

// its a plain name
manager.register_download (n, std::string (), std::string (), v);
manager.register_download (n, std::string (), std::string (), DefaultProtocol, std::string (), v);

}

}
Expand Down
29 changes: 20 additions & 9 deletions src/lay/lay/laySaltDownloadManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ ConfirmationDialog::ConfirmationDialog (QWidget *parent)
}

void
ConfirmationDialog::add_info (const std::string &name, bool update, const std::string &version, const std::string &url)
ConfirmationDialog::add_info (const std::string &name, bool update, const std::string &version, const std::string &url, Protocol protocol, const std::string &branch)
{
QTreeWidgetItem *item = new QTreeWidgetItem (list);
m_items_by_name.insert (std::make_pair (name, item));
Expand All @@ -68,7 +68,18 @@ ConfirmationDialog::add_info (const std::string &name, bool update, const std::s
item->setText (0, tl::to_qstring (name));
item->setText (1, update ? tr ("UPDATE") : tr ("INSTALL"));
item->setText (2, tl::to_qstring (version));
item->setText (3, tl::to_qstring (url));

if (protocol == WebDAV) {
item->setText (3, tl::to_qstring ("svn@" + url));
} else if (protocol == Git) {
if (branch.empty ()) {
item->setText (3, tl::to_qstring ("git@" + url));
} else {
item->setText (3, tl::to_qstring ("git@" + url + "[" + branch + "]"));
}
} else {
item->setText (3, tl::to_qstring (url));
}

for (int column = 0; column < list->colorCount (); ++column) {
item->setData (column, Qt::ForegroundRole, QVariant (QBrush (update ? QColor (Qt::blue) : QColor (Qt::black))));
Expand Down Expand Up @@ -169,9 +180,9 @@ SaltDownloadManager::SaltDownloadManager ()
}

void
SaltDownloadManager::register_download (const std::string &name, const std::string &token, const std::string &url, const std::string &version)
SaltDownloadManager::register_download (const std::string &name, const std::string &token, const std::string &url, Protocol protocol, const std::string &branch, const std::string &version)
{
m_registry.push_back (Descriptor (name, token, url, version));
m_registry.push_back (Descriptor (name, token, url, protocol, branch, version));
}

void
Expand Down Expand Up @@ -244,7 +255,7 @@ SaltDownloadManager::compute_list (const lay::Salt &salt, const lay::Salt &salt_
if (tl::verbosity() >= 20) {
tl::log << "Considering for update as dependency: " << d->name << " (" << d->version << ") with URL " << d->url;
}
m_registry.push_back (Descriptor (d->name, std::string (), d->url, d->version));
m_registry.push_back (Descriptor (d->name, std::string (), d->url, d->protocol, d->branch, d->version));

} else {
if (tl::verbosity() >= 20) {
Expand All @@ -257,7 +268,7 @@ SaltDownloadManager::compute_list (const lay::Salt &salt, const lay::Salt &salt_
if (tl::verbosity() >= 20) {
tl::log << "Considering for download as dependency: " << d->name << " (" << d->version << ") with URL " << d->url;
}
m_registry.push_back (Descriptor (d->name, std::string (), d->url, d->version));
m_registry.push_back (Descriptor (d->name, std::string (), d->url, d->protocol, d->branch, d->version));

}

Expand Down Expand Up @@ -330,7 +341,7 @@ SaltDownloadManager::fetch_missing (const lay::Salt &salt, const lay::Salt &salt
}

try {
p->grain = SaltGrain::from_url (p->url);
p->grain = SaltGrain::from_url (p->url, p->protocol, p->branch);
} catch (tl::Exception &ex) {
throw tl::Exception (tl::to_string (QObject::tr ("Error fetching spec file for package '%1': %2").arg (tl::to_qstring (p->name)).arg (tl::to_qstring (ex.msg ()))));
}
Expand Down Expand Up @@ -387,15 +398,15 @@ SaltDownloadManager::make_confirmation_dialog (QWidget *parent, const lay::Salt
const lay::SaltGrain *g = salt.grain_by_name (p->name);
if (g) {
// \342\206\222 is UTF-8 "right arrow"
dialog->add_info (p->name, true, g->version () + " \342\206\222 " + p->version, p->url);
dialog->add_info (p->name, true, g->version () + " \342\206\222 " + p->version, p->url, p->protocol, p->branch);
}
}

// Then the packages to install
for (std::vector<Descriptor>::const_iterator p = m_registry.begin (); p != m_registry.end (); ++p) {
const lay::SaltGrain *g = salt.grain_by_name (p->name);
if (!g) {
dialog->add_info (p->name, false, p->version, p->url);
dialog->add_info (p->name, false, p->version, p->url, p->protocol, p->branch);
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/lay/lay/laySaltDownloadManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Q_OBJECT
public:
ConfirmationDialog (QWidget *parent);

void add_info (const std::string &name, bool update, const std::string &version, const std::string &url);
void add_info (const std::string &name, bool update, const std::string &version, const std::string &url, Protocol protocol, const std::string &branch);

bool is_confirmed () const { return m_confirmed; }
bool is_cancelled () const { return m_cancelled; }
Expand Down Expand Up @@ -108,7 +108,7 @@ Q_OBJECT
*
* The target directory can be empty. In this case, the downloader will pick an appropriate one.
*/
void register_download (const std::string &name, const std::string &token, const std::string &url, const std::string &version);
void register_download (const std::string &name, const std::string &token, const std::string &url, Protocol protocol, const std::string &branch, const std::string &version);

/**
* @brief Computes the dependencies after all required packages have been registered
Expand Down Expand Up @@ -145,8 +145,8 @@ Q_OBJECT
private:
struct Descriptor
{
Descriptor (const std::string &_name, const std::string &_token, const std::string &_url, const std::string &_version)
: name (_name), token (_token), url (_url), version (_version), downloaded (false)
Descriptor (const std::string &_name, const std::string &_token, const std::string &_url, Protocol _protocol, const std::string &_branch, const std::string &_version)
: name (_name), token (_token), url (_url), protocol (_protocol), branch (_branch), version (_version), downloaded (false)
{ }

bool operator< (const Descriptor &other) const
Expand All @@ -170,6 +170,8 @@ Q_OBJECT
std::string name;
std::string token;
std::string url;
Protocol protocol;
std::string branch;
std::string version;
bool downloaded;
lay::SaltGrain grain;
Expand Down
Loading

0 comments on commit 40bdd63

Please sign in to comment.