Skip to content

Commit 2c2c99d

Browse files
cleanup: De-duplicate path handling code (#150)
1 parent 5ab4983 commit 2c2c99d

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

indexer/Driver.cc

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,17 @@ struct DriverOptions {
149149
this->projectRootPath =
150150
RootPath{AbsolutePath{std::move(cwd)}, RootKind::Project};
151151

152-
if (llvm::sys::path::is_absolute(cliOpts.indexOutputPath)) {
153-
this->indexOutputPath =
154-
AbsolutePath(std::string(cliOpts.indexOutputPath));
155-
} else {
156-
this->indexOutputPath = this->projectRootPath.makeAbsolute(
157-
RootRelativePathRef(cliOpts.indexOutputPath, RootKind::Project));
158-
}
152+
auto setAbsolutePath = [this](const std::string &path, AbsolutePath &out) {
153+
if (llvm::sys::path::is_absolute(path)) {
154+
out = AbsolutePath(std::string(path));
155+
return;
156+
}
157+
out = this->projectRootPath.makeAbsolute(
158+
RootRelativePathRef(path, RootKind::Project));
159+
};
159160

160-
if (llvm::sys::path::is_absolute(cliOpts.compdbPath)) {
161-
this->compdbPath = AbsolutePath(std::string(cliOpts.compdbPath));
162-
} else {
163-
auto relPath = RootRelativePathRef(cliOpts.compdbPath, RootKind::Project);
164-
this->compdbPath = this->projectRootPath.makeAbsolute(relPath);
165-
}
161+
setAbsolutePath(cliOpts.indexOutputPath, this->indexOutputPath);
162+
setAbsolutePath(cliOpts.compdbPath, this->compdbPath);
166163

167164
auto makeDirs = [](const StdPath &path, const char *name) {
168165
std::error_code error;

0 commit comments

Comments
 (0)