📄 merge.c
字号:
/* and we haven't seen these elements yet */ mc->href->len = 0; mc->vsn_name->len = 0; mc->vsn_url->len = 0; /* FALLTHROUGH */ case ELEM_ignored_set: case ELEM_checked_in: /* if we see an href "soon", then its parent is ELM */ mc->href_parent = elm->id; break; case ELEM_updated_set: case ELEM_merged_set: mc->response_parent = elm->id; break; case ELEM_propstat: /* initialize the status so we can figure out if we ever saw a status element in the propstat */ mc->status = 0; break; case ELEM_resourcetype: /* we've seen a DAV:resourcetype, so it will be "regular" unless we see something within this element */ mc->rtype = RTYPE_REGULAR; break; case ELEM_collection: mc->rtype = RTYPE_COLLECTION; break; case ELEM_baseline: mc->rtype = RTYPE_BASELINE; break; default: /* one of: ELEM_href, ELEM_status, ELEM_prop, ELEM_version_name */ break; } return SVN_RA_DAV__XML_VALID;}static int end_element(void *userdata, const svn_ra_dav__xml_elm_t *elm, const char *cdata){ merge_ctx_t *mc = userdata; switch (elm->id) { case ELEM_href: switch (mc->href_parent) { case ELEM_ignored_set: add_ignored(mc, cdata); break; case ELEM_response: /* we're now working on this href... */ svn_ra_dav__copy_href(mc->href, cdata); break; case ELEM_checked_in: svn_ra_dav__copy_href(mc->vsn_url, cdata); break; } break; case ELEM_responsedescription: /* ### I don't think we'll see this right now, due to validate_element */ /* ### remember this for error messages? */ break; case ELEM_status: { ne_status hs; if (ne_parse_statusline(cdata, &hs) != 0) mc->response_has_error = TRUE; else { mc->status = hs.code; if (hs.code != 200) { /* ### create an error structure? */ mc->response_has_error = TRUE; } free(hs.reason_phrase); } if (mc->response_has_error && mc->err == NULL) { /* ### fix this error value */ mc->err = svn_error_create(APR_EGENERAL, NULL, _("The MERGE property response had an " "error status")); } } break; case ELEM_propstat: /* ### does Neon have a symbol for 200? */ if (mc->status == 200 /* OK */) { /* ### what to do? reset all the data? */ } /* ### else issue an error? status==0 means we never saw one */ break; case ELEM_response: { svn_error_t *err; /* the end of a DAV:response means that we've seen all the information related to this resource. process it. */ err = handle_resource(mc, mc->scratchpool); if (err != NULL) { /* ### how best to handle this error? for now, just remember the ### first one found */ if (mc->err == NULL) mc->err = err; else svn_error_clear(err); } svn_pool_clear(mc->scratchpool); } break; case ELEM_checked_in: /* When we leave a DAV:checked-in element, the parents are DAV:prop, DAV:propstat, then DAV:response. If we see a DAV:href "on the way out", then it is going to belong to the DAV:response. */ mc->href_parent = ELEM_response; break; case ELEM_version_name: svn_stringbuf_set(mc->vsn_name, cdata); break; case ELEM_post_commit_err: svn_stringbuf_set(mc->post_commit_err, cdata); break; case ELEM_creationdate: svn_stringbuf_set(mc->committed_date, cdata); break; case ELEM_creator_displayname: svn_stringbuf_set(mc->last_author, cdata); break; default: /* one of: ELEM_updated_set, ELEM_merged_set, ELEM_ignored_set, ELEM_prop, ELEM_resourcetype, ELEM_collection, ELEM_baseline */ break; } return SVN_RA_DAV__XML_VALID;}svn_error_t * svn_ra_dav__assemble_locktoken_body(svn_stringbuf_t **body, apr_hash_t *lock_tokens, apr_pool_t *pool){ apr_hash_index_t *hi; apr_size_t buf_size; const char *closing_tag = "</S:lock-token-list>"; apr_size_t closing_tag_size = strlen(closing_tag); apr_pool_t *tmppool = svn_pool_create(pool); apr_hash_t *xml_locks = apr_hash_make(tmppool); svn_stringbuf_t *lockbuf = svn_stringbuf_create ("<S:lock-token-list xmlns:S=\"" SVN_XML_NAMESPACE "\">" DEBUG_CR, pool); buf_size = lockbuf->len;#define SVN_LOCK "<S:lock>" DEBUG_CR#define SVN_LOCK_LEN sizeof(SVN_LOCK)-1#define SVN_LOCK_CLOSE "</S:lock>" DEBUG_CR#define SVN_LOCK_CLOSE_LEN sizeof(SVN_LOCK_CLOSE)-1#define SVN_LOCK_PATH "<S:lock-path>"#define SVN_LOCK_PATH_LEN sizeof(SVN_LOCK_PATH)-1#define SVN_LOCK_PATH_CLOSE "</S:lock-path>" DEBUG_CR#define SVN_LOCK_PATH_CLOSE_LEN sizeof(SVN_LOCK_CLOSE)-1#define SVN_LOCK_TOKEN "<S:lock-token>"#define SVN_LOCK_TOKEN_LEN sizeof(SVN_LOCK_TOKEN)-1#define SVN_LOCK_TOKEN_CLOSE "</S:lock-token>" DEBUG_CR#define SVN_LOCK_TOKEN_CLOSE_LEN sizeof(SVN_LOCK_TOKEN_CLOSE)-1 /* First, figure out how much string data we're talking about, and allocate a stringbuf big enough to hold it all... we *never* want have the stringbuf do an auto-reallocation. While here, we'll be copying our hash of paths -> tokens into a hash of xml-escaped-paths -> tokens. */ for (hi = apr_hash_first(tmppool, lock_tokens); hi; hi = apr_hash_next(hi)) { const void *key; void *val; apr_ssize_t klen; svn_string_t lock_path; svn_stringbuf_t *lock_path_xml = NULL; apr_hash_this(hi, &key, &klen, &val); /* XML-escape our key and store it in our temporary hash. */ lock_path.data = key; lock_path.len = klen; svn_xml_escape_cdata_string(&lock_path_xml, &lock_path, tmppool); apr_hash_set(xml_locks, lock_path_xml->data, lock_path_xml->len, val); /* Now, on with the stringbuf calculations. */ buf_size += SVN_LOCK_LEN; buf_size += SVN_LOCK_PATH_LEN; buf_size += lock_path_xml->len; buf_size += SVN_LOCK_PATH_CLOSE_LEN; buf_size += SVN_LOCK_TOKEN_LEN; buf_size += strlen(val); buf_size += SVN_LOCK_TOKEN_CLOSE_LEN; buf_size += SVN_LOCK_CLOSE_LEN; } buf_size += closing_tag_size; svn_stringbuf_ensure(lockbuf, buf_size + 1); /* Now append all the temporary hash's keys and values into the stringbuf. This is better than doing apr_pstrcat() in a loop, because (1) there's no need to constantly re-alloc, and (2) the stringbuf already knows the end of the buffer, so there's no seek-time to the end of the string when appending. */ for (hi = apr_hash_first(tmppool, xml_locks); hi; hi = apr_hash_next(hi)) { const void *key; apr_ssize_t klen; void *val; apr_hash_this(hi, &key, &klen, &val); svn_stringbuf_appendcstr(lockbuf, SVN_LOCK); svn_stringbuf_appendcstr(lockbuf, SVN_LOCK_PATH); svn_stringbuf_appendbytes(lockbuf, key, klen); svn_stringbuf_appendcstr(lockbuf, SVN_LOCK_PATH_CLOSE); svn_stringbuf_appendcstr(lockbuf, SVN_LOCK_TOKEN); svn_stringbuf_appendcstr(lockbuf, val); svn_stringbuf_appendcstr(lockbuf, SVN_LOCK_TOKEN_CLOSE); svn_stringbuf_appendcstr(lockbuf, SVN_LOCK_CLOSE); } svn_stringbuf_appendcstr(lockbuf, closing_tag);#undef SVN_LOCK#undef SVN_LOCK_LEN#undef SVN_LOCK_CLOSE#undef SVN_LOCK_CLOSE_LEN#undef SVN_LOCK_PATH#undef SVN_LOCK_PATH_LEN#undef SVN_LOCK_PATH_CLOSE#undef SVN_LOCK_PATH_CLOSE_LEN#undef SVN_LOCK_TOKEN#undef SVN_LOCK_TOKEN_LEN#undef SVN_LOCK_TOKEN_CLOSE#undef SVN_LOCK_TOKEN_CLOSE_LEN *body = lockbuf; svn_pool_destroy(tmppool); return SVN_NO_ERROR;}svn_error_t * svn_ra_dav__merge_activity( svn_revnum_t *new_rev, const char **committed_date, const char **committed_author, const char **post_commit_err, svn_ra_dav__session_t *ras, const char *repos_url, const char *activity_url, apr_hash_t *valid_targets, apr_hash_t *lock_tokens, svn_boolean_t keep_locks, svn_boolean_t disable_merge_response, apr_pool_t *pool){ merge_ctx_t mc = { 0 }; const char *body; apr_hash_t *extra_headers = NULL; svn_stringbuf_t *lockbuf = svn_stringbuf_create("", pool); svn_error_t *err; mc.pool = pool; mc.scratchpool = svn_pool_create(pool); mc.base_href = repos_url; mc.base_len = strlen(repos_url); mc.rev = SVN_INVALID_REVNUM; mc.valid_targets = valid_targets; mc.push_prop = ras->callbacks->push_wc_prop; mc.cb_baton = ras->callback_baton; mc.href = MAKE_BUFFER(pool); mc.vsn_name = MAKE_BUFFER(pool); mc.vsn_url = MAKE_BUFFER(pool); mc.committed_date = MAKE_BUFFER(pool); mc.last_author = MAKE_BUFFER(pool); if (post_commit_err) mc.post_commit_err = MAKE_BUFFER(pool); if (disable_merge_response || (! keep_locks)) { const char *value; value = apr_psprintf(pool, "%s %s", disable_merge_response ? SVN_DAV_OPTION_NO_MERGE_RESPONSE : "", keep_locks ? "" : SVN_DAV_OPTION_RELEASE_LOCKS); if (! extra_headers) extra_headers = apr_hash_make(pool); apr_hash_set(extra_headers, SVN_DAV_OPTIONS_HEADER, APR_HASH_KEY_STRING, value); } /* Need to marshal the whole [path->token] hash to the server as a string within the body of the MERGE request. */ if ((lock_tokens != NULL) && (apr_hash_count(lock_tokens) > 0)) SVN_ERR(svn_ra_dav__assemble_locktoken_body(&lockbuf, lock_tokens, pool)); body = apr_psprintf(pool, "<?xml version=\"1.0\" encoding=\"utf-8\"?>" "<D:merge xmlns:D=\"DAV:\">" "<D:source><D:href>%s</D:href></D:source>" "<D:no-auto-merge/><D:no-checkout/>" "<D:prop>" "<D:checked-in/><D:version-name/><D:resourcetype/>" "<D:creationdate/><D:creator-displayname/>" "</D:prop>" "%s" "</D:merge>", activity_url, lockbuf->data); err = svn_ra_dav__parsed_request_compat(ras->sess, "MERGE", repos_url, body, 0, NULL, merge_elements, validate_element, start_element, end_element, &mc, extra_headers, NULL, FALSE, pool); /* is there an error stashed away in our context? */ if (mc.err) { if (err) svn_error_clear(err); return mc.err; } else if (err) return err; /* return some commit properties to the caller. */ if (new_rev) *new_rev = mc.rev; if (committed_date) *committed_date = mc.committed_date->len ? apr_pstrdup(pool, mc.committed_date->data) : NULL; if (committed_author) *committed_author = mc.last_author->len ? apr_pstrdup(pool, mc.last_author->data) : NULL; if (post_commit_err) *post_commit_err = mc.post_commit_err->len ? apr_pstrdup(pool, mc.post_commit_err->data) : NULL; svn_pool_destroy(mc.scratchpool); return NULL;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -