1 /* === S Y N F I G ========================================================= */
3 ** \brief Template File
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>
50 /* === U S I N G =========================================================== */
54 using namespace synfig;
55 using namespace synfigapp;
57 /* === M A C R O S ========================================================= */
59 #define cvs_command synfig::String("cvs -z4")
66 time_t _daylight_() { time_t t(time(0)); return localtime(&t)->tm_gmtoff; }
67 #define daylight _daylight_()
70 /* === G L O B A L S ======================================================= */
72 /* === P R O C E D U R E S ================================================= */
74 /* === M E T H O D S ======================================================= */
76 CVSInfo::CVSInfo(const synfig::String& file_name)
78 update_available_=false;
79 set_file_name(file_name);
84 update_available_=false;
92 CVSInfo::set_file_name(const synfig::String& file_name)
96 std::ifstream file((dirname(file_name_)+"/CVS/Root").c_str());
101 calc_repository_info();
108 CVSInfo::calc_repository_info()
111 synfig::info("in_sandbox() = %d",in_sandbox());
117 std::ifstream file((dirname(file_name_)+"/CVS/Entries").c_str());
123 if(line.find(basename(file_name_))!=String::npos)
126 String::size_type s,f;
130 assert(s!=String::npos);
132 f=line.find('/',s+1);
133 assert(f!=String::npos);
134 cvs_version_=String(line,s,f-s);
139 f=line.find('/',s+1);
140 assert(f!=String::npos);
142 strptime(String(line,s,f-s).c_str(),"%c",&time_struct);
143 original_timestamp_=mktime(&time_struct);
148 "cd '%s' && cvs status '%s' | grep -q -e 'Needs Patch'",
149 dirname(file_name_).c_str(),
150 basename(file_name_).c_str()
154 synfig::info("UPDATE_AVAILABLE=TRUE");
155 update_available_=true;
160 "cd '%s' && cvs status '%s'",
161 dirname(file_name_).c_str(),
162 basename(file_name_).c_str()
164 synfig::info("UPDATE_AVAILABLE=FALSE");
165 update_available_=false;
170 synfig::info("in_repository() = %d",in_repository());
171 synfig::info("get_cvs_version() = %s",get_cvs_version().c_str());
172 synfig::info("get_original_timestamp() = %s",ctime(&get_original_timestamp()));
173 time_t t(get_current_timestamp());
174 synfig::info("get_current_timestamp() = %s",ctime(&t));
175 synfig::info("get_cvs_root() = %s",get_cvs_root().c_str());
176 synfig::info("get_cvs_module() = %s",get_cvs_module().c_str());
182 in_repository_=false;
183 cvs_version_.clear();
184 original_timestamp_=0;
187 synfig::info("in_repository() = %d",in_repository());
192 CVSInfo::in_sandbox()const
198 CVSInfo::in_repository()const
202 return in_repository_;
206 CVSInfo::is_modified()const
208 if(!in_sandbox() || !in_repository())
211 synfig::info("%d-%d=%d",get_current_timestamp(),get_original_timestamp(),get_current_timestamp()-get_original_timestamp());
213 return get_current_timestamp()!=get_original_timestamp() && abs(get_current_timestamp()-get_original_timestamp())!=3600;
217 CVSInfo::is_updated()const
219 return update_available_;
222 const synfig::String&
223 CVSInfo::get_cvs_version()const
229 CVSInfo::get_original_timestamp()const
231 return original_timestamp_;
235 CVSInfo::get_current_timestamp()const
238 if(stat(file_name_.c_str(),&st)<0)
240 synfig::error("Unable to get file stats");
243 time_t ret((daylight-1)*3600);
250 CVSInfo::get_cvs_root()const
253 return synfig::String();
255 std::ifstream file((dirname(file_name_)+"/CVS/Root").c_str());
264 return synfig::String();
268 CVSInfo::get_cvs_module()const
271 return synfig::String();
273 std::ifstream file((dirname(file_name_)+"/CVS/Repository").c_str());
282 return synfig::String();
285 // This function pre-processes the message so that we
286 // don't get any CVS syntax errors.
287 inline synfig::String fix_msg(const synfig::String& message)
291 for(i=0;i<(int)message.size();i++)
302 CVSInfo::cvs_add(const synfig::String& message)
306 synfig::error("cvs_add(): Not in a sand box");
311 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()));
313 int ret(system(command.c_str()));
315 calc_repository_info();
322 synfig::error("Unknown errorcode %d (\"%s\")",ret,command.c_str());
329 CVSInfo::cvs_update()
333 synfig::error("cvs_update(): Not in a sand box");
338 synfig::String command(strprintf("cd '%s' && %s update '%s'",dirname(file_name_).c_str(),cvs_command.c_str(),basename(file_name_).c_str()));
340 int ret(system(command.c_str()));
342 calc_repository_info();
349 synfig::error("Unknown errorcode %d (\"%s\")",ret,command.c_str());
356 CVSInfo::cvs_commit(const synfig::String& message)
360 synfig::error("cvs_commit(): Not in a sand box");
365 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()));
367 int ret(system(command.c_str()));
369 calc_repository_info();
376 synfig::error("Unknown errorcode %d (\"%s\")",ret,command.c_str());