aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Alexander Færøy <eroyf@eroyf.org> 2008-04-19 15:13:53 +0000
committerAvatar Alexander Færøy <root@seth.(none)> 2008-04-19 15:13:53 +0000
commit32b86df59039405bd643586f5528ef5b47ae172e (patch)
treed7622b068b0fd9ac1859339d7fc4058e7bcaff51
parent8e9f14f1aacaf55403d0e010a7faf0425bd6bc36 (diff)
downloadinops-32b86df59039405bd643586f5528ef5b47ae172e.tar.gz
inops-32b86df59039405bd643586f5528ef5b47ae172e.tar.xz
added git files
-rw-r--r--inops/vcs/Makefile.am1
-rw-r--r--inops/vcs/git.cc139
-rw-r--r--inops/vcs/git.hh53
3 files changed, 193 insertions, 0 deletions
diff --git a/inops/vcs/Makefile.am b/inops/vcs/Makefile.am
index b936147..d87dec0 100644
--- a/inops/vcs/Makefile.am
+++ b/inops/vcs/Makefile.am
@@ -12,4 +12,5 @@ libinopsvcs_a_SOURCES = \
vcs.cc vcs.hh \
vcs_file.cc vcs_file.hh \
svn.cc svn.hh \
+ git.cc git.hh \
novcs.cc novcs.hh
diff --git a/inops/vcs/git.cc b/inops/vcs/git.cc
new file mode 100644
index 0000000..7d9c596
--- /dev/null
+++ b/inops/vcs/git.cc
@@ -0,0 +1,139 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 Alexander Færøy
+ *
+ * This file is part of the Inops commit client. Inops is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Inops is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <inops/vcs/git.hh>
+
+#include <paludis/util/fd_holder.hh>
+#include <paludis/util/system.hh>
+#include <paludis/util/stringify.hh>
+#include <paludis/util/tr1_memory.hh>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+namespace inops
+{
+ GitError::GitError(const std::string & message) throw () :
+ Exception(message)
+ {
+ }
+
+ Git::Git()
+ {
+ std::stringstream output;
+ paludis::Command cmd("git rev-parse --git-dir");
+ std::string line;
+
+ paludis::FDHolder dev_null(::open("/dev/null", O_WRONLY));
+ paludis::set_run_command_stdout_fds(dev_null, -1);
+ paludis::set_run_command_stderr_fds(dev_null, -1);
+
+ if (paludis::run_command(cmd.with_captured_stdout_stream(&output)))
+ throw GitError("Unable to find git dir: " + output.str());
+
+ std::getline(output, line);
+ line.erase(line.length() - 4);
+ git_dir.reset(new paludis::FSEntry(line));
+ }
+
+ Git::~Git()
+ {
+ }
+
+ void Git::commit(const std::string & message)
+ {
+ std::stringstream output;
+ paludis::Command commit_command("git commit -m \"" + message + "\"");
+
+ paludis::FDHolder dev_null(::open("/dev/null", O_WRONLY));
+ paludis::set_run_command_stdout_fds(dev_null, -1);
+ paludis::set_run_command_stderr_fds(dev_null, -1);
+
+ if (paludis::run_command(commit_command.with_captured_stdout_stream(&output)))
+ throw GitError("Unable to perform commit with git: " + output.str());
+ }
+
+ void Git::update()
+ {
+ std::stringstream output;
+ paludis::Command update_command("git pull");
+
+ paludis::FDHolder dev_null(::open("/dev/null", O_WRONLY));
+ paludis::set_run_command_stdout_fds(dev_null, -1);
+ paludis::set_run_command_stderr_fds(dev_null, -1);
+
+ if (paludis::run_command(update_command.with_captured_stdout_stream(&output)))
+ throw GitError("Unable to perform update with git: " + output.str());
+ }
+
+ void Git::add_file(const paludis::FSEntry & file)
+ {
+ std::stringstream output;
+ paludis::Command add_command("git add \"" + paludis::stringify(file) + "\"");
+
+ paludis::FDHolder dev_null(::open("/dev/null", O_WRONLY));
+ paludis::set_run_command_stdout_fds(dev_null, -1);
+ paludis::set_run_command_stderr_fds(dev_null, -1);
+
+ if (paludis::run_command(add_command.with_captured_stdout_stream(&output)))
+ throw GitError("Unable to add file \"" + paludis::stringify(file) + "\" with git: " + output.str());
+ }
+
+ std::string Git::get_name()
+ {
+ return "git";
+ }
+
+ paludis::tr1::shared_ptr<VCSFileList> SVN::get_files()
+ {
+ paludis::tr1::shared_ptr<VCSFileList> file_list(new VCSFileList);
+ std::stringstream output;
+ paludis::Command file_command("git diff --name-status HEAD -- .");
+ std::string line;
+ std::string::size_type end_cwd(paludis::stringify(paludis::FSEntry::cwd()).length());
+
+ paludis::FDHolder dev_null(::open("/dev/null", O_WRONLY));
+ paludis::set_run_command_stdout_fds(dev_null, -1);
+ paludis::set_run_command_stderr_fds(dev_null, -1);
+
+ if (paludis::run_command(file_command.with_captured_stdout_stream(&output)))
+ throw GitError("Failed to find VCS files with git: " + output.str());
+
+ while (std::getline(output, line))
+ {
+ std::string file_path(paludis::strip_leading_string(line.substr(1), std::string(" ")));
+ file_path = (paludis::stringify(*git_dir) + file_path).erase(0, end_cwd);
+ paludis::FSEntry file_entry(file_path.substr(1));
+ VCSFileState file_state(vcs_fs_untracked);
+ char git_state(line.at(0));
+
+ if (git_state == 'A')
+ file_state = vcs_fs_added;
+ else if (git_state == 'M')
+ file_state = vcs_fs_modified;
+ else if (git_state == 'D')
+ file_state = vcs_fs_removed;
+
+ file_list->add_entry(paludis::tr1::shared_ptr<VCSFile>(new VCSFile(file_entry, file_state)));
+ }
+
+ return file_list;
+ }
+}
diff --git a/inops/vcs/git.hh b/inops/vcs/git.hh
new file mode 100644
index 0000000..b604751
--- /dev/null
+++ b/inops/vcs/git.hh
@@ -0,0 +1,53 @@
+/* vim: set sw=4 sts=4 et foldmethod=syntax : */
+
+/*
+ * Copyright (c) 2008 Alexander Færøy
+ *
+ * This file is part of the Inops commit client. Inops is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU General
+ * Public License version 2, as published by the Free Software Foundation.
+ *
+ * Inops is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef INOPS_GUARD_INOPS_VCS_GIT_HH
+#define INOPS_GUARD_INOPS_VCS_GIT_HH 1
+
+#include <inops/vcs/vcs.hh>
+#include <inops/utils/exception.hh>
+
+
+namespace inops
+{
+ class GitError :
+ public Exception
+ {
+ public:
+ GitError(const std::string & message) throw ();
+ };
+
+ class Git :
+ public VCS
+ {
+ private:
+ paludis::tr1::shared_ptr<paludis::FSEntry> git_dir;
+
+ public:
+ Git();
+ virtual ~Git();
+ virtual void commit(const std::string & message);
+ virtual void update();
+ virtual void add_file(const paludis::FSEntry & file);
+ virtual std::string get_name();
+ virtual paludis::tr1::shared_ptr<VCSFileList> get_files();
+ };
+}
+
+#endif