mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 16:57:49 +03:00
895a0196d9
Summary: Our Model TreeEntry code was a bit too general - in reality, both git and hg only support a handful of specific tree entries: regular files, executable files, symlinks, and trees. (git also supports submodules.) This diff delays the expansion of a TreeEntry's type into a full mode_t. Reviewed By: simpkins Differential Revision: D6980003 fbshipit-source-id: 73729208000668078a180b728d7e0bb9169c6f3c
78 lines
1.9 KiB
C++
78 lines
1.9 KiB
C++
/*
|
|
* Copyright (c) 2004-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*
|
|
*/
|
|
#include "eden/fs/model/TreeEntry.h"
|
|
|
|
#include <ostream>
|
|
|
|
#include <folly/Conv.h>
|
|
#include <folly/Range.h>
|
|
|
|
namespace facebook {
|
|
namespace eden {
|
|
|
|
std::string TreeEntry::toLogString() const {
|
|
char fileTypeChar = '?';
|
|
switch (fileType_) {
|
|
case FileType::DIRECTORY:
|
|
fileTypeChar = 'd';
|
|
break;
|
|
case FileType::REGULAR_FILE:
|
|
fileTypeChar = 'f';
|
|
break;
|
|
case FileType::EXECUTABLE_FILE:
|
|
fileTypeChar = 'x';
|
|
break;
|
|
case FileType::SYMLINK:
|
|
fileTypeChar = 'l';
|
|
break;
|
|
}
|
|
|
|
return folly::to<std::string>(
|
|
"(", name_, ", ", hash_.toString(), ", ", fileTypeChar, ")");
|
|
}
|
|
|
|
std::ostream& operator<<(std::ostream& os, FileType type) {
|
|
switch (type) {
|
|
case FileType::DIRECTORY:
|
|
return os << "DIRECTORY";
|
|
case FileType::REGULAR_FILE:
|
|
return os << "REGULAR_FILE";
|
|
case FileType::EXECUTABLE_FILE:
|
|
return os << "EXECUTABLE_FILE";
|
|
case FileType::SYMLINK:
|
|
return os << "SYMLINK";
|
|
}
|
|
|
|
return os << "FileType::" << int(type);
|
|
}
|
|
|
|
std::ostream& operator<<(std::ostream& os, TreeEntryType type) {
|
|
switch (type) {
|
|
case TreeEntryType::TREE:
|
|
return os << "TREE";
|
|
case TreeEntryType::BLOB:
|
|
return os << "BLOB";
|
|
}
|
|
|
|
return os << "TreeEntryType::" << int(type);
|
|
}
|
|
|
|
bool operator==(const TreeEntry& entry1, const TreeEntry& entry2) {
|
|
return (entry1.getHash() == entry2.getHash()) &&
|
|
(entry1.getFileType() == entry2.getFileType()) &&
|
|
(entry1.getName() == entry2.getName());
|
|
}
|
|
|
|
bool operator!=(const TreeEntry& entry1, const TreeEntry& entry2) {
|
|
return !(entry1 == entry2);
|
|
}
|
|
} // namespace eden
|
|
} // namespace facebook
|