2017-04-27 21:43:34 +03:00
|
|
|
/*
|
2019-06-20 02:58:25 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2017-04-27 21:43:34 +03:00
|
|
|
*
|
2019-06-20 02:58:25 +03:00
|
|
|
* This software may be used and distributed according to the terms of the
|
|
|
|
* GNU General Public License version 2.
|
2017-04-27 21:43:34 +03:00
|
|
|
*/
|
2019-10-11 15:26:59 +03:00
|
|
|
|
2017-04-27 21:43:34 +03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <iosfwd>
|
2018-10-24 03:03:11 +03:00
|
|
|
#include <optional>
|
2017-04-27 21:43:34 +03:00
|
|
|
|
|
|
|
#include "eden/fs/model/Hash.h"
|
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace eden {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Data about the parent commits for a working directory.
|
|
|
|
*
|
|
|
|
* In most circumstances there will only be a single parent, but there
|
|
|
|
* will be two parents when in the middle of resolving a merge conflict.
|
|
|
|
*/
|
|
|
|
class ParentCommits {
|
|
|
|
public:
|
|
|
|
ParentCommits() = default;
|
|
|
|
explicit ParentCommits(const Hash& p1) : parent1_{p1} {}
|
2018-10-24 03:03:11 +03:00
|
|
|
explicit ParentCommits(const Hash& p1, const std::optional<Hash>& p2)
|
2017-04-27 21:43:34 +03:00
|
|
|
: parent1_{p1}, parent2_{p2} {}
|
|
|
|
|
|
|
|
Hash& parent1() {
|
|
|
|
return parent1_;
|
|
|
|
}
|
|
|
|
const Hash& parent1() const {
|
|
|
|
return parent1_;
|
|
|
|
}
|
|
|
|
|
2018-10-24 03:03:11 +03:00
|
|
|
std::optional<Hash>& parent2() {
|
2017-04-27 21:43:34 +03:00
|
|
|
return parent2_;
|
|
|
|
}
|
2018-10-24 03:03:11 +03:00
|
|
|
const std::optional<Hash>& parent2() const {
|
2017-04-27 21:43:34 +03:00
|
|
|
return parent2_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setParents(const Hash& p1) {
|
|
|
|
parent1_ = p1;
|
2018-10-24 03:03:11 +03:00
|
|
|
parent2_ = std::nullopt;
|
2017-04-27 21:43:34 +03:00
|
|
|
}
|
2018-10-24 03:03:11 +03:00
|
|
|
void setParents(const Hash& p1, const std::optional<Hash>& p2) {
|
2017-04-27 21:43:34 +03:00
|
|
|
parent1_ = p1;
|
|
|
|
parent2_ = p2;
|
|
|
|
}
|
|
|
|
void setParents(const ParentCommits& parents) {
|
|
|
|
parent1_ = parents.parent1();
|
|
|
|
parent2_ = parents.parent2();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy constructor and copy assignment.
|
|
|
|
// There isn't much point in having move-assignment or move construction,
|
|
|
|
// since all of our data is stored inline, and can't really be moved.
|
|
|
|
ParentCommits(const ParentCommits& other) = default;
|
|
|
|
ParentCommits& operator=(const ParentCommits& other) = default;
|
|
|
|
|
|
|
|
bool operator==(const ParentCommits& other) const;
|
|
|
|
bool operator!=(const ParentCommits& other) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
Hash parent1_;
|
2018-10-24 03:03:11 +03:00
|
|
|
std::optional<Hash> parent2_;
|
2017-04-27 21:43:34 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Output stream operator for ParentCommits.
|
|
|
|
*
|
|
|
|
* This makes it possible to easily use ParentCommits in glog statements.
|
|
|
|
*/
|
|
|
|
std::ostream& operator<<(std::ostream& os, const ParentCommits& parents);
|
2017-11-04 01:58:04 +03:00
|
|
|
} // namespace eden
|
|
|
|
} // namespace facebook
|