File indexing completed on 2024-04-28 16:01:32
0001 /****************************************************************************** 0002 * This file is part of the libqgit2 library 0003 * Copyright (c) 2011 Laszlo Papp <djszapi@archlinux.us> 0004 * Copyright (C) 2013 Leonardo Giordani 0005 * 0006 * This library is free software; you can redistribute it and/or 0007 * modify it under the terms of the GNU Lesser General Public 0008 * License as published by the Free Software Foundation; either 0009 * version 2.1 of the License, or (at your option) any later version. 0010 * 0011 * This library is distributed in the hope that it will be useful, 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 * Lesser General Public License for more details. 0015 * 0016 * You should have received a copy of the GNU Lesser General Public 0017 * License along with this library; if not, write to the Free Software 0018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 0019 */ 0020 0021 #include "git2.h" 0022 0023 #include "qgitexception.h" 0024 #include <QtCore/QString> 0025 0026 namespace LibQGit2 0027 { 0028 0029 Exception::Exception() : 0030 m_category(None) 0031 { 0032 const git_error *err = giterr_last(); 0033 0034 if (err != NULL) { 0035 m_msg = err->message; 0036 0037 switch (err->klass) { 0038 case GITERR_NOMEMORY: m_category = NoMemory; break; 0039 case GITERR_OS: m_category = OS; break; 0040 case GITERR_INVALID: m_category = Invalid; break; 0041 case GITERR_REFERENCE: m_category = Reference; break; 0042 case GITERR_ZLIB: m_category = ZLib; break; 0043 case GITERR_REPOSITORY: m_category = Repository; break; 0044 case GITERR_CONFIG: m_category = Config; break; 0045 case GITERR_REGEX: m_category = RegEx; break; 0046 case GITERR_ODB: m_category = ODB; break; 0047 case GITERR_INDEX: m_category = Index; break; 0048 case GITERR_OBJECT: m_category = Object; break; 0049 case GITERR_NET: m_category = Net; break; 0050 case GITERR_TAG: m_category = Tag; break; 0051 case GITERR_TREE: m_category = Tree; break; 0052 case GITERR_INDEXER: m_category = Indexer; break; 0053 case GITERR_SSL: m_category = SSL; break; 0054 case GITERR_SUBMODULE: m_category = Submodule; break; 0055 case GITERR_THREAD: m_category = Thread; break; 0056 case GITERR_STASH: m_category = Stash; break; 0057 case GITERR_CHECKOUT: m_category = Checkout; break; 0058 case GITERR_FETCHHEAD: m_category = FetchHead; break; 0059 case GITERR_MERGE: m_category = Merge; break; 0060 case GITERR_SSH: m_category = SSH; break; 0061 case GITERR_FILTER: m_category = Filter; break; 0062 case GITERR_REVERT: m_category = Revert; break; 0063 case GITERR_CALLBACK: m_category = Callback; break; 0064 case GITERR_CHERRYPICK: m_category = Cherrypick; break; 0065 case GITERR_NONE: 0066 default: m_category = None; break; 0067 } 0068 0069 giterr_clear(); 0070 } 0071 } 0072 0073 Exception::Exception(const QString& msg, Category category) : 0074 m_msg(msg.toLatin1()), 0075 m_category(category) 0076 { 0077 } 0078 0079 Exception::~Exception() throw() 0080 { 0081 } 0082 0083 const char *Exception::what() const throw() 0084 { 0085 return m_msg; 0086 } 0087 0088 QByteArray Exception::message() const throw() 0089 { 0090 return m_msg; 0091 } 0092 0093 Exception::Category Exception::category() const throw() 0094 { 0095 return m_category; 0096 } 0097 0098 }