| 1 |
#pragma once |
| 2 |
|
| 3 |
#include "iarchive.h" |
| 4 |
#include <git2.h> |
| 5 |
#include "stream/BufferInputStream.h" |
| 6 |
|
| 7 |
namespace vcs |
| 8 |
{ |
| 9 |
|
| 10 |
namespace git |
| 11 |
{ |
| 12 |
|
| 13 |
// Adapter class, implementing the ArchiveTextFile interface to a Git BLOB |
| 14 |
class GitArchiveTextFile : |
| 15 |
public ArchiveTextFile |
| 16 |
{ |
| 17 |
private: |
| 18 |
git_blob* _blob; |
| 19 |
std::size_t _blobSize; |
| 20 |
const void* _blobContents; |
| 21 |
|
| 22 |
std::string _path; |
| 23 |
|
| 24 |
stream::BufferInputStream _stream; |
| 25 |
|
| 26 |
public: |
| 27 |
using Ptr = std::shared_ptr<GitArchiveTextFile>; |
| 28 |
|
| 29 |
GitArchiveTextFile(git_blob* blob, const std::string& path) : |
| 30 |
_blob(blob), |
| 31 |
_blobSize(git_blob_rawsize(_blob)), |
| 32 |
_blobContents(git_blob_rawcontent(_blob)), |
| 33 |
_path(path), |
| 34 |
_stream(reinterpret_cast<const char*>(_blobContents), _blobSize) |
| 35 |
{} |
| 36 |
|
| 37 |
~GitArchiveTextFile() |
| 38 |
{ |
| 39 |
git_blob_free(_blob); |
| 40 |
} |
| 41 |
|
| 42 |
std::string getModName() const override |
| 43 |
{ |
| 44 |
return "Git History"; |
| 45 |
} |
| 46 |
|
| 47 |
const std::string& getName() const override |
| 48 |
{ |
| 49 |
return _path; |
| 50 |
} |
| 51 |
|
| 52 |
TextInputStream& getInputStream() override |
| 53 |
{ |
| 54 |
return _stream; |
| 55 |
} |
| 56 |
}; |
| 57 |
|
| 58 |
} |
| 59 |
|
| 60 |
} |