You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Garrett Rooney <ro...@electricjellyfish.net> on 2002/02/25 02:01:39 UTC
[PATCH] partial fix for issue 571
Here's a patch that fixes half of issue 571. The issue is about
printing out notification that a file has been replaced, rather than
having a notification that it was deleted followed by a notification
that the same file was added. This patch fixes it for commit, and if
people think this is the right approach, I'll do something similar for
update.
-garrett
Index: ./subversion/clients/cmdline/trace-commit.c
===================================================================
--- ./subversion/clients/cmdline/trace-commit.c
+++ ./subversion/clients/cmdline/trace-commit.c Sun Feb 24 20:46:35 2002
@@ -44,6 +44,22 @@
};
+/* When we add and delete files, we don't immediately print out that info,
+ because if a file is both added and deleted, we want to say it was
+ replaced. So instead, we have 2 hashes in the dir baton, one for adds
+ and one for deletes. For deletes, the key is all that matters, since
+ we just need to know the entity's name. For adds, the val is used to
+ tell us if the file was binary or not. (We use the pointer as a flag,
+ it doesn't actually point to anything) We can't just store the value of
+ the file's binary flag, because FALSE is equal to NULL, and that means
+ 'erase this entry' in apr_hash_set. So instead we use this enum. */
+enum file_type
+{
+ binary = 1,
+ text = 2
+};
+
+
struct dir_baton
{
struct edit_baton *edit_baton;
@@ -51,6 +67,8 @@
svn_stringbuf_t *path;
svn_boolean_t added;
svn_boolean_t prop_changed;
+ apr_hash_t *entries_added;
+ apr_hash_t *entries_deleted;
apr_pool_t *subpool;
int ref_count;
};
@@ -80,6 +98,34 @@
if (db->ref_count == 0)
{
struct dir_baton *dbparent = db->parent_dir_baton;
+ apr_hash_index_t *hi;
+ const void *key;
+ void *val;
+
+ for (hi = apr_hash_first(db->subpool, db->entries_added);
+ hi;
+ hi = apr_hash_next(hi))
+ {
+ apr_hash_this(hi, &key, NULL, &val);
+ if (apr_hash_get(db->entries_deleted, key, APR_HASH_KEY_STRING)
+ != NULL)
+ {
+ printf("Replacing %s\n", (const char *)key);
+ apr_hash_set(db->entries_deleted, key, APR_HASH_KEY_STRING, NULL);
+ }
+ else
+ printf("Adding %s %s\n",
+ ((enum file_type)val) == binary ? "(bin)" : " ",
+ (const char *)key);
+ }
+
+ for (hi = apr_hash_first(db->subpool, db->entries_deleted);
+ hi;
+ hi = apr_hash_next(hi))
+ {
+ apr_hash_this(hi, &key, NULL, NULL);
+ printf("Deleting %s\n", (const char *)key);
+ }
/* Destroy all memory used by this baton, including the baton
itself! */
@@ -107,6 +153,9 @@
rb->subpool = subpool;
rb->ref_count = 1;
+ rb->entries_added = apr_hash_make(subpool);
+ rb->entries_deleted = apr_hash_make(subpool);
+
*root_baton = rb;
return SVN_NO_ERROR;
@@ -122,7 +171,9 @@
svn_path_add_component (printable_name, name);
- printf ("Deleting %s\n", printable_name->data);
+ apr_hash_set(d->entries_deleted, printable_name->data, APR_HASH_KEY_STRING,
+ printable_name->data);
+
return SVN_NO_ERROR;
}
@@ -150,7 +201,12 @@
child_d->ref_count = 1;
parent_d->ref_count++;
- printf ("Adding %s\n", child_d->path->data);
+ child_d->entries_added = apr_hash_make(subpool);
+ child_d->entries_deleted = apr_hash_make(subpool);
+
+ apr_hash_set(parent_d->entries_added, child_d->path->data,
+ APR_HASH_KEY_STRING, child_d->path->data);
+
*child_baton = child_d;
return SVN_NO_ERROR;
@@ -178,6 +234,9 @@
child_d->ref_count = 1;
parent_d->ref_count++;
+ child_d->entries_added = apr_hash_make(subpool);
+ child_d->entries_deleted = apr_hash_make(subpool);
+
*child_baton = child_d;
/* Don't print anything for a directory open -- this event is
@@ -206,9 +265,9 @@
struct file_baton *fb = file_baton;
if (fb->added)
- printf ("Adding %s %s\n",
- fb->binary ? "(bin)" : " ",
- fb->path->data);
+ apr_hash_set(fb->parent_dir_baton->entries_added, fb->path->data,
+ APR_HASH_KEY_STRING,
+ fb->binary ? (void *)binary : (void *)text);
else
printf ("Sending %s\n", fb->path->data);
--
garrett rooney Unix was not designed to stop you from
rooneg@electricjellyfish.net doing stupid things, because that would
http://electricjellyfish.net/ stop you from doing clever things.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Re: [PATCH] partial fix for issue 571
Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On Mon, Feb 25, 2002 at 09:56:13PM -0500, Garrett Rooney wrote:
> On Mon, Feb 25, 2002 at 05:59:47PM -0800, Greg Stein wrote:
> > [ most of this mentioned over IRC to Garrett, but he asked for it to be sent
> > to the list, so others can get the info, too :-) ]
>
> and here's the new version of the patch, with gstein's comments taken
> into account. note that it has one small problem, but i don't think
> it's with this patch. we never print out 'Replaced (bin)', since when
> we replace something, even if it is binary (and the svn add showed it
> was binary) when we see it in close_file() it never has the binary
> flag set on it. i haven't had a chance to debug this yet though, so
> if someone wants to take a look, feel free.
>
> again, if there are no more comments, i will commit today or tomorrow.
> even with the bug, it gets us closer to the desired functionality, and
> doesn't seem to hurt anything.
I just committed this in rev 1378, with one change. In a moment of
paranoia, I added a check to delete_entry to see if the entry is
already in the hash table and if so update it's status there if it is,
rather than overwriting it. This doesn't seem to happen (we always
seem to get add called, then delete, never the other way around), but
I couldn't find any documentation telling me it was garunteed to work
this way, so I figured better safe than sorry.
Next, on to trace-update.c, which seems like it will need to change to
look quite a bit more like trace-commit.c, since it will need to grow
ref counts to tell when the directory should be printed out.
-garrett
--
garrett rooney Unix was not designed to stop you from
rooneg@electricjellyfish.net doing stupid things, because that would
http://electricjellyfish.net/ stop you from doing clever things.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Re: [PATCH] partial fix for issue 571
Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On Mon, Feb 25, 2002 at 05:59:47PM -0800, Greg Stein wrote:
> [ most of this mentioned over IRC to Garrett, but he asked for it to be sent
> to the list, so others can get the info, too :-) ]
and here's the new version of the patch, with gstein's comments taken
into account. note that it has one small problem, but i don't think
it's with this patch. we never print out 'Replaced (bin)', since when
we replace something, even if it is binary (and the svn add showed it
was binary) when we see it in close_file() it never has the binary
flag set on it. i haven't had a chance to debug this yet though, so
if someone wants to take a look, feel free.
again, if there are no more comments, i will commit today or tomorrow.
even with the bug, it gets us closer to the desired functionality, and
doesn't seem to hurt anything.
-garrett
Index: ./subversion/clients/cmdline/trace-commit.c
===================================================================
--- ./subversion/clients/cmdline/trace-commit.c
+++ ./subversion/clients/cmdline/trace-commit.c Mon Feb 25 21:33:17 2002
@@ -27,6 +27,7 @@
#define APR_WANT_STDIO
#define APR_WANT_STRFUNC
#include <apr_want.h>
+#include <assert.h>
#include "svn_pools.h"
#include "svn_wc.h"
@@ -44,6 +45,19 @@
};
+static const int svn_cl__item_added = 0;
+static const int svn_cl__item_added_binary = 0;
+static const int svn_cl__item_deleted = 0;
+static const int svn_cl__item_replaced = 0;
+static const int svn_cl__item_replaced_binary = 0;
+
+#define ITEM_ADDED (&svn_cl__item_added)
+#define ITEM_ADDED_BINARY (&svn_cl__item_added_binary)
+#define ITEM_DELETED (&svn_cl__item_deleted)
+#define ITEM_REPLACED (&svn_cl__item_replaced)
+#define ITEM_REPLACED_BINARY (&svn_cl__item_replaced_binary)
+
+
struct dir_baton
{
struct edit_baton *edit_baton;
@@ -51,6 +65,7 @@
svn_stringbuf_t *path;
svn_boolean_t added;
svn_boolean_t prop_changed;
+ apr_hash_t *added_or_deleted;
apr_pool_t *subpool;
int ref_count;
};
@@ -80,6 +95,33 @@
if (db->ref_count == 0)
{
struct dir_baton *dbparent = db->parent_dir_baton;
+ apr_hash_index_t *hi;
+
+ for (hi = apr_hash_first (db->subpool, db->added_or_deleted);
+ hi;
+ hi = apr_hash_next (hi))
+ {
+ const char *pattern;
+ const void *key;
+ void *val;
+
+ apr_hash_this (hi, &key, NULL, &val);
+
+ if (val == ITEM_REPLACED)
+ pattern = "Replacing %s\n";
+ else if (val == ITEM_REPLACED_BINARY)
+ pattern = "Replacing (bin) %s\n";
+ else if (val == ITEM_DELETED)
+ pattern = "Deleting %s\n";
+ else if (val == ITEM_ADDED)
+ pattern = "Adding %s\n";
+ else if (val == ITEM_ADDED_BINARY)
+ pattern = "Adding (bin) %s\n";
+ else
+ assert(0); /* this should never happen */
+
+ printf (pattern, (const char *)key);
+ }
/* Destroy all memory used by this baton, including the baton
itself! */
@@ -107,6 +149,8 @@
rb->subpool = subpool;
rb->ref_count = 1;
+ rb->added_or_deleted = apr_hash_make (subpool);
+
*root_baton = rb;
return SVN_NO_ERROR;
@@ -122,7 +166,9 @@
svn_path_add_component (printable_name, name);
- printf ("Deleting %s\n", printable_name->data);
+ apr_hash_set (d->added_or_deleted, printable_name->data, printable_name->len,
+ ITEM_DELETED);
+
return SVN_NO_ERROR;
}
@@ -137,6 +183,7 @@
apr_pool_t *subpool;
struct dir_baton *parent_d = parent_baton;
struct dir_baton *child_d;
+ void *vp;
subpool = svn_pool_create (parent_d->edit_baton->pool);
child_d = apr_pcalloc (subpool, sizeof (*child_d));
@@ -150,7 +197,17 @@
child_d->ref_count = 1;
parent_d->ref_count++;
- printf ("Adding %s\n", child_d->path->data);
+ child_d->added_or_deleted = apr_hash_make (subpool);
+
+ vp = apr_hash_get (parent_d->added_or_deleted, child_d->path->data,
+ child_d->path->len);
+ if (vp == ITEM_DELETED)
+ apr_hash_set (parent_d->added_or_deleted, child_d->path->data,
+ child_d->path->len, ITEM_REPLACED);
+ else
+ apr_hash_set (parent_d->added_or_deleted, child_d->path->data,
+ child_d->path->len, ITEM_ADDED);
+
*child_baton = child_d;
return SVN_NO_ERROR;
@@ -178,6 +235,8 @@
child_d->ref_count = 1;
parent_d->ref_count++;
+ child_d->added_or_deleted = apr_hash_make (subpool);
+
*child_baton = child_d;
/* Don't print anything for a directory open -- this event is
@@ -206,9 +265,28 @@
struct file_baton *fb = file_baton;
if (fb->added)
- printf ("Adding %s %s\n",
- fb->binary ? "(bin)" : " ",
- fb->path->data);
+ {
+ void *vp = apr_hash_get (fb->parent_dir_baton->added_or_deleted,
+ fb->path->data, fb->path->len);
+ if (vp == NULL)
+ {
+ if (fb->binary)
+ vp = (void *)ITEM_ADDED_BINARY;
+ else
+ vp = (void *)ITEM_ADDED;
+ }
+ else
+ {
+ if (fb->binary)
+ vp = (void *)ITEM_REPLACED_BINARY;
+ else
+ vp = (void*)ITEM_REPLACED;
+ }
+
+ apr_hash_set (fb->parent_dir_baton->added_or_deleted,
+ fb->path->data, fb->path->len, vp);
+
+ }
else
printf ("Sending %s\n", fb->path->data);
--
garrett rooney Unix was not designed to stop you from
rooneg@electricjellyfish.net doing stupid things, because that would
http://electricjellyfish.net/ stop you from doing clever things.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Re: [PATCH] partial fix for issue 571
Posted by Greg Stein <gs...@lyra.org>.
[ most of this mentioned over IRC to Garrett, but he asked for it to be sent
to the list, so others can get the info, too :-) ]
On Mon, Feb 25, 2002 at 08:17:31PM -0500, Garrett Rooney wrote:
>...
> +++ ./subversion/clients/cmdline/trace-commit.c Mon Feb 25 19:57:47 2002
>...
> +enum status
> +{
> + added,
> + deleted,
> + replaced
> +};
Those are awfully generic symbols. Usually, it is best to have some kind of
prefix, even on module-private symbols.
> +struct entry_status
> +{
> + svn_boolean_t binary;
> + enum status status;
> +};
Using a structure means more headache and allocations. Two alternatives:
1) use an integer casted to/from a void*. use bitfields in the integer.
2) use singleton pointers for your five states
Garrett said he didn't like (1), so option two uses things like this:
static const char singleton_item_added = 0;
static const char singleton_item_added_binary = 0;
...
#define ITEM_ADDED (&singleton_item_added)
#define ITEM_ADDED_B (&singleton_item_added_binary)
...
apr_hash_set(hash, key, klen, ITEM_ADDED);
...
val = apr_hash_get(hash, key, klen);
if (val == ITEM_ADDED) ...
>...
> + if (es->status == replaced)
> + printf ("Replacing %s\n", (const char *)key);
You have "binary" status here, too. If you don't print it, then the user is
losing information (they used to get 'Adding (bin) ...' here).
>...
> + es = apr_hash_get (d->added_or_deleted, printable_name->data,
> + APR_HASH_KEY_STRING);
The "rule" here is:
* if you have the key's length already, then pass it
* if you don't have the length, then do not call strlen(), but use
APR_HASH_KEY_STRING instead (the hash code can be more efficient by
computing the hash value and the length at the same time)
So... in these cases, you have printable_name->len which can be passed.
>...
> + es = apr_hash_get (parent_d->added_or_deleted, child_d->path->data,
> + APR_HASH_KEY_STRING);
And child_d->path->len.
Cheers,
-g
--
Greg Stein, http://www.lyra.org/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Re: [PATCH] partial fix for issue 571
Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On Mon, Feb 25, 2002 at 02:21:23PM -0500, Garrett Rooney wrote:
> On Mon, Feb 25, 2002 at 07:21:13PM +0100, Branko _ibej wrote:
>
> [ snip much code and comments ]
>
> > Right here. It you add 'fb', keyed off it's name, to the hash instead of
> > the binary/text flag, you can later: a) check fb->binary directly
> > instead of muching around with the enums; b) fix up 'added' to
> > 'replaced', as I suggested above.
> >
> > This may mean a bit more work up front, but the code would definitely be
> > cleaner. Not to mention that you'd have only one additional hash table
> > instead of two.
>
> I can't believe I didn't think of that... It will certainly make
> things much simpler. I'll write this change up tonight.
Well, it wasn't quite as simple as sticking the baton in the hash
table, since we don't always have an appropriate baton. In
delete_entry we only have a pointer to the parent, not the current
entity. Instead I'm using a single hash, as you suggested, which
stores a struct that contains a flag to denote binary/text status and
a status flag to say if it's been added, deleted, or replaced.
This is quite a bit more readable than my original change.
If nobody has any other suggestions, I'll commit this and move on to
fixing the behavior in svn update.
-garrett
Index: ./subversion/clients/cmdline/trace-commit.c
===================================================================
--- ./subversion/clients/cmdline/trace-commit.c
+++ ./subversion/clients/cmdline/trace-commit.c Mon Feb 25 19:57:47 2002
@@ -27,6 +27,7 @@
#define APR_WANT_STDIO
#define APR_WANT_STRFUNC
#include <apr_want.h>
+#include <assert.h>
#include "svn_pools.h"
#include "svn_wc.h"
@@ -44,6 +45,21 @@
};
+enum status
+{
+ added,
+ deleted,
+ replaced
+};
+
+
+struct entry_status
+{
+ svn_boolean_t binary;
+ enum status status;
+};
+
+
struct dir_baton
{
struct edit_baton *edit_baton;
@@ -51,6 +67,7 @@
svn_stringbuf_t *path;
svn_boolean_t added;
svn_boolean_t prop_changed;
+ apr_hash_t *added_or_deleted;
apr_pool_t *subpool;
int ref_count;
};
@@ -80,6 +97,28 @@
if (db->ref_count == 0)
{
struct dir_baton *dbparent = db->parent_dir_baton;
+ apr_hash_index_t *hi;
+ const void *key;
+ void *val;
+
+ for (hi = apr_hash_first (db->subpool, db->added_or_deleted);
+ hi;
+ hi = apr_hash_next (hi))
+ {
+ struct entry_status *es;
+ apr_hash_this (hi, &key, NULL, &val);
+
+ es = val;
+
+ if (es->status == replaced)
+ printf ("Replacing %s\n", (const char *)key);
+ else if (es->status == deleted)
+ printf ("Deleting %s\n", (const char *)key);
+ else
+ printf ("Adding %s %s\n", es->binary ? "(bin)" : " ",
+ (const char *)key);
+ }
+
/* Destroy all memory used by this baton, including the baton
itself! */
@@ -107,6 +146,8 @@
rb->subpool = subpool;
rb->ref_count = 1;
+ rb->added_or_deleted = apr_hash_make (subpool);
+
*root_baton = rb;
return SVN_NO_ERROR;
@@ -117,12 +158,30 @@
delete_entry (svn_stringbuf_t *name, svn_revnum_t revision, void *parent_baton)
{
struct dir_baton *d = parent_baton;
+ struct entry_status *es;
svn_stringbuf_t *printable_name =
svn_stringbuf_dup (d->path, d->edit_baton->pool);
svn_path_add_component (printable_name, name);
- printf ("Deleting %s\n", printable_name->data);
+ es = apr_hash_get (d->added_or_deleted, printable_name->data,
+ APR_HASH_KEY_STRING);
+ if (es == NULL)
+ {
+ es = apr_palloc (d->subpool, sizeof(struct entry_status));
+
+ es->status = deleted;
+ }
+ else
+ {
+ assert (es->status == added);
+
+ es->status = deleted;
+ }
+
+ apr_hash_set (d->added_or_deleted, printable_name->data, APR_HASH_KEY_STRING,
+ es);
+
return SVN_NO_ERROR;
}
@@ -137,6 +196,7 @@
apr_pool_t *subpool;
struct dir_baton *parent_d = parent_baton;
struct dir_baton *child_d;
+ struct entry_status *es;
subpool = svn_pool_create (parent_d->edit_baton->pool);
child_d = apr_pcalloc (subpool, sizeof (*child_d));
@@ -150,7 +210,26 @@
child_d->ref_count = 1;
parent_d->ref_count++;
- printf ("Adding %s\n", child_d->path->data);
+ child_d->added_or_deleted = apr_hash_make (subpool);
+
+ es = apr_hash_get (parent_d->added_or_deleted, child_d->path->data,
+ APR_HASH_KEY_STRING);
+ if (es == NULL)
+ {
+ es = apr_palloc (parent_d->subpool, sizeof(struct entry_status));
+
+ es->status = added;
+ }
+ else
+ {
+ assert (es->status = deleted);
+
+ es->status = replaced;
+ }
+
+ apr_hash_set (parent_d->added_or_deleted, child_d->path->data,
+ APR_HASH_KEY_STRING, es);
+
*child_baton = child_d;
return SVN_NO_ERROR;
@@ -178,6 +257,8 @@
child_d->ref_count = 1;
parent_d->ref_count++;
+ child_d->added_or_deleted = apr_hash_make (subpool);
+
*child_baton = child_d;
/* Don't print anything for a directory open -- this event is
@@ -206,9 +287,29 @@
struct file_baton *fb = file_baton;
if (fb->added)
- printf ("Adding %s %s\n",
- fb->binary ? "(bin)" : " ",
- fb->path->data);
+ {
+ struct entry_status *es =
+ apr_hash_get (fb->parent_dir_baton->added_or_deleted, fb->path->data,
+ APR_HASH_KEY_STRING);
+ if (es == NULL)
+ {
+ es = apr_palloc (fb->parent_dir_baton->subpool,
+ sizeof(struct entry_status));
+
+ es->status = added;
+ es->binary = fb->binary;
+ }
+ else
+ {
+ assert (es->status == deleted);
+
+ es->status = replaced;
+ es->binary = fb->binary;
+ }
+
+ apr_hash_set (fb->parent_dir_baton->added_or_deleted, fb->path->data,
+ APR_HASH_KEY_STRING, es);
+ }
else
printf ("Sending %s\n", fb->path->data);
--
garrett rooney Unix was not designed to stop you from
rooneg@electricjellyfish.net doing stupid things, because that would
http://electricjellyfish.net/ stop you from doing clever things.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Re: [PATCH] partial fix for issue 571
Posted by Garrett Rooney <ro...@electricjellyfish.net>.
On Mon, Feb 25, 2002 at 07:21:13PM +0100, Branko _ibej wrote:
[ snip much code and comments ]
> Right here. It you add 'fb', keyed off it's name, to the hash instead of
> the binary/text flag, you can later: a) check fb->binary directly
> instead of muching around with the enums; b) fix up 'added' to
> 'replaced', as I suggested above.
>
> This may mean a bit more work up front, but the code would definitely be
> cleaner. Not to mention that you'd have only one additional hash table
> instead of two.
I can't believe I didn't think of that... It will certainly make
things much simpler. I'll write this change up tonight.
Thanks,
-garrett
--
garrett rooney Unix was not designed to stop you from
rooneg@electricjellyfish.net doing stupid things, because that would
http://electricjellyfish.net/ stop you from doing clever things.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Re: [PATCH] partial fix for issue 571
Posted by Branko Čibej <br...@xbc.nu>.
Garrett Rooney wrote:
>Here's a patch that fixes half of issue 571. The issue is about
>printing out notification that a file has been replaced, rather than
>having a notification that it was deleted followed by a notification
>that the same file was added. This patch fixes it for commit, and if
>people think this is the right approach, I'll do something similar for
>update.
>
>-garrett
>
>Index: ./subversion/clients/cmdline/trace-commit.c
>===================================================================
>--- ./subversion/clients/cmdline/trace-commit.c
>+++ ./subversion/clients/cmdline/trace-commit.c Sun Feb 24 20:46:35 2002
>@@ -44,6 +44,22 @@
> };
>
>
>+/* When we add and delete files, we don't immediately print out that info,
>+ because if a file is both added and deleted, we want to say it was
>+ replaced. So instead, we have 2 hashes in the dir baton, one for adds
>+ and one for deletes. For deletes, the key is all that matters, since
>+ we just need to know the entity's name. For adds, the val is used to
>+ tell us if the file was binary or not. (We use the pointer as a flag,
>+ it doesn't actually point to anything) We can't just store the value of
>+ the file's binary flag, because FALSE is equal to NULL, and that means
>+ 'erase this entry' in apr_hash_set. So instead we use this enum. */
>+enum file_type
>+{
>+ binary = 1,
>+ text = 2
>+};
>
I don't think you need this at all, see below.
>struct dir_baton
> {
> struct edit_baton *edit_baton;
>@@ -51,6 +67,8 @@
> svn_stringbuf_t *path;
> svn_boolean_t added;
> svn_boolean_t prop_changed;
>+ apr_hash_t *entries_added;
>+ apr_hash_t *entries_deleted;
>
You don't need two hashes. You need only one. What you do is, every time
you get an "add" or "delete", you:
* Check the hash. If the entry is already there, change its state to
"replaced".
* Otherwise just add the entry to the hash.
>
> apr_pool_t *subpool;
> int ref_count;
> };
>@@ -80,6 +98,34 @@
> if (db->ref_count == 0)
> {
> struct dir_baton *dbparent = db->parent_dir_baton;
>+ apr_hash_index_t *hi;
>+ const void *key;
>+ void *val;
>+
>+ for (hi = apr_hash_first(db->subpool, db->entries_added);
>+ hi;
>+ hi = apr_hash_next(hi))
>+ {
>+ apr_hash_this(hi, &key, NULL, &val);
>+ if (apr_hash_get(db->entries_deleted, key, APR_HASH_KEY_STRING)
>+ != NULL)
>+ {
>+ printf("Replacing %s\n", (const char *)key);
>+ apr_hash_set(db->entries_deleted, key, APR_HASH_KEY_STRING, NULL);
>+ }
>+ else
>+ printf("Adding %s %s\n",
>+ ((enum file_type)val) == binary ? "(bin)" : " ",
>+ (const char *)key);
>+ }
>+
>+ for (hi = apr_hash_first(db->subpool, db->entries_deleted);
>+ hi;
>+ hi = apr_hash_next(hi))
>+ {
>+ apr_hash_this(hi, &key, NULL, NULL);
>+ printf("Deleting %s\n", (const char *)key);
>+ }
>
It's much simpler to just add the whole entry to the hash, see below ...
>
> /* Destroy all memory used by this baton, including the baton
> itself! */
>@@ -107,6 +153,9 @@
> rb->subpool = subpool;
> rb->ref_count = 1;
>
>+ rb->entries_added = apr_hash_make(subpool);
>+ rb->entries_deleted = apr_hash_make(subpool);
>+
> *root_baton = rb;
>
> return SVN_NO_ERROR;
>@@ -122,7 +171,9 @@
>
> svn_path_add_component (printable_name, name);
>
>- printf ("Deleting %s\n", printable_name->data);
>+ apr_hash_set(d->entries_deleted, printable_name->data, APR_HASH_KEY_STRING,
>+ printable_name->data);
>+
> return SVN_NO_ERROR;
> }
>
>@@ -150,7 +201,12 @@
> child_d->ref_count = 1;
> parent_d->ref_count++;
>
>- printf ("Adding %s\n", child_d->path->data);
>+ child_d->entries_added = apr_hash_make(subpool);
>+ child_d->entries_deleted = apr_hash_make(subpool);
>+
>+ apr_hash_set(parent_d->entries_added, child_d->path->data,
>+ APR_HASH_KEY_STRING, child_d->path->data);
>+
> *child_baton = child_d;
>
> return SVN_NO_ERROR;
>@@ -178,6 +234,9 @@
> child_d->ref_count = 1;
> parent_d->ref_count++;
>
>+ child_d->entries_added = apr_hash_make(subpool);
>+ child_d->entries_deleted = apr_hash_make(subpool);
>+
> *child_baton = child_d;
>
> /* Don't print anything for a directory open -- this event is
>@@ -206,9 +265,9 @@
> struct file_baton *fb = file_baton;
>
> if (fb->added)
>- printf ("Adding %s %s\n",
>- fb->binary ? "(bin)" : " ",
>- fb->path->data);
>+ apr_hash_set(fb->parent_dir_baton->entries_added, fb->path->data,
>+ APR_HASH_KEY_STRING,
>+ fb->binary ? (void *)binary : (void *)text);
> else
> printf ("Sending %s\n", fb->path->data);
>
Right here. It you add 'fb', keyed off it's name, to the hash instead of
the binary/text flag, you can later: a) check fb->binary directly
instead of muching around with the enums; b) fix up 'added' to
'replaced', as I suggested above.
This may mean a bit more work up front, but the code would definitely be
cleaner. Not to mention that you'd have only one additional hash table
instead of two.
--
Brane Čibej <br...@xbc.nu> http://www.xbc.nu/brane/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org