Skip to content

Commit d4f8309

Browse files
committed
address review comments
1 parent 33bebf0 commit d4f8309

15 files changed

+88
-156
lines changed

src/subcommand/checkout_subcommand.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,6 @@ void checkout_subcommand::run()
5656
}
5757
}
5858

59-
std::optional<annotated_commit_wrapper> checkout_subcommand::resolve_local_ref
60-
(
61-
const repository_wrapper& repo,
62-
const std::string& target_name
63-
)
64-
{
65-
if (auto ref = repo.find_reference_dwim(target_name))
66-
{
67-
return repo.find_annotated_commit(*ref);
68-
}
69-
else if (auto obj = repo.revparse_single(target_name))
70-
{
71-
return repo.find_annotated_commit(obj->oid());
72-
}
73-
else
74-
{
75-
return std::nullopt;
76-
}
77-
}
78-
7959
annotated_commit_wrapper checkout_subcommand::create_local_branch
8060
(
8161
repository_wrapper& repo,

src/subcommand/checkout_subcommand.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ class checkout_subcommand
1717

1818
private:
1919

20-
std::optional<annotated_commit_wrapper> resolve_local_ref
21-
(
22-
const repository_wrapper& repo,
23-
const std::string& target_name
24-
);
25-
2620
annotated_commit_wrapper create_local_branch
2721
(
2822
repository_wrapper& repo,

src/subcommand/merge_subcommand.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <git2/types.h>
33

44
#include "merge_subcommand.hpp"
5-
#include "../wrapper/repository_wrapper.hpp"
5+
// #include "../wrapper/repository_wrapper.hpp"
66

77

88
merge_subcommand::merge_subcommand(const libgit2_object&, CLI::App& app)
@@ -14,7 +14,7 @@ merge_subcommand::merge_subcommand(const libgit2_object&, CLI::App& app)
1414
sub->callback([this]() { this->run(); });
1515
}
1616

17-
annotated_commit_list_wrapper resolve_heads(const repository_wrapper& repo, std::vector<std::string> m_branches_to_merge)
17+
annotated_commit_list_wrapper merge_subcommand::resolve_heads(const repository_wrapper& repo)
1818
{
1919
std::vector<annotated_commit_wrapper> commits_to_merge;
2020
commits_to_merge.reserve(m_branches_to_merge.size());
@@ -30,7 +30,7 @@ annotated_commit_list_wrapper resolve_heads(const repository_wrapper& repo, std:
3030
return annotated_commit_list_wrapper(std::move(commits_to_merge));
3131
}
3232

33-
void perform_fastforward(repository_wrapper& repo, const git_oid* target_oid, int is_unborn)
33+
void perform_fastforward(repository_wrapper& repo, const git_oid target_oid, int is_unborn)
3434
{
3535
const git_checkout_options ff_checkout_options = GIT_CHECKOUT_OPTIONS_INIT;
3636

@@ -45,13 +45,13 @@ void perform_fastforward(repository_wrapper& repo, const git_oid* target_oid, in
4545
return repo->find_reference("HEAD");
4646
}
4747
};
48-
auto target_ref = lambda_get_target_ref(&repo, is_unborn);
48+
reference_wrapper target_ref = lambda_get_target_ref(&repo, is_unborn);
4949

50-
auto target = repo.find_object(target_oid, GIT_OBJECT_COMMIT);
50+
object_wrapper target = repo.find_object(target_oid, GIT_OBJECT_COMMIT);
5151

52-
repo.checkout_tree(target, &ff_checkout_options);
52+
repo.checkout_tree(target, ff_checkout_options);
5353

54-
auto new_target_ref = target_ref.new_ref(target_oid);
54+
target_ref.write_new_ref(target_oid);
5555
}
5656

5757
void merge_subcommand::run()
@@ -68,7 +68,7 @@ void merge_subcommand::run()
6868

6969
git_merge_analysis_t analysis;
7070
git_merge_preference_t preference;
71-
annotated_commit_list_wrapper commits_to_merge = resolve_heads(repo, m_branches_to_merge);
71+
annotated_commit_list_wrapper commits_to_merge = resolve_heads(repo);
7272
size_t num_commits_to_merge = commits_to_merge.size();
7373
git_annotated_commit** c_commits_to_merge = commits_to_merge;
7474
auto commits_to_merge_const = const_cast<const git_annotated_commit**>(c_commits_to_merge);
@@ -83,7 +83,6 @@ void merge_subcommand::run()
8383
(analysis & GIT_MERGE_ANALYSIS_FASTFORWARD &&
8484
!(preference & GIT_MERGE_PREFERENCE_NO_FASTFORWARD)))
8585
{
86-
const git_oid* target_oid;
8786
if (analysis & GIT_MERGE_ANALYSIS_UNBORN)
8887
{
8988
std::cout << "Unborn" << std::endl;
@@ -93,7 +92,8 @@ void merge_subcommand::run()
9392
std::cout << "Fast-forward" << std::endl;
9493
}
9594
const annotated_commit_wrapper& commit = commits_to_merge.front();
96-
target_oid = &commit.oid();
95+
const git_oid target_oid = commit.oid();
96+
// Since this is a fast-forward, there can be only one merge head.
9797
assert(num_commits_to_merge == 1);
9898
perform_fastforward(repo, target_oid, (analysis & GIT_MERGE_ANALYSIS_UNBORN));
9999
}

src/subcommand/merge_subcommand.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <CLI/CLI.hpp>
44

55
#include "../utils/common.hpp"
6+
#include "../wrapper/repository_wrapper.hpp"
67

78
class merge_subcommand
89
{
@@ -12,5 +13,8 @@ class merge_subcommand
1213
void run();
1314

1415
private:
16+
17+
annotated_commit_list_wrapper resolve_heads(const repository_wrapper& repo);
18+
1519
std::vector<std::string> m_branches_to_merge;
1620
};
Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "../wrapper/annotated_commit_wrapper.hpp"
2-
#include <iostream>
32

43
annotated_commit_wrapper::annotated_commit_wrapper(git_annotated_commit* commit)
54
: base_type(commit)
@@ -22,38 +21,3 @@ std::string_view annotated_commit_wrapper::reference_name() const
2221
const char* res = git_annotated_commit_ref(*this);
2322
return res ? res : std::string_view{};
2423
}
25-
26-
annotated_commit_list_wrapper::annotated_commit_list_wrapper(std::vector<annotated_commit_wrapper> annotated_commit_list)
27-
: m_annotated_commit_list(std::move(annotated_commit_list))
28-
{
29-
p_resource = new git_annotated_commit*[m_annotated_commit_list.size()];
30-
for (size_t i=0; i<m_annotated_commit_list.size(); ++i)
31-
{
32-
p_resource[i] = m_annotated_commit_list[i];
33-
}
34-
}
35-
36-
annotated_commit_list_wrapper::~annotated_commit_list_wrapper()
37-
{
38-
delete[] p_resource;
39-
p_resource = nullptr;
40-
}
41-
42-
size_t annotated_commit_list_wrapper::size() const
43-
{
44-
return m_annotated_commit_list.size();
45-
}
46-
47-
annotated_commit_wrapper annotated_commit_list_wrapper::front()
48-
{
49-
return annotated_commit_wrapper(std::move(m_annotated_commit_list.front()));
50-
}
51-
52-
void annotated_commit_list_wrapper::print() const
53-
{
54-
std::cout << "aclw - p_resource = " << p_resource <<std::endl;
55-
for (size_t i=0; i<m_annotated_commit_list.size(); ++i)
56-
{
57-
std::cout << "aclw - p_resource[i] = :" << p_resource[i] << std::endl;
58-
}
59-
}
Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#pragma once
22

33
#include <string_view>
4-
#include <vector>
54

65
#include <git2.h>
76

@@ -28,25 +27,4 @@ class annotated_commit_wrapper : public wrapper_base<git_annotated_commit>
2827
friend class repository_wrapper;
2928
};
3029

31-
class annotated_commit_list_wrapper : public wrapper_base<git_annotated_commit*>
32-
{
33-
public:
34-
35-
using base_type = wrapper_base<git_annotated_commit*>;
36-
37-
explicit annotated_commit_list_wrapper(std::vector<annotated_commit_wrapper> annotated_commit_list);
38-
39-
~annotated_commit_list_wrapper();
40-
41-
annotated_commit_list_wrapper(annotated_commit_list_wrapper&&) noexcept = default;
42-
annotated_commit_list_wrapper& operator=(annotated_commit_list_wrapper&&) noexcept = default;
43-
44-
size_t size() const;
45-
annotated_commit_wrapper front();
46-
void print() const;
47-
48-
private:
49-
50-
std::vector<annotated_commit_wrapper> m_annotated_commit_list;
51-
52-
};
30+
using annotated_commit_list_wrapper = list_wrapper<annotated_commit_wrapper>;

src/wrapper/commit_wrapper.cpp

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,3 @@ std::string commit_wrapper::commit_oid_tostr() const
2626
char buf[GIT_OID_SHA1_HEXSIZE + 1];
2727
return git_oid_tostr(buf, sizeof(buf), &this->oid());
2828
}
29-
30-
commit_list_wrapper::commit_list_wrapper(std::vector<commit_wrapper> commit_list)
31-
{
32-
git_commit** p_resource = new git_commit*[m_commit_list.size()];
33-
for (size_t i=0; i<m_commit_list.size(); ++i)
34-
{
35-
p_resource[i] = m_commit_list[i];
36-
}
37-
}
38-
39-
commit_list_wrapper::~commit_list_wrapper()
40-
{
41-
delete[] p_resource;
42-
p_resource = nullptr;
43-
}
44-
45-
size_t commit_list_wrapper::size() const
46-
{
47-
return m_commit_list.size();
48-
}

src/wrapper/commit_wrapper.hpp

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,4 @@ class commit_wrapper : public wrapper_base<git_commit>
3030
friend class reference_wrapper;
3131
};
3232

33-
class commit_list_wrapper : public wrapper_base<git_commit*>
34-
{
35-
public:
36-
37-
using base_type = wrapper_base<git_commit*>;
38-
39-
explicit commit_list_wrapper(std::vector<commit_wrapper> commit_list);
40-
41-
~commit_list_wrapper();
42-
43-
commit_list_wrapper(commit_list_wrapper&&) noexcept = default;
44-
commit_list_wrapper& operator=(commit_list_wrapper&&) noexcept = default;
45-
46-
size_t size() const;
47-
48-
private:
49-
50-
std::vector<commit_wrapper> m_commit_list;
51-
52-
};
33+
using commit_list_wrapper = list_wrapper<commit_wrapper>;

src/wrapper/refs_wrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ const git_oid* reference_wrapper::target() const
3030
return git_reference_target(p_resource);
3131
}
3232

33-
reference_wrapper reference_wrapper::new_ref(const git_oid* target_oid)
33+
reference_wrapper reference_wrapper::write_new_ref(const git_oid target_oid)
3434
{
3535
git_reference* new_ref;
36-
throw_if_error(git_reference_set_target(&new_ref, p_resource, target_oid, NULL));
36+
throw_if_error(git_reference_set_target(&new_ref, p_resource, &target_oid, NULL));
3737
return reference_wrapper(new_ref);
3838
}

src/wrapper/refs_wrapper.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class reference_wrapper : public wrapper_base<git_reference>
2323
std::string short_name() const;
2424
bool is_remote() const;
2525
const git_oid* target() const;
26-
reference_wrapper new_ref(const git_oid* target_oid);
26+
reference_wrapper write_new_ref(const git_oid target_oid);
2727

2828
template <class W>
2929
W peel() const;

0 commit comments

Comments
 (0)