File indexing completed on 2024-04-28 16:01:31
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 #ifndef LIBQGIT2_DATABASE_H 0022 #define LIBQGIT2_DATABASE_H 0023 0024 #include "libqgit2_export.h" 0025 0026 #include "qgitdatabasebackend.h" 0027 #include "qgitoid.h" 0028 0029 #include <QtCore/QString> 0030 0031 namespace LibQGit2 0032 { 0033 /** 0034 * @brief Wrapper class for git_odb. 0035 * Represents a Git object database containing unique sha1 object ids. 0036 * 0037 * @ingroup LibQGit2 0038 * @{ 0039 */ 0040 class LIBQGIT2_EXPORT Database 0041 { 0042 public: 0043 /** 0044 * Create a new object database with no backends. 0045 * 0046 * Before the ODB can be used for read/writing, a custom database 0047 * backend must be manually added using `addBackend()` 0048 * 0049 */ 0050 explicit Database( git_odb *odb = 0); 0051 0052 Database( const Database& other ); 0053 0054 ~Database(); 0055 0056 public: 0057 /** 0058 * Create a new object database and automatically add 0059 * the two default backends: 0060 * 0061 * - backendLoose: read and write loose object files 0062 * from disk, assuming `objects_dir` as the Objects folder 0063 * 0064 * - backendPack: read objects from packfiles, 0065 * assuming `objectsDir` as the Objects folder which 0066 * contains a 'pack/' folder with the corresponding data 0067 * 0068 * @param objectsDir path of the backends' "objects" directory. 0069 * @return GIT_SUCCESS if the database opened; otherwise an error 0070 * code describing why the open was not possible. 0071 */ 0072 int open(const QString& objectsDir); 0073 0074 /** 0075 * Close an open object database. 0076 */ 0077 void close(); 0078 0079 /** 0080 * Add a custom backend to an existing Object DB 0081 * 0082 * Read <odb_backends.h> for more information. 0083 * 0084 * @param backend pointer to a databaseBackend instance 0085 * @return 0 on sucess; error code otherwise 0086 */ 0087 int addBackend(DatabaseBackend *backend, int priority); 0088 0089 /** 0090 * Add a custom backend to an existing Object DB; this 0091 * backend will work as an alternate. 0092 * 0093 * Alternate backends are always checked for objects *after* 0094 * all the main backends have been exhausted. 0095 * 0096 * Writing is disabled on alternate backends. 0097 * 0098 * Read <odb_backends.h> for more information. 0099 * 0100 * @param backend pointer to a databaseBackend instance 0101 * @return 0 on sucess; error code otherwise 0102 */ 0103 int addAlternate(DatabaseBackend *backend, int priority); 0104 0105 /** 0106 * Determine if the given object can be found in the object database. 0107 * 0108 * @param db database to be searched for the given object. 0109 * @param id the object to search for. 0110 * @return 0111 * - true, if the object was found 0112 * - false, otherwise 0113 */ 0114 int exists(Database *db, const OId& id); 0115 0116 git_odb* data() const; 0117 const git_odb* constData() const; 0118 0119 private: 0120 git_odb *m_database; 0121 }; 0122 0123 /**@}*/ 0124 } 0125 0126 #endif // LIBQGIT2_DATABASE_H