1 | // $Id: utility.cc 100 2006-06-19 09:53:16Z peter $ |
---|
2 | |
---|
3 | /* |
---|
4 | Copyright (C) 2006 Jari Häkkinen, Peter Johansson |
---|
5 | |
---|
6 | This file is part of svnstat, http://lev.thep.lu.se/trac/svnstat |
---|
7 | |
---|
8 | svnstat is free software; you can redistribute it and/or modify it |
---|
9 | under the terms of the GNU General Public License as published by |
---|
10 | the Free Software Foundation; either version 2 of the License, or |
---|
11 | (at your option) any later version. |
---|
12 | |
---|
13 | svnstat is distributed in the hope that it will be useful, but |
---|
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with this program; if not, write to the Free Software |
---|
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
---|
21 | 02111-1307, USA. |
---|
22 | */ |
---|
23 | |
---|
24 | #include "utility.h" |
---|
25 | #include "rmdirhier.h" |
---|
26 | |
---|
27 | #include <fstream> |
---|
28 | #include <iostream> |
---|
29 | #include <map> |
---|
30 | #include <sstream> |
---|
31 | #include <string> |
---|
32 | #include <sys/stat.h> |
---|
33 | |
---|
34 | namespace theplu{ |
---|
35 | namespace svnstat{ |
---|
36 | |
---|
37 | int blame(const std::string& path) |
---|
38 | { |
---|
39 | std::string system_call="svn blame " + path + " 1> svnstat.tmp 2> /dev/null"; |
---|
40 | int system_return = system(system_call.c_str()); |
---|
41 | if (system_return) |
---|
42 | std::cerr << "Error: svn blame " << path << std::endl; |
---|
43 | return system_return; |
---|
44 | } |
---|
45 | |
---|
46 | int createdir(const std::string& dir, bool force) |
---|
47 | { |
---|
48 | struct stat buf; |
---|
49 | if (force && !stat(dir.c_str(),&buf)) |
---|
50 | rmdirhier(dir); |
---|
51 | |
---|
52 | return mkdir(dir.c_str(),0777); |
---|
53 | } |
---|
54 | |
---|
55 | std::string file_name(const std::string& full_path) |
---|
56 | { |
---|
57 | std::stringstream ss(full_path); |
---|
58 | std::string name; |
---|
59 | while (getline(ss,name,'/')) {} |
---|
60 | return name; |
---|
61 | } |
---|
62 | |
---|
63 | std::map<std::string, std::string> info(const std::string& path) |
---|
64 | { |
---|
65 | std::string system_call="svn info " + path + " 1> svnstat.tmp 2> /dev/null"; |
---|
66 | int system_return = system(system_call.c_str()); |
---|
67 | if (system_return) |
---|
68 | return std::map<std::string, std::string>(); |
---|
69 | |
---|
70 | std::ifstream is("svnstat.tmp"); |
---|
71 | std::string line; |
---|
72 | std::map<std::string, std::string> svn_info; |
---|
73 | while (getline(is,line)){ |
---|
74 | std::stringstream ss(line); |
---|
75 | std::string tag; |
---|
76 | getline(ss,tag,':'); |
---|
77 | ss >> svn_info[tag]; |
---|
78 | } |
---|
79 | return svn_info; |
---|
80 | } |
---|
81 | |
---|
82 | |
---|
83 | |
---|
84 | |
---|
85 | }} // end of namespace svnstat and namespace theplu |
---|