From 7a6c15e8ff135fc6b22b09038454d007da9642f4 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Sat, 11 Aug 2018 22:25:39 +0300 Subject: Make get-related functions to take minimum supported version as an argument --- bdep/git.cxx | 14 ++++++++----- bdep/git.hxx | 25 +++++++++++++++++----- bdep/git.ixx | 18 ++++++++++------ bdep/git.txx | 26 +++++++++++------------ bdep/project-email.cxx | 5 ++++- bdep/publish.cxx | 56 ++++++++++++++++++++++++++++++++++---------------- bdep/types.hxx | 5 +++++ tests/common.test | 9 +++++--- tests/publish.test | 6 ++++++ 9 files changed, 113 insertions(+), 51 deletions(-) diff --git a/bdep/git.cxx b/bdep/git.cxx index c0b48fc..79e6255 100644 --- a/bdep/git.cxx +++ b/bdep/git.cxx @@ -5,7 +5,6 @@ #include #include -#include #include @@ -15,8 +14,11 @@ namespace bdep { static optional git_ver; + // On the first call check that git is at least of the specified minimum + // supported version. + // void - git_check_version () + git_check_version (const standard_version& min_ver) { if (!git_ver) { @@ -25,14 +27,16 @@ namespace bdep // git_ver = standard_version (); - optional s (git_line (false /* ignore_error */, "--version")); + optional s (git_line (min_ver, + false /* ignore_error */, + "--version")); if (!s || !(git_ver = git_version (*s))) fail << "unable to obtain git version"; - if (git_ver->version < 20120000000) + if (*git_ver < min_ver) fail << "unsupported git version " << *git_ver << - info << "minimum supported version is 2.12.0" << endf; + info << "minimum supported version is " << min_ver << endf; } } diff --git a/bdep/git.hxx b/bdep/git.hxx index ca49622..6b112c8 100644 --- a/bdep/git.hxx +++ b/bdep/git.hxx @@ -14,31 +14,46 @@ namespace bdep { using butl::git_repository; + // All functions that start git process take the minimum supported git + // version as an argument. + // + // Start git process. + // template process - start_git (I&& in, O&& out, E&& err, A&&... args); + start_git (const standard_version&, I&& in, O&& out, E&& err, A&&... args); template process - start_git (const dir_path& repo, I&& in, O&& out, E&& err, A&&... args); + start_git (const standard_version&, + const dir_path& repo, + I&& in, O&& out, E&& err, + A&&... args); + // Wait git process to terminate. + // void finish_git (process& pr, bool io_read = false); + // Run git process. + // template void - run_git (const dir_path& repo, A&&... args); + run_git (const standard_version&, const dir_path& repo, A&&... args); // Return the first line of the git output. If ignore_error is true, then // suppress stderr, ignore (normal) error exit status, and return nullopt. // template optional - git_line (bool ignore_error, A&&... args); + git_line (const standard_version&, bool ignore_error, A&&... args); template optional - git_line (const dir_path& repo, bool ignore_error, A&&... args); + git_line (const standard_version&, + const dir_path& repo, + bool ignore_error, + A&&... args); // Similar to the above but takes the already started git process with a // redirected output pipe. diff --git a/bdep/git.ixx b/bdep/git.ixx index 9369564..0e3ee9f 100644 --- a/bdep/git.ixx +++ b/bdep/git.ixx @@ -6,11 +6,13 @@ namespace bdep { template inline process - start_git (const dir_path& repo, I&& in, O&& out, E&& err, A&&... args) + start_git (const standard_version& min_ver, + const dir_path& repo, + I&& in, O&& out, E&& err, + A&&... args) { - return start_git (forward (in), - forward (out), - forward (err), + return start_git (min_ver, + forward (in), forward (out), forward (err), "-C", repo, forward (args)...); } @@ -23,9 +25,13 @@ namespace bdep template inline optional - git_line (const dir_path& repo, bool ie, A&&... args) + git_line (const standard_version& min_ver, + const dir_path& repo, + bool ie, + A&&... args) { - return git_line (ie, + return git_line (min_ver, + ie, "-C", repo, forward (args)...); } diff --git a/bdep/git.txx b/bdep/git.txx index aef5f3d..19a9d42 100644 --- a/bdep/git.txx +++ b/bdep/git.txx @@ -6,41 +6,41 @@ namespace bdep { template void - run_git (const dir_path& repo, A&&... args) + run_git (const standard_version& min_ver, const dir_path& repo, A&&... args) { - process pr (start_git (repo, - 0 /* stdin */, - 1 /* stdout */, - 2 /* stderr */, + process pr (start_git (min_ver, + repo, + 0 /* stdin */, 1 /* stdout */, 2 /* stderr */, forward (args)...)); finish_git (pr); } void - git_check_version (); + git_check_version (const standard_version& min_ver); template process - start_git (I&& in, O&& out, E&& err, A&&... args) + start_git (const standard_version& min_ver, + I&& in, O&& out, E&& err, + A&&... args) { - git_check_version (); + git_check_version (min_ver); - return start (forward (in), - forward (out), - forward (err), + return start (forward (in), forward (out), forward (err), "git", forward (args)...); } template optional - git_line (bool ie, A&&... args) + git_line (const standard_version& min_ver, bool ie, A&&... args) { fdpipe pipe (fdopen_pipe ()); auto_fd null (ie ? fdnull () : auto_fd ()); - process pr (start_git (0 /* stdin */, + process pr (start_git (min_ver, + 0 /* stdin */, pipe /* stdout */, ie ? null.get () : 2 /* stderr */, forward (args)...)); diff --git a/bdep/project-email.cxx b/bdep/project-email.cxx index 6216d28..d43f4ff 100644 --- a/bdep/project-email.cxx +++ b/bdep/project-email.cxx @@ -11,6 +11,8 @@ using namespace butl; namespace bdep { + const standard_version git_ver ("2.1.0"); + optional project_email (const dir_path& prj) { @@ -35,7 +37,8 @@ namespace bdep // resolved value can be queried with the GIT_AUTHOR_IDENT logical // variable. // - if (optional l = git_line (prj, + if (optional l = git_line (git_ver, + prj, true /* ignore_error */, "var", "GIT_AUTHOR_IDENT")) { diff --git a/bdep/publish.cxx b/bdep/publish.cxx index 40a1724..df72da7 100644 --- a/bdep/publish.cxx +++ b/bdep/publish.cxx @@ -8,7 +8,6 @@ #include // fdterm() #include -#include #include #include @@ -26,6 +25,12 @@ using namespace butl; namespace bdep { + // The minimum supported git version must be at least 2.5 due to the git + // worktree command used. We also use bpkg that caps the git version at + // 2.12, so let's use is as the lowest common denominator. + // + const standard_version git_ver ("2.12.0"); + static inline url parse_url (const string& s, const char* what) { @@ -50,7 +55,8 @@ namespace bdep // a custom URL (e.g., if a correct one cannot be automatically derived // from remote.origin.url). // - if (optional l = git_line (prj, + if (optional l = git_line (git_ver, + prj, true /* ignore_error */, "config", "--get", @@ -62,7 +68,8 @@ namespace bdep // Otherwise, get remote.origin.url and try to derive an HTTPS URL from // it. // - if (optional l = git_line (prj, + if (optional l = git_line (git_ver, + prj, true /* ignore_error */, "config", "--get", @@ -790,7 +797,7 @@ namespace bdep // contains. // auto_rmdir dr_rm (tmp_dir ("publish")); - const dir_path& dr (dr_rm.path); // dist.root + const dir_path& dr (dr_rm.path); // dist.root mk (dr); for (package& p: pkgs) @@ -919,7 +926,8 @@ namespace bdep bool q (verb < 2); auto_fd null (q ? fdnull () : auto_fd ()); - process pr (start_git (prj, + process pr (start_git (git_ver, + prj, 0 /* stdin */, q ? null.get () : 1 /* stdout */, q ? null.get () : 2 /* stderr */, @@ -947,7 +955,7 @@ namespace bdep auto worktree_prune = [&prj] () { - run_git (prj, "worktree", "prune", verb > 2 ? "-v" : nullptr); + run_git (git_ver, prj, "worktree", "prune", verb > 2 ? "-v" : nullptr); }; // Create the build2-control branch if it doesn't exist, from scratch if @@ -962,7 +970,8 @@ namespace bdep // pull. In the rare conflict cases we will advise the user to run the // fetch command and re-try. // - bool local_exists (git_line (prj, + bool local_exists (git_line (git_ver, + prj, false /* ignore_error */, "branch", "--list", @@ -971,7 +980,8 @@ namespace bdep // @@ Should we allow using the remote name other than origin (here and // everywhere) via the --remote option or smth? Maybe later. // - bool remote_exists (git_line (prj, + bool remote_exists (git_line (git_ver, + prj, false /* ignore_error */, "branch", "--list", @@ -1003,7 +1013,8 @@ namespace bdep auto_fd null (fdnull ()); fdpipe pipe (fdopen_pipe ()); - process pr (start_git (prj, + process pr (start_git (git_ver, + prj, null.get () /* stdin */, pipe /* stdout */, 2 /* stderr */, @@ -1018,7 +1029,8 @@ namespace bdep // Create the (empty) root commit. // - optional commit (git_line (prj, + optional commit (git_line (git_ver, + prj, false, "commit-tree", "-m", "Start", @@ -1033,7 +1045,8 @@ namespace bdep // are creating does not exist. It should be impossible but let's // tighten things up a bit. // - run_git (prj, + run_git (git_ver, + prj, "update-ref", "refs/heads/build2-control", *commit, @@ -1055,7 +1068,8 @@ namespace bdep // Create the local branch, setting up the corresponding upstream // branch. // - run_git (prj, + run_git (git_ver, + prj, "branch", verb < 2 ? "-q" : nullptr, "build2-control", @@ -1129,7 +1143,8 @@ namespace bdep // the use to deal with. // if (local_exists && remote_exists) - run_git (wd, + run_git (git_ver, + wd, "merge", verb < 2 ? "-q" : verb > 2 ? "-v" : nullptr, "--ff-only", @@ -1168,7 +1183,8 @@ namespace bdep fail << "unable to write " << mf << ": " << e; } - run_git (wd, + run_git (git_ver, + wd, "add", verb > 2 ? "-v" : nullptr, submit_dir / ac); @@ -1205,7 +1221,8 @@ namespace bdep } } - run_git (wd, + run_git (git_ver, + wd, "commit", verb < 2 ? "-q" : verb > 2 ? "-v" : nullptr, "-m", m); @@ -1234,14 +1251,16 @@ namespace bdep { worktree_remove (); // Release the branch before removal. - run_git (prj, + run_git (git_ver, + prj, "branch", verb < 2 ? "-q" : nullptr, "-D", "build2-control"); } else - run_git (wd, + run_git (git_ver, + wd, "reset", verb < 2 ? "-q" : nullptr, "--hard", @@ -1266,7 +1285,8 @@ namespace bdep // the verbosity level is 1. However, we still want to see the // progress in this case. // - run_git (wd, + run_git (git_ver, + wd, "push", verb < 2 ? "-q" : verb > 3 ? "-v" : nullptr, diff --git a/bdep/types.hxx b/bdep/types.hxx index a9adee6..0c13639 100644 --- a/bdep/types.hxx +++ b/bdep/types.hxx @@ -28,6 +28,7 @@ #include #include #include +#include namespace bdep { @@ -109,6 +110,10 @@ namespace bdep using butl::ofdstream; using butl::fdopen_mode; using butl::fdstream_mode; + + // + // + using butl::standard_version; } // In order to be found (via ADL) these have to be either in std:: or in diff --git a/tests/common.test b/tests/common.test index 46f4abc..f532d76 100644 --- a/tests/common.test +++ b/tests/common.test @@ -15,7 +15,8 @@ build = $recall($build.path) test.options += --build $build -# Check that git version is the minimum supported one (2.12.0) or above. +# Check that git version is the minimum supported one or above. The lowest +# common denominator for bdep commands is 2.1. # +git --version | set git_version_out @@ -30,10 +31,12 @@ end +echo "$git_version" | sed -e 's/\d+\.(\d+).*/\1/' | set git_version_minor # This flag must be used by testscripts to decide if they should skip git -# repository-related tests. +# repository-related tests or adjust bdep commands. Note that specific command +# tests may still adjust this flag to express the higher requirements for the +# minimum supported git version. # git_supported = ($git_version_major > 2 || \ - $git_version_major == 2 && $git_version_minor >= 12) + $git_version_major == 2 && $git_version_minor >= 1) # Helper commands that can be used by tests to prepare the testing environment # or validate an outcome of the command being tested. They are likely to get diff --git a/tests/publish.test b/tests/publish.test index dbdcabd..8541d9c 100644 --- a/tests/publish.test +++ b/tests/publish.test @@ -24,6 +24,12 @@ init += $cxx -d prj 2>! &prj/**/bootstrap/*** windows = ($cxx.target.class == 'windows') +# bdep-publish requirements for the minimum supported git version are higher +# then the default 2.1 (see bdep/publish.cxx for details). +# +git_supported = ($git_version_major > 2 || \ + $git_version_major == 2 && $git_version_minor >= 12) + # Note that using the same package name and version for tests may result in # duplicate submissions. We will use unique version for each test, # incrementing the patch version for 1.0.X. -- cgit v1.1