mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 15:27:13 +03:00
add == and != comparisons for Tree objects
Summary: Add == and != operators for Tree and TreeEntry. These are mainly useful for unit tests to compare that imported trees look as expected. Reviewed By: wez Differential Revision: D5365956 fbshipit-source-id: c039dfc58e430e99466db1a6c891a3c50d7906fe
This commit is contained in:
parent
1f52adbca4
commit
7e7d208127
23
eden/fs/model/Tree.cpp
Normal file
23
eden/fs/model/Tree.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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 "Tree.h"
|
||||
|
||||
namespace facebook {
|
||||
namespace eden {
|
||||
bool operator==(const Tree& tree1, const Tree& tree2) {
|
||||
return (tree1.getHash() == tree2.getHash()) &&
|
||||
(tree1.getTreeEntries() == tree2.getTreeEntries());
|
||||
}
|
||||
|
||||
bool operator!=(const Tree& tree1, const Tree& tree2) {
|
||||
return !(tree1 == tree2);
|
||||
}
|
||||
}
|
||||
}
|
@ -61,5 +61,8 @@ class Tree {
|
||||
const Hash hash_;
|
||||
const std::vector<TreeEntry> entries_;
|
||||
};
|
||||
|
||||
bool operator==(const Tree& tree1, const Tree& tree2);
|
||||
bool operator!=(const Tree& tree1, const Tree& tree2);
|
||||
}
|
||||
}
|
||||
|
@ -27,5 +27,16 @@ std::ostream& operator<<(std::ostream& os, TreeEntryType type) {
|
||||
os << "TreeEntryType::" << int(type);
|
||||
return os;
|
||||
}
|
||||
|
||||
bool operator==(const TreeEntry& entry1, const TreeEntry& entry2) {
|
||||
return (entry1.getHash() == entry2.getHash()) &&
|
||||
(entry1.getFileType() == entry2.getFileType()) &&
|
||||
(entry1.getOwnerPermissions() == entry2.getOwnerPermissions()) &&
|
||||
(entry1.getName() == entry2.getName());
|
||||
}
|
||||
|
||||
bool operator!=(const TreeEntry& entry1, const TreeEntry& entry2) {
|
||||
return !(entry1 == entry2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -98,5 +98,7 @@ class TreeEntry {
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, TreeEntryType type);
|
||||
bool operator==(const TreeEntry& entry1, const TreeEntry& entry2);
|
||||
bool operator!=(const TreeEntry& entry1, const TreeEntry& entry2);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user