[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: [PATCH] partial fix for issue 571

From: Garrett Rooney <rooneg_at_electricjellyfish.net>
Date: 2002-02-26 02:17:31 CET

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
Received on Sat Oct 21 14:37:09 2006

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.