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

Re: [PATCH] Revert and svn:needs-lock

From: D.J. Heap <dj_at_shadyvale.net>
Date: 2005-04-28 22:23:03 CEST

D.J. Heap wrote:
[snip]
>
> For fixing revert, if I put the call to svn_wc__maybe_set_read_only
> before the svn_wc__maybe_set_executable call in
> adm_ops.c:revert_admin_things, then it will correctly revert all cases I
> tried except where the needs-lock property is dropped and then reverted.
>
> In that case, even if I add the needs-lock to the magic property check,
> svn_wc_get_prop_diffs does not return a diff for the dropped needs-lock
> property and so it drops through without touching the working file at
[snip]

After more investigation, I've found this is not always the case. If
you 'svn revert D:\Temp\wc\file.txt' from outside the working copy, then
svn_wc_get_prop_diffs doesn't seem to work right -- it doesn't return
any property diffs.

So, ignoring the above bug, how does this patch look? I will invesigate
the svn_wc_get_prop_diffs issue further.

Log:
* subversion/libsvn_wc/adm_ops.c
   (revert_admin_things): Call svn_wc__maybe_set_read_only to
   restore read-only-ness as needed.

* subversion/libsvn_wc/translate.c
   (svn_wc__maybe_set_read_only): See if we have the lock token
   before making a svn:needs-lock file read-only.

* subversion/tests/clients/cmdline/lock_tests.py
   (revert_lock): New regression test for above.

Index: subversion/libsvn_wc/adm_ops.c
===================================================================
--- subversion/libsvn_wc/adm_ops.c (revision 14500)
+++ subversion/libsvn_wc/adm_ops.c (working copy)
@@ -1246,7 +1246,8 @@
             if ((! strcmp (propchange->name, SVN_PROP_EXECUTABLE))
                 || (! strcmp (propchange->name, SVN_PROP_KEYWORDS))
                 || (! strcmp (propchange->name, SVN_PROP_EOL_STYLE))
- || (! strcmp (propchange->name, SVN_PROP_SPECIAL)))
+ || (! strcmp (propchange->name, SVN_PROP_SPECIAL))
+ || (! strcmp (propchange->name, SVN_PROP_NEEDS_LOCK)))
               magic_props_changed = TRUE;
           }
       }
@@ -1359,6 +1360,9 @@
               (err, apr_psprintf (pool, _("Error restoring text for '%s'"),
                                   svn_path_local_style (fullpath, pool)));
 
+ /* If necessary, tweak the read-only-ness of the file. */
+ SVN_ERR (svn_wc__maybe_set_read_only (NULL, fullpath, adm_access, pool));
+
           /* If necessary, tweak the new working file's executable bit. */
           SVN_ERR (svn_wc__maybe_set_executable (NULL, fullpath, adm_access,
                                                  pool));
Index: subversion/libsvn_wc/translate.c
===================================================================
--- subversion/libsvn_wc/translate.c (revision 14500)
+++ subversion/libsvn_wc/translate.c (working copy)
@@ -265,6 +265,15 @@
                              apr_pool_t *pool)
 {
   const svn_string_t *needs_lock;
+ svn_wc_entry_t* entry;
+
+ if (did_set)
+ *did_set = FALSE;
+
+ SVN_ERR (svn_wc_entry (&entry, path, adm_access, FALSE, pool));
+ if ( entry && entry->lock_token )
+ return SVN_NO_ERROR;
+
   SVN_ERR (svn_wc_prop_get (&needs_lock, SVN_PROP_NEEDS_LOCK, path,
                             adm_access, pool));
 
@@ -275,8 +284,6 @@
       if (did_set)
         *did_set = TRUE;
     }
- else if (did_set)
- *did_set = FALSE;
 
   return SVN_NO_ERROR;
 }
Index: subversion/tests/clients/cmdline/lock_tests.py
===================================================================
--- subversion/tests/clients/cmdline/lock_tests.py (revision 14500)
+++ subversion/tests/clients/cmdline/lock_tests.py (working copy)
@@ -750,8 +750,70 @@
                                      '--password', svntest.main.wc_passwd,
                                      '-m', '', file_path_b)
 
+#----------------------------------------------------------------------
+# Tests reverting a svn:needs-lock file
+def revert_lock(sbox):
+ "verify svn:needs-lock behavior with revert"
 
+ sbox.build()
+ wc_dir = sbox.wc_dir
 
+ iota_path = os.path.join(wc_dir, 'iota')
+
+ mode = stat.S_IWGRP | stat.S_IWOTH | stat.S_IWRITE
+
+ # set the prop in wc
+ svntest.main.run_svn(None, 'propset', 'svn:needs-lock', 'foo', iota_path)
+
+ # commit r2
+ svntest.main.run_svn(None, 'commit',
+ '--username', svntest.main.wc_author,
+ '--password', svntest.main.wc_passwd,
+ '-m', '', iota_path)
+
+ # make sure that iota got set to read-only
+ if (os.stat (iota_path)[0] & mode):
+ print "Committing a file with 'svn:needs-lock'"
+ print "did not set the file to read-only"
+ raise svntest.Failure
+
+ # remove read-only-ness
+ svntest.main.run_svn(None, 'propdel', 'svn:needs-lock', iota_path)
+
+ # make sure that iota got read-only-ness removed
+ if (os.stat (iota_path)[0] & mode == 0):
+ print "Deleting the 'svn:needs-lock' property "
+ print "did not remove read-only-ness"
+ raise svntest.Failure
+
+ # revert the change
+ svntest.main.run_svn(None, 'revert', iota_path)
+
+ # make sure that iota got set back to read-only
+ if (os.stat (iota_path)[0] & mode):
+ print "Reverting a file with 'svn:needs-lock'"
+ print "did not set the file back to read-only"
+ raise svntest.Failure
+
+ # now lock the file
+ svntest.main.run_svn(None, 'lock',
+ '--username', svntest.main.wc_author,
+ '--password', svntest.main.wc_passwd,
+ '-m', '', iota_path)
+
+ # modify it
+ svntest.main.file_append(iota_path, "This line added\n")
+
+ # revert it
+ svntest.main.run_svn(None, 'revert', iota_path)
+
+ # make sure it is still writable since we have the lock
+ if (os.stat (iota_path)[0] & mode == 0):
+ print "Reverting a 'svn:needs-lock' file (with lock in wc) "
+ print "did not leave the file writable"
+ raise svntest.Failure
+
+
 #----------------------------------------------------------------------
 def examine_lock_via_url(sbox):
   "examine the fields of a lock from a URL"
@@ -781,7 +843,6 @@
     raise svntest.Failure
 
 
-
 ########################################################################
 # Run the tests
 
@@ -804,6 +865,7 @@
               lock_non_existent_file,
               out_of_date,
               update_while_needing_lock,
+ revert_lock,
               examine_lock_via_url,
              ]
 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Thu Apr 28 23:11:23 2005

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