1 /* === S Y N F I G ========================================================= */
3 ** \brief Template File
5 ** $Id: cvs.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
33 #include <ETL/stringf>
36 #include <synfig/general.h>
40 #include <sys/types.h>
48 /* === U S I N G =========================================================== */
52 using namespace synfig;
53 using namespace synfigapp;
55 /* === M A C R O S ========================================================= */
57 #define cvs_command synfig::String("cvs -z4")
64 time_t _daylight_() { time_t t(time(0)); return localtime(&t)->tm_gmtoff; }
65 #define daylight _daylight_()
68 /* === G L O B A L S ======================================================= */
70 /* === P R O C E D U R E S ================================================= */
72 /* === M E T H O D S ======================================================= */
74 CVSInfo::CVSInfo(const synfig::String& file_name)
76 update_available_=false;
77 set_file_name(file_name);
82 update_available_=false;
90 CVSInfo::set_file_name(const synfig::String& file_name)
94 std::ifstream file((dirname(file_name_)+"/CVS/Root").c_str());
99 calc_repository_info();
106 CVSInfo::calc_repository_info()
109 synfig::info("in_sandbox() = %d",in_sandbox());
115 std::ifstream file((dirname(file_name_)+"/CVS/Entries").c_str());
121 if(line.find(basename(file_name_))!=String::npos)
124 String::size_type s,f;
128 assert(s!=String::npos);
130 f=line.find('/',s+1);
131 assert(f!=String::npos);
132 cvs_version_=String(line,s,f-s);
137 f=line.find('/',s+1);
138 assert(f!=String::npos);
140 strptime(String(line,s,f-s).c_str(),"%c",&time_struct);
141 original_timestamp_=mktime(&time_struct);
146 "cd '%s' && cvs status '%s' | grep -q -e 'Needs Patch'",
147 dirname(file_name_).c_str(),
148 basename(file_name_).c_str()
152 synfig::info("UPDATE_AVAILABLE=TRUE");
153 update_available_=true;
158 "cd '%s' && cvs status '%s'",
159 dirname(file_name_).c_str(),
160 basename(file_name_).c_str()
162 synfig::info("UPDATE_AVAILABLE=FALSE");
163 update_available_=false;
168 synfig::info("in_repository() = %d",in_repository());
169 synfig::info("get_cvs_version() = %s",get_cvs_version().c_str());
170 synfig::info("get_original_timestamp() = %s",ctime(&get_original_timestamp()));
171 time_t t(get_current_timestamp());
172 synfig::info("get_current_timestamp() = %s",ctime(&t));
173 synfig::info("get_cvs_root() = %s",get_cvs_root().c_str());
174 synfig::info("get_cvs_module() = %s",get_cvs_module().c_str());
180 in_repository_=false;
181 cvs_version_.clear();
182 original_timestamp_=0;
185 synfig::info("in_repository() = %d",in_repository());
190 CVSInfo::in_sandbox()const
196 CVSInfo::in_repository()const
200 return in_repository_;
204 CVSInfo::is_modified()const
207 synfig::info("%d-%d=%d",get_current_timestamp(),get_original_timestamp(),get_current_timestamp()-get_original_timestamp());
209 if(!in_sandbox() || !in_repository())
211 return get_current_timestamp()!=get_original_timestamp() && abs(get_current_timestamp()-get_original_timestamp())!=3600;
215 CVSInfo::is_updated()const
217 return update_available_;
220 const synfig::String&
221 CVSInfo::get_cvs_version()const
227 CVSInfo::get_original_timestamp()const
229 return original_timestamp_;
233 CVSInfo::get_current_timestamp()const
236 if(stat(file_name_.c_str(),&st)<0)
238 synfig::error("Unable to get file stats");
241 time_t ret((daylight-1)*3600);
248 CVSInfo::get_cvs_root()const
251 return synfig::String();
253 std::ifstream file((dirname(file_name_)+"/CVS/Root").c_str());
262 return synfig::String();
266 CVSInfo::get_cvs_module()const
269 return synfig::String();
271 std::ifstream file((dirname(file_name_)+"/CVS/Repository").c_str());
280 return synfig::String();
283 // This function pre-processes the message so that we
284 // don't get any CVS syntax errors.
285 inline synfig::String fix_msg(const synfig::String& message)
289 for(i=0;i<(int)message.size();i++)
300 CVSInfo::cvs_add(const synfig::String& message)
304 synfig::error("cvs_add(): Not in a sand box");
309 synfig::String command(strprintf("cd '%s' && %s add -m '%s' '%s'",dirname(file_name_).c_str(),cvs_command.c_str(),fix_msg(message).c_str(),basename(file_name_).c_str()));
311 int ret(system(command.c_str()));
313 calc_repository_info();
320 synfig::error("Unknown errorcode %d (\"%s\")",ret,command.c_str());
327 CVSInfo::cvs_update()
331 synfig::error("cvs_update(): Not in a sand box");
336 synfig::String command(strprintf("cd '%s' && %s update '%s'",dirname(file_name_).c_str(),cvs_command.c_str(),basename(file_name_).c_str()));
338 int ret(system(command.c_str()));
340 calc_repository_info();
347 synfig::error("Unknown errorcode %d (\"%s\")",ret,command.c_str());
354 CVSInfo::cvs_commit(const synfig::String& message)
358 synfig::error("cvs_commit(): Not in a sand box");
363 synfig::String command(strprintf("cd '%s' && %s commit -m '%s' '%s'",dirname(file_name_).c_str(),cvs_command.c_str(),fix_msg(message).c_str(),basename(file_name_).c_str()));
365 int ret(system(command.c_str()));
367 calc_repository_info();
374 synfig::error("Unknown errorcode %d (\"%s\")",ret,command.c_str());