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 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
32 #include <ETL/stringf>
35 #include <synfig/general.h>
39 #include <sys/types.h>
47 /* === U S I N G =========================================================== */
51 using namespace synfig;
52 using namespace synfigapp;
54 /* === M A C R O S ========================================================= */
56 #define cvs_command synfig::String("cvs -z4")
63 time_t _daylight_() { time_t t(time(0)); return localtime(&t)->tm_gmtoff; }
64 #define daylight _daylight_()
67 /* === G L O B A L S ======================================================= */
69 /* === P R O C E D U R E S ================================================= */
71 /* === M E T H O D S ======================================================= */
73 CVSInfo::CVSInfo(const synfig::String& file_name)
75 update_available_=false;
76 set_file_name(file_name);
81 update_available_=false;
89 CVSInfo::set_file_name(const synfig::String& file_name)
93 std::ifstream file((dirname(file_name_)+"/CVS/Root").c_str());
98 calc_repository_info();
105 CVSInfo::calc_repository_info()
108 synfig::info("in_sandbox() = %d",in_sandbox());
114 std::ifstream file((dirname(file_name_)+"/CVS/Entries").c_str());
120 if(line.find(basename(file_name_))!=String::npos)
123 String::size_type s,f;
127 assert(s!=String::npos);
129 f=line.find('/',s+1);
130 assert(f!=String::npos);
131 cvs_version_=String(line,s,f-s);
136 f=line.find('/',s+1);
137 assert(f!=String::npos);
139 strptime(String(line,s,f-s).c_str(),"%c",&time_struct);
140 original_timestamp_=mktime(&time_struct);
145 "cd '%s' && cvs status '%s' | grep -q -e 'Needs Patch'",
146 dirname(file_name_).c_str(),
147 basename(file_name_).c_str()
151 synfig::info("UPDATE_AVAILABLE=TRUE");
152 update_available_=true;
157 "cd '%s' && cvs status '%s'",
158 dirname(file_name_).c_str(),
159 basename(file_name_).c_str()
161 synfig::info("UPDATE_AVAILABLE=FALSE");
162 update_available_=false;
167 synfig::info("in_repository() = %d",in_repository());
168 synfig::info("get_cvs_version() = %s",get_cvs_version().c_str());
169 synfig::info("get_original_timestamp() = %s",ctime(&get_original_timestamp()));
170 time_t t(get_current_timestamp());
171 synfig::info("get_current_timestamp() = %s",ctime(&t));
172 synfig::info("get_cvs_root() = %s",get_cvs_root().c_str());
173 synfig::info("get_cvs_module() = %s",get_cvs_module().c_str());
179 in_repository_=false;
180 cvs_version_.clear();
181 original_timestamp_=0;
184 synfig::info("in_repository() = %d",in_repository());
189 CVSInfo::in_sandbox()const
195 CVSInfo::in_repository()const
199 return in_repository_;
203 CVSInfo::is_modified()const
206 synfig::info("%d-%d=%d",get_current_timestamp(),get_original_timestamp(),get_current_timestamp()-get_original_timestamp());
208 if(!in_sandbox() || !in_repository())
210 return get_current_timestamp()!=get_original_timestamp() && abs(get_current_timestamp()-get_original_timestamp())!=3600;
214 CVSInfo::is_updated()const
216 return update_available_;
219 const synfig::String&
220 CVSInfo::get_cvs_version()const
226 CVSInfo::get_original_timestamp()const
228 return original_timestamp_;
232 CVSInfo::get_current_timestamp()const
235 if(stat(file_name_.c_str(),&st)<0)
237 synfig::error("Unable to get file stats");
240 return st.st_mtime+timezone+(daylight-1)*3600;
244 CVSInfo::get_cvs_root()const
247 return synfig::String();
249 std::ifstream file((dirname(file_name_)+"/CVS/Root").c_str());
258 return synfig::String();
262 CVSInfo::get_cvs_module()const
265 return synfig::String();
267 std::ifstream file((dirname(file_name_)+"/CVS/Repository").c_str());
276 return synfig::String();
279 // This function pre-processes the message so that we
280 // don't get any CVS syntax errors.
281 inline synfig::String fix_msg(const synfig::String& message)
285 for(i=0;i<(int)message.size();i++)
296 CVSInfo::cvs_add(const synfig::String& message)
300 synfig::error("cvs_add(): Not in a sand box");
305 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()));
307 int ret(system(command.c_str()));
309 calc_repository_info();
316 synfig::error("Unknown errorcode %d (\"%s\")",ret,command.c_str());
323 CVSInfo::cvs_update()
327 synfig::error("cvs_update(): Not in a sand box");
332 synfig::String command(strprintf("cd '%s' && %s update '%s'",dirname(file_name_).c_str(),cvs_command.c_str(),basename(file_name_).c_str()));
334 int ret(system(command.c_str()));
336 calc_repository_info();
343 synfig::error("Unknown errorcode %d (\"%s\")",ret,command.c_str());
350 CVSInfo::cvs_commit(const synfig::String& message)
354 synfig::error("cvs_commit(): Not in a sand box");
359 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()));
361 int ret(system(command.c_str()));
363 calc_repository_info();
370 synfig::error("Unknown errorcode %d (\"%s\")",ret,command.c_str());