File: ConfigSVNSource.cc

package info (click to toggle)
config-manager 0.3-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 3,180 kB
  • ctags: 802
  • sloc: sh: 8,865; cpp: 2,630; python: 2,191; makefile: 127
file content (165 lines) | stat: -rw-r--r-- 4,589 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
 * Copyright (C) 2003  Robert Collins  <robertc@squid-cache.org>
 *               2004  Rob Weir <rweir@ertius.org>
 * 
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program 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
 * 
 * DO NOT ALTER THE NEXT LINE
 * arch-tag: 86ccf9ce-01a4-40bd-a9c0-4e5289ed14eb
 *
 */

#include "ConfigSVNSource.h"
#include <iostream>
#include <stdexcept>
#include <getopt++/GetOption.h>
#include <getopt++/StringOption.h>
#include <getopt++/BoolOption.h>
#include <cassert>
#include <cstdlib>
#include <fstream>
#include "Path.h"


using namespace std;

ConfigSVNSource::ConfigSVNSource() 
{
}

ConfigSVNSource::ConfigSVNSource(string const &aUrl) : theUrl(aUrl)
{
    fake_url = aUrl;
    if ((theUrl.find("svn://") == 0) || (theUrl.find("svn+ssh://") == 0)) {
        real_url = aUrl;
    } else {
        real_url = theUrl.substr(4);
    }

    if (Verbose()) {
      cout << " processed SVN url: " << aUrl << "giving fake_url: " << fake_url << " and real_url: " << real_url << endl;
    }
}

string
ConfigSVNSource::url(bool const &stripScheme) const
{
    return (stripScheme ? fake_url : fake_url.substr(fake_url.find("://") + 2));
}

void
ConfigSVNSource::get
    (string const &where) const throw(exception *)
{
    string command = "cd `dirname " + where + "` && svn co " + real_url + " " + where;

    run (command, "SVN");
}

void
ConfigSVNSource::update (string const &where) const throw(exception *)
{
    string command = "cd " + where + " && svn update";

    run (command, "SVN");
}

int
ConfigSVNSource::changes (string const &where) const throw(exception *)
{
    string command = "cd " + where + " && svn diff | grep . > /dev/null || return 1 && return 0";

    return run_query (command, "SVN");
}

int
ConfigSVNSource::missing (string const &where) const throw(exception *)
{
    string command = "cd " + where + "&& svn status -u | grep ""\\*"" > /dev/null && return 1 || return 0";

    return run_query(command, "SVN");
}

string
ConfigSVNSource::getOneLineFile(string const & where) const
{
    ifstream buffer(where.c_str());
    string result;
    if (buffer.is_open())
	buffer >> result;
    return result;
}

string 
ConfigSVNSource::getRoot(string const &where) const
{
    return getOneLineFile(where + "/CVS/Root");
}

string 
ConfigSVNSource::getRepository(string const &where) const
{
    return getOneLineFile(where + "/CVS/Repository");
}

string
ConfigSVNSource::treeVersion(string const &where) const
{
}

void
ConfigSVNSource::ignore (ConfigSource const *, string const &where) const throw (std::exception *)
{
}

/* Repository (CVS/Root) + module + tag must remain the same */
ConfigSVNSource*
ConfigSVNSource::Create(Path const &location, ConfigSource const *mayBeParent) throw (std::exception *)
{
    ConfigSVNSource const *parent = dynamic_cast<ConfigSVNSource const *>(mayBeParent);

//     ConfigSVNSource *result = new ConfigSVNSource;
//     string Root = result->getRoot(location.fullName());
//     if (!Root.size()) {
// 	delete result;
// 	return NULL;
//     }
//     string Repository = result->getRepository(location.fullName());
//     if (!Repository.size()) {
// 	delete result;
// 	return NULL;
//     }
//     /* No parent, valid CVS dir */
//     if (!parent) {
// 	ConfigSVNSource *realResult = new ConfigSVNSource(result->treeVersion(location.fullName()));
// 	delete result;
// 	return realResult;
//     }
//     string canonical = Root + "/" + Repository;
//     canonical = schemeFromRepository(canonical);
//     /* check for a change in parent */
//     if ((canonical.find(urlScheme(parent->scheme) + parent->repository + "/" + parent->module) != 0)  ||
// 	/* XXX: fixme tags */
// 	(parent->tag != result->tag))
//       {
// 	/* new source */
// 	ConfigSVNSource *realResult = new ConfigSVNSource(result->treeVersion(location.fullName()));
// 	delete result;
// 	return realResult;
//       }
//     delete result;
    return const_cast<ConfigSVNSource *>(parent);
}