git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 07/13] Implement open_root and close_edit

From
Ramkumar Ramachandra <artagnon@gmail.com>
Date
Jul 7, 2010, 00:14 UTC
Message-ID
<1278461693-3828-8-git-send-email-artagnon@gmail.com>
In-Reply-To
<1278461693-3828-1-git-send-email-artagnon@gmail.com>

open_root first creates a special edit_baton pool, and then allocates memory from that pool to various items in edit_baton. Then it creates a new directory baton to set as the root_baton. close_edit destroys the special edit_baton pool (hence destroying all the items that were allocated there), and increments current_rev. Add related make_dir_baton function and dir_baton_t structure.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 dump_editor.c |   70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 dumpr_util.h  |   30 ++++++++++++++++++++++++
 2 files changed, 100 insertions(+), 0 deletions(-)
diff --git a/dump_editor.c b/dump_editor.c
index 70d6c0b..6e9b0f5 100644
--- a/dump_editor.c
+++ b/dump_editor.c
@@ -15,11 +15,77 @@
 
 #include "dumpr_util.h"
 
+
+/* Make a directory baton to represent the directory was path
+   (relative to EDIT_BATON's path) is PATH.
+
+   CMP_PATH/CMP_REV are the path/revision against which this directory
+   should be compared for changes.  If either is omitted (NULL for the
+   path, SVN_INVALID_REVNUM for the rev), just compare this directory
+   PATH against itself in the previous revision.
+
+   PARENT_DIR_BATON is the directory baton of this directory's parent,
+   or NULL if this is the top-level directory of the edit.  ADDED
+   indicated if this directory is newly added in this revision.
+   Perform all allocations in POOL.  */
+struct dir_baton *make_dir_baton(const char *path,
+                                 const char *cmp_path,
+                                 svn_revnum_t cmp_rev,
+                                 void *edit_baton,
+                                 void *parent_dir_baton,
+                                 svn_boolean_t added,
+                                 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));
+	const char *full_path;
+	apr_array_header_t *compose_path = apr_array_make(pool, 2, sizeof(const char *));
+
+	/* A path relative to nothing?  I don't think so. */
+	SVN_ERR_ASSERT_NO_RETURN(!path || pb);
+
+	/* Construct the full path of this node. */
+	if (pb) {
+		APR_ARRAY_PUSH(compose_path, const char *) = "/";
+		APR_ARRAY_PUSH(compose_path, const char *) = path;
+		full_path = svn_path_compose(compose_path, pool);
+	}
+	else
+		full_path = apr_pstrdup(pool, "/");
+
+	/* Remove leading slashes from copyfrom paths. */
+	if (cmp_path)
+		cmp_path = ((*cmp_path == '/') ? cmp_path + 1 : cmp_path);
+
+	new_db->eb = eb;
+	new_db->parent_dir_baton = pb;
+	new_db->path = full_path;
+	new_db->cmp_path = cmp_path ? apr_pstrdup(pool, cmp_path) : NULL;
+	new_db->cmp_rev = cmp_rev;
+	new_db->added = added;
+	new_db->written_out = FALSE;
+	new_db->deleted_entries = apr_hash_make(pool);
+	new_db->pool = pool;
+
+	return new_db;
+}
 svn_error_t *open_root(void *edit_baton,
                        svn_revnum_t base_revision,
                        apr_pool_t *pool,
                        void **root_baton)
 {
+	/* Allocate a special pool for the edit_baton to avoid pool
+	   lifetime issues */
+	struct edit_baton *eb = edit_baton;
+	eb->pool = svn_pool_create(pool);
+	eb->properties = apr_hash_make(eb->pool);
+	eb->del_properties = apr_hash_make(eb->pool);
+	eb->propstring = svn_stringbuf_create("", eb->pool);
+	eb->is_copy = FALSE;
+
+	*root_baton = make_dir_baton(NULL, NULL, SVN_INVALID_REVNUM,
+	                             edit_baton, NULL, FALSE, pool);
 	return SVN_NO_ERROR;
 }
 
@@ -108,6 +174,10 @@ svn_error_t *close_file(void *file_baton,
 
 svn_error_t *close_edit(void *edit_baton, apr_pool_t *pool)
 {
+	struct edit_baton *eb = edit_baton;
+	svn_pool_destroy(eb->pool);
+	(eb->current_rev) ++;
+
 	return SVN_NO_ERROR;
 }
 
diff --git a/dumpr_util.h b/dumpr_util.h
index 1a5752b..96670ff 100644
--- a/dumpr_util.h
+++ b/dumpr_util.h
@@ -31,6 +31,36 @@ struct edit_baton {
 	svn_checksum_t *checksum;
 };
 
+struct dir_baton {
+	struct edit_baton *eb;
+	struct dir_baton *parent_dir_baton;
+
+	/* is this directory a new addition to this revision? */
+	svn_boolean_t added;
+
+	/* has this directory been written to the output stream? */
+	svn_boolean_t written_out;
+
+	/* the absolute path to this directory */
+	const char *path;
+
+	/* the comparison path and revision of this directory.  if both of
+	   these are valid, use them as a source against which to compare
+	   the directory instead of the default comparison source of PATH in
+	   the previous revision. */
+	const char *cmp_path;
+	svn_revnum_t cmp_rev;
+
+	/* hash of paths that need to be deleted, though some -might- be
+	   replaced.  maps const char * paths to this dir_baton.  (they're
+	   full paths, because that's what the editor driver gives us.  but
+	   really, they're all within this directory.) */
+	apr_hash_t *deleted_entries;
+
+	/* pool to be used for deleting the hash items */
+	apr_pool_t *pool;
+};
+
 void write_hash_to_stringbuf(apr_hash_t *properties,
 			     svn_boolean_t deleted,
 			     svn_stringbuf_t **strbuf,
-- 
1.7.1
Previous: Ramkumar RamachandraNext: Ramkumar Ramachandra
Message 24 of 31 in “[GSoC update] git-remote-svn: Week 10”
  1. Ramkumar RamachandraJul 7, 2010
  2. 01/13 Add LICENSERamkumar Ramachandra, Jul 7, 2010
  3. 02/13 Add skeleton SVN client and MakefileRamkumar Ramachandra, Jul 7, 2010
  4. Jonathan NiederJul 7, 2010
  5. Ramkumar RamachandraJul 7, 2010
  6. Jonathan NiederJul 7, 2010
  7. Ramkumar RamachandraJul 7, 2010
  8. Daniel ShahafJul 7, 2010
  9. 03/13 Add debug editor from Subversion trunkRamkumar Ramachandra, Jul 7, 2010
  10. Jonathan NiederJul 7, 2010
  11. 04/13 Add skeleton dump editorRamkumar Ramachandra, Jul 7, 2010
  12. Jonathan NiederJul 7, 2010
  13. Ramkumar RamachandraJul 8, 2010
  14. 05/13 Drive the debug editorRamkumar Ramachandra, Jul 7, 2010
  15. Jonathan NiederJul 7, 2010
  16. Ramkumar RamachandraJul 7, 2010
  17. Jonathan NiederJul 7, 2010
  18. Ramkumar RamachandraJul 8, 2010
  19. 06/13 Dump the revprops at the start of every revisionRamkumar Ramachandra, Jul 7, 2010
  20. Jonathan NiederJul 7, 2010
  21. Ramkumar RamachandraJul 21, 2010
  22. Julian FoadJul 26, 2010
  23. Ramkumar RamachandraJul 26, 2010
  24. 07/13 Implement open_root and close_editRamkumar Ramachandra, Jul 7, 2010
  25. 08/13 Implement dump_nodeRamkumar Ramachandra, Jul 7, 2010
  26. 09/13 Implement directory-related functionsRamkumar Ramachandra, Jul 7, 2010
  27. 10/13 Implement file-related functionsRamkumar Ramachandra, Jul 7, 2010
  28. 11/13 Implement apply_textdeltaRamkumar Ramachandra, Jul 7, 2010
  29. 12/13 Implement close_fileRamkumar Ramachandra, Jul 7, 2010
  30. 13/13 Add a validation scriptRamkumar Ramachandra, Jul 7, 2010
  31. Ramkumar RamachandraJul 7, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.