[WIP PATCH 6/7] Add file_baton and trigger dump_node in change_file_prop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add a file_baton structure, and fill it in in open_file and add_file
functions. It is to be used by apply_textdelta and change_file_prop
functions. Trigger dump_node in change_file_prop. Dump the actual
properties along with the property lengths.

Signed-off-by: Ramkumar Ramachandra <artagnon@xxxxxxxxx>
---
 dump_editor.c |  100 ++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 89 insertions(+), 11 deletions(-)

diff --git a/dump_editor.c b/dump_editor.c
index a80d711..7bd00a4 100644
--- a/dump_editor.c
+++ b/dump_editor.c
@@ -15,7 +15,6 @@
 
 #define ARE_VALID_COPY_ARGS(p,r) ((p) && SVN_IS_VALID_REVNUM(r))
 
-static svn_boolean_t must_dump_text = FALSE, must_dump_props = FALSE;
 static svn_boolean_t text_changed = FALSE, props_changed = FALSE;
 
 struct edit_baton {
@@ -66,9 +65,16 @@ struct dir_baton {
 	apr_pool_t *pool;
 };
 
+struct file_baton {
+	/* Store the path of the file */
+	const char *path;
+	struct edit_baton *eb;
+};
+
 static void write_hash_to_stringbuf(apr_hash_t *hash,
                                     svn_stringbuf_t **strbuf,
-                                    apr_pool_t *pool) {
+                                    apr_pool_t *pool)
+{
 	apr_hash_index_t *this;
 	*strbuf = svn_stringbuf_create("", pool);
 
@@ -120,7 +126,8 @@ struct dir_baton *make_dir_baton(const char *path,
                                  void *edit_baton,
                                  void *parent_dir_baton,
                                  svn_boolean_t added,
-                                 apr_pool_t *pool) {
+                                 apr_pool_t *pool)
+{
 	struct edit_baton *eb = edit_baton;
 	struct dir_baton *pb = parent_dir_baton;
 	struct dir_baton *new_db = apr_pcalloc(pool, sizeof(*new_db));
@@ -156,6 +163,18 @@ struct dir_baton *make_dir_baton(const char *path,
 	return new_db;
 }
 
+struct file_baton *make_file_baton(struct edit_baton *eb,
+                                   const char *path,
+                                   apr_pool_t *pool)
+{
+	struct file_baton *new_fb = apr_pcalloc(pool, sizeof(struct file_baton));
+	new_fb->path = apr_pcalloc(pool, sizeof(const char *));
+	new_fb->path = path;
+	new_fb->eb = eb;
+
+	return new_fb;
+}
+
 static svn_error_t *dump_node(struct edit_baton *eb,
                               const char *path,    /* an absolute path. */
                               svn_node_kind_t kind,
@@ -170,6 +189,7 @@ static svn_error_t *dump_node(struct edit_baton *eb,
 	svn_revnum_t compare_rev = eb->current_rev - 1;
 	svn_stringbuf_t *propstring;
 	svn_filesize_t content_length = 0;
+	svn_boolean_t must_dump_text = FALSE, must_dump_props = FALSE;
 
 	/* Write out metadata headers for this file node. */
 	SVN_ERR(svn_stream_printf(eb->stream, pool,
@@ -310,10 +330,44 @@ static svn_error_t *dump_node(struct edit_baton *eb,
 		                          SVN_REPOS_DUMPFILE_PROP_CONTENT_LENGTH
 		                          ": %" APR_SIZE_T_FMT "\n", proplen));
 	}
+
+	/* If we are supposed to dump text, write out a text length header
+	   here, and an MD5 checksum (if available). */
 	if (must_dump_text && (kind == svn_node_file)) {
-		/* svn_stream_t *contents; */
 		;
 	}
+
+	/* 'Content-length:' is the last header before we dump the content,
+	   and is the sum of the text and prop contents lengths.  We write
+	   this only for the benefit of non-Subversion RFC-822 parsers. */
+	SVN_ERR(svn_stream_printf(eb->stream, pool,
+	                          SVN_REPOS_DUMPFILE_CONTENT_LENGTH
+	                          ": %" SVN_FILESIZE_T_FMT "\n\n",
+	                          content_length));
+
+	/* Now dump the text and properties */
+	if (must_dump_props)
+	{
+		len = propstring->len;
+		SVN_ERR(svn_stream_write(eb->stream, propstring->data, &len));
+	}
+	/* if (must_dump_text && (kind == svn_node_file)) */
+	/* { */
+	/* 	svn_stream_t *contents; */
+
+	/* 	if (delta_file) */
+	/* 	{ */
+	/* 		/\* Make sure to close the underlying file when the stream is */
+	/* 		   closed. *\/ */
+	/* 		contents = svn_stream_from_aprfile2(delta_file, FALSE, pool); */
+	/* 	} */
+	/* 	else */
+	/* 		SVN_ERR(svn_fs_file_contents(&contents, eb->fs_root, path, pool)); */
+
+	/* 	SVN_ERR(svn_stream_copy3(contents, svn_stream_disown(eb->stream, pool), */
+	/* 	                         NULL, NULL, pool)); */
+	/* } */
+
 	return SVN_NO_ERROR;
 }
 svn_error_t *open_root(void *edit_baton,
@@ -467,12 +521,12 @@ svn_error_t *add_file(const char *path,
 		/* delete the path, it's now been dumped. */
 		apr_hash_set(pb->deleted_entries, path, APR_HASH_KEY_STRING, NULL);
 
-	/* TODO: Store the delta in file_baton */
-	*file_baton = NULL;
+	/* Build a nice file baton to pass to change_file_prop and apply_textdelta */
+	*file_baton = make_file_baton(eb, path, pool);
+
 	return SVN_NO_ERROR;
 }
 
-
 svn_error_t *open_file(const char *path,
                        void *parent_baton,
                        svn_revnum_t ancestor_revision,
@@ -497,9 +551,10 @@ svn_error_t *open_file(const char *path,
 	SVN_ERR(dump_node(eb, path,
 	                  svn_node_file, svn_node_action_change,
 	                  FALSE, cmp_path, cmp_rev, pool));
-
-	/* TODO: Store the delta in file_baton */
-	*file_baton = NULL;
+	
+	/* Build a nice file baton to pass to change_file_prop and apply_textdelta */
+	*file_baton = make_file_baton(eb, path, pool);
+	
 	return SVN_NO_ERROR;
 }
 
@@ -532,6 +587,29 @@ svn_error_t *change_dir_prop(void *parent_baton,
 	return SVN_NO_ERROR;
 }
 
+svn_error_t *change_file_prop(void *file_baton,
+                              const char *name,
+                              const svn_string_t *value,
+                              apr_pool_t *pool)
+{
+	struct file_baton *fb = file_baton;
+	
+	if (svn_property_kind(NULL, name) != svn_prop_regular_kind)
+		return SVN_NO_ERROR;
+
+	value ? apr_hash_set(fb->eb->properties, apr_pstrdup(pool, name),
+	                     APR_HASH_KEY_STRING, svn_string_dup(value, pool)) :
+		apr_hash_set(fb->eb->del_properties, apr_pstrdup(pool, name),
+		             APR_HASH_KEY_STRING, (void *)0x1);
+	props_changed = TRUE;
+	
+	SVN_ERR(dump_node(fb->eb, fb->path,
+	                  svn_node_dir, svn_node_action_change,
+	                  FALSE, NULL, 0, pool));
+
+	return SVN_NO_ERROR;
+}
+
 svn_error_t *get_dump_editor(const svn_delta_editor_t **editor,
                              void **edit_baton,
                              svn_revnum_t to_rev,
@@ -545,7 +623,6 @@ svn_error_t *get_dump_editor(const svn_delta_editor_t **editor,
 	eb->current_rev = to_rev;
 	eb->properties = apr_hash_make(pool);
 	eb->del_properties = apr_hash_make(pool);
-	eb->delta_text = apr_pcalloc(pool, sizeof(const char *));
 
 	dump_editor->open_root = open_root;
 	dump_editor->delete_entry = delete_entry;
@@ -553,6 +630,7 @@ svn_error_t *get_dump_editor(const svn_delta_editor_t **editor,
 	dump_editor->open_directory = open_directory;
 	dump_editor->close_directory = close_directory;
 	dump_editor->change_dir_prop = change_dir_prop;
+	dump_editor->change_file_prop = change_file_prop;	
 	dump_editor->add_file = add_file;
 	dump_editor->open_file = open_file;
 
-- 
1.7.1

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]