📄 props.c
字号:
/* And of course, delete the temporary reject file. */ SVN_ERR(svn_wc__loggy_remove(entry_accum, adm_access, reject_tmp_path, pool)); /* Mark entry as "conflicted" with a particular .prej file. */ { svn_wc_entry_t entry; entry.prejfile = reject_path; SVN_ERR(svn_wc__loggy_entry_modify(entry_accum, adm_access, entryname, &entry, SVN_WC__ENTRY_MODIFY_PREJFILE, pool)); } } /* if (reject_tmp_fp) */ return SVN_NO_ERROR;}/* This is DEPRECATED, use svn_wc_merge_props() instead. */svn_error_t *svn_wc_merge_prop_diffs(svn_wc_notify_state_t *state, const char *path, svn_wc_adm_access_t *adm_access, const apr_array_header_t *propchanges, svn_boolean_t base_merge, svn_boolean_t dry_run, apr_pool_t *pool){ /* NOTE: Here, we use implementation knowledge. The public svn_wc_merge_props doesn't allow NULL as baseprops argument, but we know that it works. */ return svn_wc_merge_props(state, path, adm_access, NULL, propchanges, base_merge, dry_run, pool);}/*------------------------------------------------------------------*//*** Private 'wc prop' functions ***//* If wcprops are stored in a single file in this working copy, read that file and store it in the cache of ADM_ACCESS. Use POOL for temporary allocations. */static svn_error_t *read_wcprops(svn_wc_adm_access_t *adm_access, apr_pool_t *pool){ apr_file_t *file; apr_pool_t *cache_pool = svn_wc_adm_access_pool(adm_access); apr_hash_t *all_wcprops; apr_hash_t *proplist; svn_stream_t *stream; svn_error_t *err; /* If the WC format is too old, there is nothing to cache. */ if (svn_wc__adm_wc_format(adm_access) <= SVN_WC__WCPROPS_MANY_FILES_VERSION) return SVN_NO_ERROR; all_wcprops = apr_hash_make(cache_pool); err = svn_wc__open_adm_file(&file, svn_wc_adm_access_path(adm_access), SVN_WC__ADM_ALL_WCPROPS, APR_READ | APR_BUFFERED, pool); /* A non-existent file means there are no props. */ if (err && APR_STATUS_IS_ENOENT(err->apr_err)) { svn_error_clear(err); svn_wc__adm_access_set_wcprops(adm_access, all_wcprops); return SVN_NO_ERROR; } SVN_ERR(err); stream = svn_stream_from_aprfile2(file, TRUE, pool); /* Read the proplist for THIS_DIR. */ proplist = apr_hash_make(cache_pool); SVN_ERR(svn_hash_read2(proplist, stream, SVN_HASH_TERMINATOR, cache_pool)); apr_hash_set(all_wcprops, SVN_WC_ENTRY_THIS_DIR, APR_HASH_KEY_STRING, proplist); /* And now, the children. */ while (1729) { svn_stringbuf_t *line; svn_boolean_t eof; SVN_ERR(svn_stream_readline(stream, &line, "\n", &eof, cache_pool)); if (eof) { if (line->len > 0) return svn_error_createf (SVN_ERR_WC_CORRUPT, NULL, _("Missing end of line in wcprops file for '%s'"), svn_path_local_style(svn_wc_adm_access_path(adm_access), pool)); break; } proplist = apr_hash_make(cache_pool); SVN_ERR(svn_hash_read2(proplist, stream, SVN_HASH_TERMINATOR, cache_pool)); apr_hash_set(all_wcprops, line->data, APR_HASH_KEY_STRING, proplist); } svn_wc__adm_access_set_wcprops(adm_access, all_wcprops); SVN_ERR(svn_wc__close_adm_file(file, svn_wc_adm_access_path(adm_access), SVN_WC__ADM_ALL_WCPROPS, FALSE, pool)); return SVN_NO_ERROR;}svn_error_t *svn_wc__wcprops_write(svn_wc_adm_access_t *adm_access, apr_pool_t *pool){ apr_hash_t *wcprops = svn_wc__adm_access_wcprops(adm_access); apr_file_t *file; svn_stream_t *stream; apr_hash_t *proplist; apr_hash_index_t *hi; apr_pool_t *subpool = svn_pool_create(pool); svn_boolean_t any_props = FALSE; /* If there are no cached wcprops, there is nothing to do. */ if (! wcprops) return SVN_NO_ERROR; /* Check if there are any properties at all. */ for (hi = apr_hash_first(pool, wcprops); hi && ! any_props; hi = apr_hash_next(hi)) { const void *key; void *val; apr_hash_this(hi, &key, NULL, &val); proplist = val; if (apr_hash_count(proplist) > 0) any_props = TRUE; } /* If there are no props, remove the file. */ if (! any_props) { svn_error_t *err; err = svn_wc__remove_adm_file(svn_wc_adm_access_path(adm_access), pool, SVN_WC__ADM_ALL_WCPROPS, NULL); if (err && APR_STATUS_IS_ENOENT(err->apr_err)) { svn_error_clear(err); return SVN_NO_ERROR; } else return err; } SVN_ERR(svn_wc__open_adm_file(&file, svn_wc_adm_access_path(adm_access), SVN_WC__ADM_ALL_WCPROPS, APR_WRITE | APR_BUFFERED, pool)); stream = svn_stream_from_aprfile2(file, TRUE, pool); /* First, the props for this_dir. */ proplist = apr_hash_get(wcprops, SVN_WC_ENTRY_THIS_DIR, APR_HASH_KEY_STRING); if (! proplist) proplist = apr_hash_make(subpool); SVN_ERR(svn_hash_write2(proplist, stream, SVN_HASH_TERMINATOR, subpool)); /* Write children. */ for (hi = apr_hash_first(pool, wcprops); hi; hi = apr_hash_next(hi)) { const void *key; void *val; const char *name; apr_hash_this(hi, &key, NULL, &val); name = key; proplist = val; /* We already wrote this_dir, and writing empty hashes makes me feel silly... */ if (strcmp(SVN_WC_ENTRY_THIS_DIR, name) == 0 || apr_hash_count(proplist) == 0) continue; svn_pool_clear(subpool); svn_stream_printf(stream, subpool, "%s\n", name); SVN_ERR(svn_hash_write2(proplist, stream, SVN_HASH_TERMINATOR, subpool)); } SVN_ERR(svn_wc__close_adm_file(file, svn_wc_adm_access_path(adm_access), SVN_WC__ADM_ALL_WCPROPS, TRUE, pool)); return SVN_NO_ERROR;}svn_error_t *svn_wc__wcprop_list(apr_hash_t **wcprops, const char *entryname, svn_wc_adm_access_t *adm_access, apr_pool_t *pool){ const char *prop_path; const svn_wc_entry_t *entry; apr_hash_t *all_wcprops; apr_pool_t *cache_pool = svn_wc_adm_access_pool(adm_access); const char *path = svn_path_join(svn_wc_adm_access_path(adm_access), entryname, pool); SVN_ERR(svn_wc_entry(&entry, path, adm_access, FALSE, pool)); if (! entry) { /* No entry exists, therefore no wcprop-file can exist */ *wcprops = apr_hash_make(pool); return SVN_NO_ERROR; } /* Try the cache first. */ all_wcprops = svn_wc__adm_access_wcprops(adm_access); if (! all_wcprops) { SVN_ERR(read_wcprops(adm_access, pool)); all_wcprops = svn_wc__adm_access_wcprops(adm_access); } if (all_wcprops) { *wcprops = apr_hash_get(all_wcprops, entryname, APR_HASH_KEY_STRING); /* The cache contains no hash tables for empty proplist, so we just create one here if that's the case. */ if (! *wcprops) { *wcprops = apr_hash_make(cache_pool); entryname = apr_pstrdup(cache_pool, entryname); apr_hash_set(all_wcprops, entryname, APR_HASH_KEY_STRING, *wcprops); } return SVN_NO_ERROR; } /* Fall back on individual files for backwards compatibility. */ /* Construct a path to the relevant property file */ SVN_ERR(svn_wc__wcprop_path(&prop_path, path, entry->kind, FALSE, pool)); *wcprops = apr_hash_make(pool); SVN_ERR(svn_wc__load_prop_file(prop_path, *wcprops, pool)); return SVN_NO_ERROR;}/* Get a single 'wcprop' NAME for versioned object PATH, return in *VALUE. ADM_ACCESS is an access baton set that contains PATH. */static svn_error_t *wcprop_get(const svn_string_t **value, const char *name, const char *path, svn_wc_adm_access_t *adm_access, apr_pool_t *pool){ svn_error_t *err; apr_hash_t *prophash; const svn_wc_entry_t *entry; SVN_ERR(svn_wc_entry(&entry, path, adm_access, FALSE, pool)); if (! entry) { *value = NULL; return SVN_NO_ERROR; } if (entry->kind == svn_node_dir) SVN_ERR(svn_wc_adm_retrieve(&adm_access, adm_access, path, pool)); else SVN_ERR(svn_wc_adm_retrieve(&adm_access, adm_access, svn_path_dirname(path, pool), pool)); err = svn_wc__wcprop_list(&prophash, entry->name, adm_access, pool); if (err) return svn_error_quick_wrap (err, _("Failed to load properties from disk")); *value = apr_hash_get(prophash, name, APR_HASH_KEY_STRING); return SVN_NO_ERROR;}svn_error_t *svn_wc__wcprop_set(const char *name, const svn_string_t *value, const char *path, svn_wc_adm_access_t *adm_access, svn_boolean_t force_write, apr_pool_t *pool){ svn_error_t *err; apr_hash_t *prophash; apr_file_t *fp = NULL; apr_pool_t *cache_pool = svn_wc_adm_access_pool(adm_access); const svn_wc_entry_t *entry; SVN_ERR(svn_wc_entry(&entry, path, adm_access, FALSE, pool)); if (! entry) return svn_error_createf(SVN_ERR_UNVERSIONED_RESOURCE, NULL, _("'%s' is not under version control"), svn_path_local_style(path, pool)); if (entry->kind == svn_node_dir) SVN_ERR(svn_wc_adm_retrieve(&adm_access, adm_access, path, pool)); else SVN_ERR(svn_wc_adm_retrieve(&adm_access, adm_access, svn_path_dirname(path, pool), pool)); err = svn_wc__wcprop_list(&prophash, entry->name, adm_access, pool); if (err) return svn_error_quick_wrap (err, _("Failed to load properties from disk")); /* Now we have all the properties in our hash. Simply merge the new property into it. */ name = apr_pstrdup(cache_pool, name); if (value) value = svn_string_dup(value, cache_pool); apr_hash_set(prophash, name, APR_HASH_KEY_STRING, value); if (svn_wc__adm_wc_format(adm_access) > SVN_WC__WCPROPS_MANY_FILES_VERSION) { if (force_write) SVN_ERR(svn_wc__wcprops_write(adm_access, pool)); } else { /* For backwards compatibility. We don't use the cache in this case, so write to disk regardless of force_write. */ /* Open the propfile for writing. */ SVN_ERR(svn_wc__open_props(&fp, path, /* open in PATH */ (APR_WRITE | APR_CREATE | APR_BUFFERED), 0, /* not base props */ 1, /* we DO want wcprops */ pool)); /* Write. */ SVN_ERR_W(svn_hash_write(prophash, fp, pool), apr_psprintf(pool, _("Cannot write property hash for '%s'"), svn_path_local_style(path, pool))); /* Close file, doing an atomic "move". */ SVN_ERR(svn_wc__close_props(fp, path, 0, 1, 1, /* sync! */ pool)); } return SVN_NO_ERROR;}svn_error_t *svn_wc__remove_wcprops(svn_wc_adm_access_t *adm_access, const char *name, svn_boolean_t recurse, apr_pool_t *pool){ apr_hash_t *all_wcprops = svn_wc__adm_access_wcprops(adm_access); svn_boolean_t write_needed = FALSE; if (! name) { /* There is no point in reading the props just to determine if we need to rewrite them:-), so assume a write is needed if the props aren't already cached. */ if (! all_wcprops || apr_hash_count(all_wcprops) > 0) { svn_wc__adm_access_set_wcprops (adm_access, apr_hash_make(svn_wc_adm_access_pool(adm_access))); write_needed = TRUE; } } else { apr_hash_t *wcprops; if (! all_wcprops) { SVN_ERR(read_wcprops(adm_access, pool)); all_wcprops = svn_wc__adm_access_wcprops(adm_access); } if (all_wcprops) wcprops = apr_hash_get(all_wcprops, name, APR_HASH_KEY_STRING);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -