Change the format of the revprops block sent in svnserve for
[svn.git] / subversion / libsvn_wc / revision_status.c
blobd0f8ca746eb2cb79ad53d713bcebb1f36dd66e03
1 /*
2 * revision_status.c: report the revision range and status of a working copy
4 * ====================================================================
5 * Copyright (c) 2003-2004 CollabNet. All rights reserved.
7 * This software is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at http://subversion.tigris.org/license-1.html.
10 * If newer versions of this license are posted there, you may use a
11 * newer version instead, at your option.
13 * This software consists of voluntary contributions made by many
14 * individuals. For exact contribution history, see the revision
15 * history and logs, available at http://subversion.tigris.org/.
16 * ====================================================================
19 #include "svn_wc.h"
21 #include "svn_private_config.h"
24 /* A baton for analyze_status(). */
25 struct status_baton
27 svn_wc_revision_status_t *result; /* where to put the result */
28 svn_boolean_t committed; /* examine last committed revisions */
29 const char *wc_path; /* path whose URL we're looking for */
30 const char *wc_url; /* URL for the path whose URL we're looking for */
31 apr_pool_t *pool; /* pool in which to store alloc-needy things */
34 /* An svn_wc_status_func2_t callback function for analyzing status
35 structures. */
36 static void
37 analyze_status(void *baton,
38 const char *path,
39 svn_wc_status2_t *status)
41 struct status_baton *sb = baton;
43 if (! status->entry)
44 return;
46 /* Added files have a revision of no interest */
47 if (status->text_status != svn_wc_status_added)
49 svn_revnum_t item_rev = (sb->committed
50 ? status->entry->cmt_rev
51 : status->entry->revision);
53 if (sb->result->min_rev == SVN_INVALID_REVNUM
54 || item_rev < sb->result->min_rev)
55 sb->result->min_rev = item_rev;
57 if (sb->result->max_rev == SVN_INVALID_REVNUM
58 || item_rev > sb->result->max_rev)
59 sb->result->max_rev = item_rev;
62 sb->result->switched |= status->switched;
63 sb->result->modified |= (status->text_status != svn_wc_status_normal);
64 sb->result->modified |= (status->prop_status != svn_wc_status_normal
65 && status->prop_status != svn_wc_status_none);
66 sb->result->sparse_checkout |= (status->entry->depth != svn_depth_infinity);
68 if (sb->wc_path
69 && (! sb->wc_url)
70 && (strcmp(path, sb->wc_path) == 0)
71 && (status->entry))
72 sb->wc_url = apr_pstrdup(sb->pool, status->entry->url);
75 svn_error_t *
76 svn_wc_revision_status(svn_wc_revision_status_t **result_p,
77 const char *wc_path,
78 const char *trail_url,
79 svn_boolean_t committed,
80 svn_cancel_func_t cancel_func,
81 void *cancel_baton,
82 apr_pool_t *pool)
84 struct status_baton sb;
85 const char *target;
86 svn_wc_adm_access_t *anchor_access, *target_access;
87 const svn_delta_editor_t *editor;
88 void *edit_baton;
89 svn_revnum_t edit_revision;
90 svn_wc_revision_status_t *result = apr_palloc(pool, sizeof(**result_p));
91 *result_p = result;
93 /* set result as nil */
94 result->min_rev = SVN_INVALID_REVNUM;
95 result->max_rev = SVN_INVALID_REVNUM;
96 result->switched = FALSE;
97 result->modified = FALSE;
98 result->sparse_checkout = FALSE;
100 /* initialize walking baton */
101 sb.result = result;
102 sb.committed = committed;
103 sb.wc_path = wc_path;
104 sb.wc_url = NULL;
105 sb.pool = pool;
107 SVN_ERR(svn_wc_adm_open_anchor(&anchor_access, &target_access, &target,
108 wc_path, FALSE, -1,
109 cancel_func, cancel_baton,
110 pool));
112 SVN_ERR(svn_wc_get_status_editor3(&editor, &edit_baton, NULL,
113 &edit_revision, anchor_access, target,
114 svn_depth_infinity,
115 TRUE /* get_all */,
116 FALSE /* no_ignore */,
117 NULL /* ignore_patterns */,
118 analyze_status, &sb,
119 cancel_func, cancel_baton,
120 NULL /* traversal_info */,
121 pool));
123 SVN_ERR(editor->close_edit(edit_baton, pool));
125 SVN_ERR(svn_wc_adm_close(anchor_access));
127 if ((! result->switched) && (trail_url != NULL))
129 /* If the trailing part of the URL of the working copy directory
130 does not match the given trailing URL then the whole working
131 copy is switched. */
132 if (! sb.wc_url)
134 result->switched = TRUE;
136 else
138 apr_size_t len1 = strlen(trail_url);
139 apr_size_t len2 = strlen(sb.wc_url);
140 if ((len1 > len2) || strcmp(sb.wc_url + len2 - len1, trail_url))
141 result->switched = TRUE;
145 return SVN_NO_ERROR;