File indexing completed on 2025-01-19 05:11:32

0001 /*
0002 SPDX-FileCopyrightText: 2021 Hamed Masafi <hamed.masfi@gmail.com>
0003 
0004 SPDX-License-Identifier: GPL-3.0-or-later
0005 */
0006 
0007 #include <QList>
0008 #include <QString>
0009 #include <git2/tree.h>
0010 
0011 #include "types.h"
0012 
0013 namespace Git
0014 {
0015 
0016 namespace Deleters
0017 {
0018 
0019 void deleteGitTree(git_tree *tree)
0020 {
0021     git_tree_free(tree);
0022 }
0023 
0024 }
0025 
0026 QString convertToQString(git_buf *buf)
0027 {
0028     return QString(buf->ptr);
0029 }
0030 
0031 QStringList convert(git_strarray *arr)
0032 {
0033     QStringList list;
0034     for (size_t i = 0; i < arr->count; ++i) {
0035         list << QString{arr->strings[i]};
0036     }
0037     return list;
0038 }
0039 
0040 QString convertToString(const git_oid *id, const int len)
0041 {
0042     QString result = "";
0043     int lengthOfString = len;
0044 
0045     QString s;
0046     for (int i = 0; i < lengthOfString; i++) {
0047         s = QString("%1").arg(id->id[i], 0, 16);
0048 
0049         if (s.length() == 1)
0050             result.append("0");
0051 
0052         result.append(s);
0053     }
0054 
0055     return result;
0056 }
0057 
0058 void addToArray(git_strarray *arr, const QString &value)
0059 {
0060     arr->strings = new char *[1];
0061     arr->strings[0] = value.toLocal8Bit().data();
0062     arr->count = 0;
0063 }
0064 
0065 QSharedPointer<git_tree> makeShared(git_tree *tree)
0066 {
0067     return QSharedPointer<git_tree>(tree, Deleters::deleteGitTree);
0068 }
0069 
0070 const char *toChar(const QString &s)
0071 {
0072     return s.toLocal8Bit().constData();
0073 }
0074 }