1 /*
2 * ====================================================================
3 * Copyright (c) 2002-2009 The RapidSvn Group. All rights reserved.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program (in the file GPL.txt.
17 * If not, see <http://www.gnu.org/licenses/>.
18 *
19 * This software consists of voluntary contributions made by many
20 * individuals. For exact contribution history, see the revision
21 * history and logs, available at http://rapidsvn.tigris.org/.
22 * ====================================================================
23 */
24 #if defined( _MSC_VER) && _MSC_VER <= 1200
25 #pragma warning( disable: 4786 )// debug symbol truncated
26 #endif
27
28 // subversion api
29 #include "svn_client.h"
30 #include "svn_path.h"
31 #include "svn_sorts.h"
32 #include "svn_version.h"
33 //#include "svn_utf.h"
34
35 // svncpp
36 #include "kdevsvncpp/client.hpp"
37 #include "kdevsvncpp/dirent.hpp"
38 #include "kdevsvncpp/exception.hpp"
39
40
41 #if SVN_VER_MAJOR == 1 && SVN_VER_MINOR < 8
42
43 static int
compare_items_as_paths(const svn_sort__item_t * a,const svn_sort__item_t * b)44 compare_items_as_paths(const svn_sort__item_t *a, const svn_sort__item_t *b)
45 {
46 return svn_path_compare_paths((const char *)a->key, (const char *)b->key);
47 }
48
49 namespace svn
50 {
51 DirEntries
list(const char * pathOrUrl,svn_opt_revision_t * revision,bool recurse)52 Client::list(const char * pathOrUrl,
53 svn_opt_revision_t * revision,
54 bool recurse)
55 {
56 Pool pool;
57
58 apr_hash_t * hash;
59 svn_error_t * error =
60 svn_client_ls(&hash,
61 pathOrUrl,
62 revision,
63 recurse,
64 *m_context,
65 pool);
66
67 if (error != 0)
68 throw ClientException(error);
69
70 apr_array_header_t *
71 array = svn_sort__hash(
72 hash, compare_items_as_paths, pool);
73
74 DirEntries entries;
75
76 for (int i = 0; i < array->nelts; ++i)
77 {
78 const char *entryname;
79 svn_dirent_t *dirent;
80 svn_sort__item_t *item;
81
82 item = &APR_ARRAY_IDX(array, i, svn_sort__item_t);
83
84 entryname = static_cast<const char *>(item->key);
85
86 dirent = static_cast<svn_dirent_t *>
87 (apr_hash_get(hash, entryname, item->klen));
88
89 entries.push_back(DirEntry(entryname, dirent));
90 }
91
92 return entries;
93 }
94 }
95
96 #else
97
98 #include <algorithm>
99
store_entry(void * baton,const char * path,const svn_dirent_t * dirent,const svn_lock_t *,const char * abs_path,const char *,const char *,apr_pool_t * scratch_pool)100 static svn_error_t* store_entry(
101 void *baton,
102 const char *path,
103 const svn_dirent_t *dirent,
104 const svn_lock_t *,
105 const char *abs_path,
106 const char *,
107 const char *,
108 apr_pool_t *scratch_pool)
109 {
110 svn::DirEntries *entries = reinterpret_cast<svn::DirEntries*>(baton);
111 if (path[0] == '\0') {
112 if (dirent->kind == svn_node_file) {
113 // for compatibility with svn_client_ls behaviour, listing a file
114 // stores that file name
115 entries->push_back(svn::DirEntry(svn_path_basename(abs_path, scratch_pool), dirent));
116 }
117 } else {
118 entries->push_back(svn::DirEntry(path, dirent));
119 }
120 return SVN_NO_ERROR;
121 }
122
sort_by_path(svn::DirEntry const & a,svn::DirEntry const & b)123 static bool sort_by_path(svn::DirEntry const& a, svn::DirEntry const& b)
124 {
125 return svn_path_compare_paths(a.name(), b.name()) < 0;
126 }
127
128 namespace svn
129 {
130 DirEntries
list(const char * pathOrUrl,svn_opt_revision_t * revision,bool recurse)131 Client::list(const char * pathOrUrl,
132 svn_opt_revision_t * revision,
133 bool recurse)
134 {
135 Pool pool;
136 DirEntries entries;
137
138 svn_error_t * error =
139 svn_client_list3(pathOrUrl,
140 revision,
141 revision,
142 SVN_DEPTH_INFINITY_OR_IMMEDIATES(recurse),
143 SVN_DIRENT_ALL,
144 FALSE, // fetch locks
145 FALSE, // include externals
146 &store_entry,
147 &entries,
148 *m_context,
149 pool);
150
151 if (error != SVN_NO_ERROR)
152 throw ClientException(error);
153
154 std::sort(entries.begin(), entries.end(), &sort_by_path);
155
156 return entries;
157 }
158 }
159
160 #endif
161
162 /* -----------------------------------------------------------------
163 * local variables:
164 * eval: (load-file "../../rapidsvn-dev.el")
165 * end:
166 */
167