sapling/eden/fs/inodes/DiffContext.h
Sergey Zhupanov b6394ac357 Added user and general system level gitignore
Summary:
Added to Eden capability to incorporate default user and general system level gitignore files.
NOTE: Work in progress, sending the review out to calibrate/ensure I am on right track.

Reviewed By: simpkins

Differential Revision: D6482863

fbshipit-source-id: 9834ca1a577a9599a1f8cb2243dca4e714866be8
2017-12-08 12:52:51 -08:00

74 lines
2.4 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.
*
*/
#pragma once
#include <folly/Range.h>
#include <string>
#include "eden/fs/model/git/GitIgnoreStack.h"
#include "eden/fs/utils/PathFuncs.h"
namespace facebook {
namespace eden {
class InodeDiffCallback;
class ObjectStore;
/**
* A small helper class to store parameters for a TreeInode::diff() operation.
*
* These are parameters that remain fixed across all subdirectories being
* diffed. This class is mostly just for convenience so that we do not have to
* pass these items in individually as separate parameters to each function
* being called.
*/
class DiffContext {
public:
// Loads the system-wide ignore settings and user-specific
// ignore settings into top level git ignore stack
DiffContext(InodeDiffCallback* cb, bool listIgnored, const ObjectStore* os);
// this constructor is primarily intended for testing
DiffContext(
InodeDiffCallback* cb,
bool listIgnored,
const ObjectStore* os,
folly::StringPiece systemWideIgnoreFileContents,
folly::StringPiece userIgnoreFileContents);
const GitIgnoreStack* getToplevelIgnore() const {
return ownedIgnores_.empty() ? nullptr : ownedIgnores_.back().get();
}
InodeDiffCallback* const callback;
const ObjectStore* const store;
/**
* If listIgnored is true information about ignored files will be reported.
* If listIgnored is false then ignoredFile() will never be called on the
* callback. The diff operation may be faster with listIgnored=false, since
* it can completely omit processing ignored subdirectories.
*/
bool const listIgnored;
private:
static AbsolutePath constructUserIgnoreFileName();
static std::string tryIngestFile(folly::StringPiece fileName);
void initOwnedIgnores(
folly::StringPiece systemWideIgnoreFileContents,
folly::StringPiece userIgnoreFileContents);
void pushFrameIfAvailable(folly::StringPiece ignoreFileContents);
static constexpr folly::StringPiece kSystemWideIgnoreFileName =
"/etc/eden/ignore";
const AbsolutePath userIgnoreFileName_;
std::vector<std::unique_ptr<GitIgnoreStack>> ownedIgnores_;
};
} // namespace eden
} // namespace facebook