Skip to content
This repository has been archived by the owner on Jan 19, 2021. It is now read-only.

Commit

Permalink
Introduce move, copy and assignment constructors.
Browse files Browse the repository at this point in the history
  • Loading branch information
josephbirkner committed Dec 3, 2020
1 parent c8e08a4 commit 0fb889f
Show file tree
Hide file tree
Showing 65 changed files with 662 additions and 33 deletions.
6 changes: 6 additions & 0 deletions include/cppgit2/annotated_commit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class annotated_commit : public libgit2_api {
// Cleanup
~annotated_commit();

// Move constructor (appropriate other's c_ptr_)
annotated_commit(annotated_commit&& other);

// Move assignment constructor (appropriate other's c_ptr_)
annotated_commit& operator= (annotated_commit&& other);

// Gets the commit ID that the given git_annotated_commit refers to.
oid id() const;

Expand Down
6 changes: 6 additions & 0 deletions include/cppgit2/blame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ class blame : public libgit2_api {
// Free blame object if owned by user
~blame();

// Move constructor (appropriate other's c_ptr_)
blame(blame&& other);

// Move assignment constructor (appropriate other's c_ptr_)
blame& operator= (blame&& other);

// Get blame data for a file that has been modified in memory. The reference
// parameter is a pre-calculated blame for the in-odb history of the file.
// This means that once a file blame is completed (which can be expensive),
Expand Down
9 changes: 9 additions & 0 deletions include/cppgit2/blob.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,21 @@ class blob : public libgit2_api {
// Free blob with git_blob_free
~blob();

// Move constructor (appropriate other's c_ptr_)
blob(blob&& other);

// Move assignment constructor (appropriate other's c_ptr_)
blob& operator= (blob&& other);

// Owner repository
class repository owner() const;

// Create an in-memory copy of a blob
blob copy() const;

// Copy constructor
blob(blob const& other);

// SHA1 hash for this blob
oid id() const;

Expand Down
9 changes: 9 additions & 0 deletions include/cppgit2/commit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class commit : public libgit2_api {
commit(git_commit *c_ptr, ownership owner = ownership::libgit2);
~commit();

// Move constructor (appropriate other's c_ptr_)
commit(commit&& other);

// Move assignment constructor (appropriate other's c_ptr_)
commit& operator= (commit&& other);

// Amend an existing commit by replacing only non-NULL values
void amend(const oid &id, const std::string &update_ref,
const signature &author, const signature &committer,
Expand All @@ -36,6 +42,9 @@ class commit : public libgit2_api {
// Duplicate this commit object
commit copy() const;

// Copy constructor
commit(commit const& other);

// Get an arbitrary header field
std::string operator[](const std::string &field) const;

Expand Down
6 changes: 6 additions & 0 deletions include/cppgit2/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ class config : public libgit2_api {
config(git_config *c_ptr, ownership owner = ownership::libgit2);
~config();

// Move constructor (appropriate other's c_ptr_)
config(config&& other);

// Move assignment constructor (appropriate other's c_ptr_)
config& operator= (config&& other);

// Priority levels correspond to natural escalation logic
// when searching for config entries in git
enum class priority_level {
Expand Down
6 changes: 6 additions & 0 deletions include/cppgit2/credential.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ class credential : public libgit2_api {
// Cleanup credential object
~credential();

// Move constructor (appropriate other's c_ptr_)
credential(credential&& other);

// Move assignment constructor (appropriate other's c_ptr_)
credential& operator= (credential&& other);

// Supported credential types
// This represents the various types of authentication methods supported by
// the library.
Expand Down
6 changes: 6 additions & 0 deletions include/cppgit2/data_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ class data_buffer : public libgit2_api {
// Dispose internal buffer
~data_buffer();

// Move constructor (appropriate other's c_struct_)
data_buffer(data_buffer&& other);

// Move assignment constructor (appropriate other's c_struct_)
data_buffer& operator= (data_buffer&& other);

// Check quickly if buffer contains a NUL byte
bool contains_nul() const;

Expand Down
6 changes: 6 additions & 0 deletions include/cppgit2/diff.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ class diff : public libgit2_api {
// Free if owned by user
~diff();

// Move constructor (appropriate other's c_ptr_)
diff(diff&& other);

// Move assignment constructor (appropriate other's c_ptr_)
diff& operator= (diff&& other);

class delta : public libgit2_api {
public:
delta() {}
Expand Down
6 changes: 6 additions & 0 deletions include/cppgit2/index.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class index : public libgit2_api {
// Free index object if owned by user
~index();

// Move constructor (appropriate other's c_ptr_)
index(index&& other);

// Move assignment constructor (appropriate other's c_ptr_)
index& operator= (index&& other);

// Time structure used in a git index entry
struct time {
int32_t seconds;
Expand Down
6 changes: 6 additions & 0 deletions include/cppgit2/indexer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class indexer : public libgit2_api {
// Free indexer if owned by user
~indexer();

// Move constructor (appropriate other's c_ptr_)
indexer(indexer&& other);

// Move assignment constructor (appropriate other's c_ptr_)
indexer& operator= (indexer&& other);

// This structure is used to provide callers information about the progress of
// indexing a packfile, either directly or part of a fetch or clone that
// downloads a packfile.
Expand Down
6 changes: 6 additions & 0 deletions include/cppgit2/note.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ class note : public libgit2_api {
note(git_note *c_ptr, ownership owner = ownership::libgit2);
~note();

// Move constructor (appropriate other's c_ptr_)
note(note&& other);

// Move assignment constructor (appropriate other's c_ptr_)
note& operator= (note&& other);

// Get the note author
signature author() const;

Expand Down
9 changes: 9 additions & 0 deletions include/cppgit2/object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ class object : public libgit2_api {
// Free git object if owned by user
~object();

// Move constructor (appropriate other's c_ptr_)
object(object&& other);

// Move assignment constructor (appropriate other's c_ptr_)
object& operator= (object&& other);

// SHA1 hash of this object
oid id() const;

Expand All @@ -27,6 +33,9 @@ class object : public libgit2_api {
// Clone this object
object copy() const;

// Copy constructor
object(object const& other);

// Basic type (loose or packed) of any git object
enum class object_type {
any = -2,
Expand Down
6 changes: 6 additions & 0 deletions include/cppgit2/odb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ class odb : public libgit2_api {
// Cleanup odb object if owned by user
~odb();

// Move constructor (appropriate other's c_ptr_)
odb(odb&& other);

// Move assignment constructor (appropriate other's c_ptr_)
odb& operator= (odb&& other);

class backend : public libgit2_api {
public:
// Default construct an ODB backend
Expand Down
3 changes: 3 additions & 0 deletions include/cppgit2/oid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class oid : public libgit2_api {
// Copy an oid from one structure to another
oid copy() const;

// Copy constructor
oid(oid const& other);

// Check if an oid is all zeros
bool is_zero() const;

Expand Down
6 changes: 6 additions & 0 deletions include/cppgit2/pack_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ class pack_builder : public libgit2_api {
// Free packbuilder ptr if owned by user
~pack_builder();

// Move constructor (appropriate other's c_ptr_)
pack_builder(pack_builder&& other);

// Move assignment constructor (appropriate other's c_ptr_)
pack_builder& operator= (pack_builder&& other);

// Create the new pack and pass each object to the callback
void for_each_object(
std::function<void(void *object_data, size_t object_size)> visitor);
Expand Down
6 changes: 6 additions & 0 deletions include/cppgit2/patch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ class patch : public libgit2_api {
// Cleanup patch object
~patch();

// Move constructor (appropriate other's c_ptr_)
patch(patch&& other);

// Move assignment constructor (appropriate other's c_ptr_)
patch& operator= (patch&& other);

// Get the delta associated with a patch.
// This delta points to internal data, owned by libgit2
diff::delta delta() const;
Expand Down
6 changes: 6 additions & 0 deletions include/cppgit2/pathspec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ class pathspec : public libgit2_api {
// Cleanup pathspec if needed
~pathspec();

// Move constructor (appropriate other's c_ptr_)
pathspec(pathspec&& other);

// Move assignment constructor (appropriate other's c_ptr_)
pathspec& operator= (pathspec&& other);

enum class flag {
default_ = 0,
ignore_case = (1u << 0),
Expand Down
6 changes: 6 additions & 0 deletions include/cppgit2/rebase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ class rebase : public libgit2_api {
// Free rebase object if owned by user
~rebase();

// Move constructor (appropriate other's c_ptr_)
rebase(rebase&& other);

// Move assignment constructor (appropriate other's c_ptr_)
rebase& operator= (rebase&& other);

// A rebase operation
// Describes a single instruction/operation to be performed during the
// rebase.
Expand Down
9 changes: 9 additions & 0 deletions include/cppgit2/reference.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ class reference : public libgit2_api {
reference(git_reference *c_ptr, ownership owner = ownership::libgit2);
~reference();

// Move constructor (appropriate other's c_ptr_)
reference(reference&& other);

// Move assignment constructor (appropriate other's c_ptr_)
reference& operator= (reference&& other);

// Basic type of any Git reference
enum class reference_type {
invalid = 0, // Invalid reference
Expand All @@ -33,6 +39,9 @@ class reference : public libgit2_api {
// Create a duplicate of an existing reference
reference copy() const;

// Copy constructor
reference(reference const& other);

// Check if this reference ...
bool is_branch() const;
bool is_note() const;
Expand Down
6 changes: 6 additions & 0 deletions include/cppgit2/reflog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ class reflog : public libgit2_api {
// Free reflog if owned by user
~reflog();

// Move constructor (appropriate other's c_ptr_)
reflog(reflog&& other);

// Move assignment constructor (appropriate other's c_ptr_)
reflog& operator= (reflog&& other);

// Entry in this reflog
class entry : public libgit2_api {
public:
Expand Down
6 changes: 6 additions & 0 deletions include/cppgit2/refspec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class refspec : public libgit2_api {
// Cleanup refspec object
~refspec();

// Move constructor (appropriate other's c_ptr_)
refspec(refspec&& other);

// Move assignment constructor (appropriate other's c_ptr_)
refspec& operator= (refspec&& other);

// Get the refspec's direction.
connection_direction direction() const;

Expand Down
9 changes: 9 additions & 0 deletions include/cppgit2/remote.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ class remote : public libgit2_api {
// Cleanup remote object
~remote();

// Move constructor (appropriate other's c_ptr_)
remote(remote&& other);

// Move assignment constructor (appropriate other's c_ptr_)
remote& operator= (remote&& other);

// Retrieve the tag auto-follow setting
fetch::options::autotag autotag_option();

Expand Down Expand Up @@ -124,6 +130,9 @@ class remote : public libgit2_api {
// Callbacks are not duplicated.
remote copy() const;

// Copy constructor
remote(remote const& other);

// Create a remote without a connected local repo
// You can use this when you have a URL instead of a remote's name.
//
Expand Down
6 changes: 6 additions & 0 deletions include/cppgit2/repository.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ class repository : public libgit2_api {
// Free git_repository ptr
~repository();

// Move constructor (appropriate other's c_ptr_)
repository(repository&& other);

// Move assignment constructor (appropriate other's c_ptr_)
repository& operator= (repository&& other);

// Initialize git repository
static repository init(const std::string &path, bool is_bare);

Expand Down
4 changes: 2 additions & 2 deletions include/cppgit2/revspec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ class revspec : public libgit2_api {
}

// The left element of the revspec; must be freed by the user
object from() const { return from_; }
object const& from() const { return from_; }

// The right element of the revspec; must be freed by the user
object to() const { return to_; }
object const& to() const { return to_; }

revparse::mode flags() const {
return static_cast<revparse::mode>(c_ptr_->flags);
Expand Down
6 changes: 6 additions & 0 deletions include/cppgit2/revwalk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class revwalk : public libgit2_api {
// Cleanup revwalk
~revwalk();

// Move constructor (appropriate other's c_ptr_)
revwalk(revwalk&& other);

// Move assignment constructor (appropriate other's c_ptr_)
revwalk& operator= (revwalk&& other);

// Adds, changes or removes a callback function to hide a commit and its
// parents.
//
Expand Down
3 changes: 3 additions & 0 deletions include/cppgit2/signature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class signature : public libgit2_api {
// Duplicate this signature
signature copy() const;

// Copy constructor
signature(signature const& other);

// Getters
std::string name() const;
std::string email() const;
Expand Down
9 changes: 9 additions & 0 deletions include/cppgit2/strarray.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,18 @@ class strarray : public libgit2_api {
// Free the git_strarray struct
~strarray();

// Move constructor (appropriate other's c_struct_)
strarray(strarray&& other);

// Move assignment constructor (appropriate other's c_struct_)
strarray& operator= (strarray&& other);

// Duplicate this array
strarray copy() const;

// Copy constructor
strarray(strarray const& other);

// Build vector of tag names from strarray
std::vector<std::string> to_vector() const;

Expand Down

0 comments on commit 0fb889f

Please sign in to comment.