aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/version/snapshot.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2019-08-01 16:10:48 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2019-08-01 16:41:08 +0300
commitda9cbf29c403d27c2940f9b31199c4648f8ae4a1 (patch)
tree9732de6f48bdaead2becf32be41b1284e1e83e00 /libbuild2/version/snapshot.cxx
parent8e69e09b7ec68377758c63092f9b254e95a0d7be (diff)
Move version build system module to separate library
Diffstat (limited to 'libbuild2/version/snapshot.cxx')
-rw-r--r--libbuild2/version/snapshot.cxx39
1 files changed, 39 insertions, 0 deletions
diff --git a/libbuild2/version/snapshot.cxx b/libbuild2/version/snapshot.cxx
new file mode 100644
index 0000000..46b37f3
--- /dev/null
+++ b/libbuild2/version/snapshot.cxx
@@ -0,0 +1,39 @@
+// file : libbuild2/version/snapshot.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#include <libbuild2/version/snapshot.hxx>
+
+#include <libbuild2/filesystem.hxx>
+
+using namespace std;
+
+namespace build2
+{
+ namespace version
+ {
+ snapshot
+ extract_snapshot_git (const dir_path&);
+
+ static const path git (".git");
+
+ snapshot
+ extract_snapshot (const scope& rs)
+ {
+ // Ignore errors when checking for existence since we may be iterating
+ // over directories past any reasonable project boundaries.
+ //
+ for (dir_path d (rs.src_path ()); !d.empty (); d = d.directory ())
+ {
+ // .git can be either a directory or a file in case of a submodule.
+ //
+ if (butl::entry_exists (d / git,
+ true /* follow_symlinks */,
+ true /* ignore_errors */))
+ return extract_snapshot_git (d);
+ }
+
+ return snapshot ();
+ }
+ }
+}