Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Add a changegroup hook to update svn metadata
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Brad Hall  
View profile  
 More options Jun 8 2012, 4:28 pm
From: Brad Hall <bh...@fb.com>
Date: Fri, 8 Jun 2012 13:28:07 -0700
Local: Fri, Jun 8 2012 4:28 pm
Subject: [PATCH] Add a changegroup hook to update svn metadata
# HG changeset patch
# User Brad Hall <bh...@fb.com>
# Date 1339111745 25200
# Node ID 998fdd15b5cc2d4b2b2d819143719ac40390ad98
# Parent  1750f667b870961047424b99a3701aa8e03f0825
Add a changegroup hook to update svn metadata

diff --git a/hooks/updatemetahook.py b/hooks/updatemetahook.py
new file mode 100644
--- /dev/null
+++ b/hooks/updatemetahook.py
@@ -0,0 +1,38 @@
+# Mercurial hook to update/rebuild svn metadata if there are svn changes in
+# the incoming changegroup.
+#
+# To install, add the following to your hgrc:
+# [hooks]
+# changegroup = python:/path/to/updatemetahook.py:hook
+
+from mercurial import node
+
+shouldrun = False
+try:
+   import hgsubversion
+   import hgsubversion.util
+   import hgsubversion.svncommands
+   shouldrun = True
+except:
+   pass
+
+def hook(ui, repo, **kwargs):
+   if not shouldrun: # no hgsubversion; don't continue
+       return False
+
+   updatemeta = False
+   startrev = repo[node.bin(kwargs["node"])].rev()
+   # Check each rev until we find one that contains svn metadata
+   for rev in xrange(startrev, len(repo)):
+       svnrev = hgsubversion.util.getsvnrev(repo[rev])
+       if svnrev and svnrev.startswith("svn:"):
+           updatemeta = True
+           break
+
+   if updatemeta:
+       try:
+           hgsubversion.svncommands.updatemeta(ui, repo, args=[])
+       except Exception, e:
+           ui.warn("Failed to update svn metadata: %s" % str(e))
+
+   return False


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Augie Fackler  
View profile  
 More options Jun 13 2012, 10:36 am
From: Augie Fackler <r...@durin42.com>
Date: Wed, 13 Jun 2012 10:36:24 -0400
Local: Wed, Jun 13 2012 10:36 am
Subject: Re: [PATCH] Add a changegroup hook to update svn metadata

On Jun 8, 2012, at 4:28 PM, Brad Hall wrote:

Is there a way we could package it within hgsubversion so that it'd be easier for people that have hgsubversion installed at an unknown path?

Also, I'd love to see a test for this code, even if it's trivial.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brad Hall  
View profile  
 More options Jun 13 2012, 1:19 pm
From: Brad Hall <bh...@fb.com>
Date: Wed, 13 Jun 2012 17:19:09 +0000
Local: Wed, Jun 13 2012 1:19 pm
Subject: Re: [PATCH] Add a changegroup hook to update svn metadata

On Jun 13, 2012, at 7:36 AM, Augie Fackler wrote:

On Jun 8, 2012, at 4:28 PM, Brad Hall wrote:

# HG changeset patch
# User Brad Hall <bh...@fb.com<mailto:bh...@fb.com>>
# Date 1339111745 25200
# Node ID 998fdd15b5cc2d4b2b2d819143719ac40390ad98
# Parent  1750f667b870961047424b99a3701aa8e03f0825
Add a changegroup hook to update svn metadata

diff --git a/hooks/updatemetahook.py b/hooks/updatemetahook.py
new file mode 100644
--- /dev/null
+++ b/hooks/updatemetahook.py
@@ -0,0 +1,38 @@
+# Mercurial hook to update/rebuild svn metadata if there are svn changes in
+# the incoming changegroup.
+#
+# To install, add the following to your hgrc:
+# [hooks]
+# changegroup = python:/path/to/updatemetahook.py:hook
+

Is there a way we could package it within hgsubversion so that it'd be easier for people that have hgsubversion installed at an unknown path?

Sure, will do

Also, I'd love to see a test for this code, even if it's trivial.

OK.. I'll add one.  Thanks for reviewing!

-Brad


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brad Hall  
View profile  
 More options Jul 19 2012, 2:19 pm
From: Brad Hall <bh...@fb.com>
Date: Thu, 19 Jul 2012 11:19:54 -0700
Local: Thurs, Jul 19 2012 2:19 pm
Subject: Re: [PATCH] Add a changegroup hook to update svn metadata

On Wed, Jun 13, 2012 at 10:36:24AM -0400, Augie Fackler wrote:

> On Jun 8, 2012, at 4:28 PM, Brad Hall wrote:

> > # HG changeset patch
> > # User Brad Hall <bh...@fb.com>
> > # Date 1339111745 25200
> > # Node ID 998fdd15b5cc2d4b2b2d819143719ac40390ad98
> > # Parent  1750f667b870961047424b99a3701aa8e03f0825
> > Add a changegroup hook to update svn metadata

> Is there a way we could package it within hgsubversion so that it'd be easier for people that have hgsubversion installed at an unknown path?

> Also, I'd love to see a test for this code, even if it's trivial.

Yes to both of those.. here is a new patch:

# HG changeset patch
# User Brad Hall <bh...@fb.com>
# Date 1339111745 25200
# Node ID 0a4b16303fbae70dc4c06b9dca5ea6382716356c
# Parent  1750f667b870961047424b99a3701aa8e03f0825
Add a changegroup hook to update svn metadata

diff --git a/hgsubversion/hooks/__init__.py b/hgsubversion/hooks/__init__.py
new file mode 100644
diff --git a/hgsubversion/hooks/updatemeta.py b/hgsubversion/hooks/updatemeta.py
new file mode 100644
--- /dev/null
+++ b/hgsubversion/hooks/updatemeta.py
@@ -0,0 +1,38 @@
+# Mercurial hook to update/rebuild svn metadata if there are svn changes in
+# the incoming changegroup.
+#
+# To install, add the following to your hgrc:
+# [hooks]
+# changegroup = python:hgsubversion.hooks.updatemeta.hook
+
+from mercurial import node
+
+shouldrun = False
+try:
+    import hgsubversion
+    import hgsubversion.util
+    import hgsubversion.svncommands
+    shouldrun = True
+except:
+    pass
+
+def hook(ui, repo, **kwargs):
+    if not shouldrun: # no hgsubversion; don't continue
+        return False
+
+    updatemeta = False
+    startrev = repo[node.bin(kwargs["node"])].rev()
+    # Check each rev until we find one that contains svn metadata
+    for rev in xrange(startrev, len(repo)):
+        svnrev = hgsubversion.util.getsvnrev(repo[rev])
+        if svnrev and svnrev.startswith("svn:"):
+            updatemeta = True
+            break
+
+    if updatemeta:
+        try:
+            hgsubversion.svncommands.updatemeta(ui, repo, args=[])
+        except Exception, e:
+            ui.warn("Failed to update svn metadata: %s" % str(e))
+
+    return False
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -118,7 +118,7 @@
     long_description=open(os.path.join(os.path.dirname(__file__),
                                          'README')).read(),
     keywords='mercurial',
-    packages=('hgsubversion', 'hgsubversion.svnwrap'),
+    packages=('hgsubversion', 'hgsubversion.hooks', 'hgsubversion.svnwrap'),
     package_data={ 'hgsubversion': ['help/subversion.rst'] },
     platforms='any',
     install_requires=requires,
diff --git a/tests/run.py b/tests/run.py
--- a/tests/run.py
+++ b/tests/run.py
@@ -18,6 +18,7 @@
     import test_fetch_renames
     import test_fetch_symlinks
     import test_fetch_truncated
+    import test_hooks
     import test_pull
     import test_push_command
     import test_push_renames
diff --git a/tests/test_hooks.py b/tests/test_hooks.py
new file mode 100644
--- /dev/null
+++ b/tests/test_hooks.py
@@ -0,0 +1,48 @@
+import sys
+import test_util
+import unittest
+
+from mercurial import hg
+from mercurial import commands
+
+class TestHooks(test_util.TestBase):
+    def setUp(self):
+        super(TestHooks, self).setUp()
+
+    def _loadupdate(self, fixture_name, *args, **kwargs):
+        kwargs = kwargs.copy()
+        kwargs.update(stupid=False, noupdate=False)
+        repo, repo_path = self.load_and_fetch(fixture_name, *args, **kwargs)
+        return repo, repo_path
+
+    def test_updatemetahook(self):
+        repo, repo_path = self._loadupdate('single_rev.svndump')
+        state = repo.parents()
+        self.add_svn_rev(repo_path, {'trunk/alpha': 'Changed'})
+        commands.pull(self.repo.ui, self.repo)
+
+        # Clone to a new repository and add a hook
+        new_wc_path = "%s-2" % self.wc_path
+        commands.clone(self.repo.ui, self.wc_path, new_wc_path)
+        newrepo = hg.repository(test_util.testui(), new_wc_path)
+        newrepo.ui.setconfig('hooks', 'changegroup.meta',
+                'python:hgsubversion.hooks.updatemeta.hook')
+
+        # Commit a rev that should trigger svn meta update
+        self.add_svn_rev(repo_path, {'trunk/alpha': 'Changed Again'})
+        commands.pull(self.repo.ui, self.repo)
+
+        self.called = False
+        def _updatemeta(ui, repo, args=[]):
+            self.called = True
+        import hgsubversion.svncommands
+        oldupdatemeta = hgsubversion.svncommands.updatemeta
+        hgsubversion.svncommands.updatemeta = _updatemeta
+
+        # Pull and make sure our updatemeta function gets called
+        commands.pull(newrepo.ui, newrepo)
+        hgsubversion.svncommands.updatemeta = oldupdatemeta
+        self.assertTrue(self.called)
+
+def suite():
+    return unittest.findTestCases(sys.modules[__name__])


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Augie Fackler  
View profile  
 More options Jul 21 2012, 4:53 pm
From: Augie Fackler <r...@durin42.com>
Date: Sat, 21 Jul 2012 13:53:28 -0700
Local: Sat, Jul 21 2012 4:53 pm
Subject: Re: [PATCH] Add a changegroup hook to update svn metadata

On Jul 19, 2012, at 11:19 AM, Brad Hall wrote:

Seems pretty silly that they'd have the hook installed but not hgsubversion now. Drop this bit?

I wonder if we should print something, since this will have side effects on repositories with history from convert or hgsubversion even if the user doesn't expect that? I could go either way.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Brad Hall  
View profile  
 More options Jul 22 2012, 12:46 am
From: Brad Hall <bh...@fb.com>
Date: Sat, 21 Jul 2012 21:46:13 -0700
Local: Sun, Jul 22 2012 12:46 am
Subject: Re: [PATCH] Add a changegroup hook to update svn metadata

Gone

Yeah, makes sense.  I added a line to print that the metadata was updated.

Updated patch below..

Thanks,
Brad

# HG changeset patch
# User Brad Hall <bh...@fb.com>
# Date 1339111745 25200
# Node ID 06d3668a1b6cab1e1b11cafed89f2c061bd0710b
# Parent  1750f667b870961047424b99a3701aa8e03f0825
Add a changegroup hook to update svn metadata

diff --git a/hgsubversion/hooks/__init__.py b/hgsubversion/hooks/__init__.py
new file mode 100644
diff --git a/hgsubversion/hooks/updatemeta.py b/hgsubversion/hooks/updatemeta.py
new file mode 100644
--- /dev/null
+++ b/hgsubversion/hooks/updatemeta.py
@@ -0,0 +1,31 @@
+# Mercurial hook to update/rebuild svn metadata if there are svn changes in
+# the incoming changegroup.
+#
+# To install, add the following to your hgrc:
+# [hooks]
+# changegroup = python:hgsubversion.hooks.updatemeta.hook
+
+from mercurial import node
+
+import hgsubversion
+import hgsubversion.util
+import hgsubversion.svncommands
+
+def hook(ui, repo, **kwargs):
+    updatemeta = False
+    startrev = repo[node.bin(kwargs["node"])].rev()
+    # Check each rev until we find one that contains svn metadata
+    for rev in xrange(startrev, len(repo)):
+        svnrev = hgsubversion.util.getsvnrev(repo[rev])
+        if svnrev and svnrev.startswith("svn:"):
+            updatemeta = True
+            break
+
+    if updatemeta:
+        try:
+            hgsubversion.svncommands.updatemeta(ui, repo, args=[])
+            ui.status("Updated svn metadata\n")
+        except Exception, e:
+            ui.warn("Failed to update svn metadata: %s" % str(e))
+
+    return False
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -118,7 +118,7 @@
     long_description=open(os.path.join(os.path.dirname(__file__),
                                          'README')).read(),
     keywords='mercurial',
-    packages=('hgsubversion', 'hgsubversion.svnwrap'),
+    packages=('hgsubversion', 'hgsubversion.hooks', 'hgsubversion.svnwrap'),
     package_data={ 'hgsubversion': ['help/subversion.rst'] },
     platforms='any',
     install_requires=requires,
diff --git a/tests/run.py b/tests/run.py
--- a/tests/run.py
+++ b/tests/run.py
@@ -18,6 +18,7 @@
     import test_fetch_renames
     import test_fetch_symlinks
     import test_fetch_truncated
+    import test_hooks
     import test_pull
     import test_push_command
     import test_push_renames
diff --git a/tests/test_hooks.py b/tests/test_hooks.py
new file mode 100644
--- /dev/null
+++ b/tests/test_hooks.py
@@ -0,0 +1,48 @@
+import sys
+import test_util
+import unittest
+
+from mercurial import hg
+from mercurial import commands
+
+class TestHooks(test_util.TestBase):
+    def setUp(self):
+        super(TestHooks, self).setUp()
+
+    def _loadupdate(self, fixture_name, *args, **kwargs):
+        kwargs = kwargs.copy()
+        kwargs.update(stupid=False, noupdate=False)
+        repo, repo_path = self.load_and_fetch(fixture_name, *args, **kwargs)
+        return repo, repo_path
+
+    def test_updatemetahook(self):
+        repo, repo_path = self._loadupdate('single_rev.svndump')
+        state = repo.parents()
+        self.add_svn_rev(repo_path, {'trunk/alpha': 'Changed'})
+        commands.pull(self.repo.ui, self.repo)
+
+        # Clone to a new repository and add a hook
+        new_wc_path = "%s-2" % self.wc_path
+        commands.clone(self.repo.ui, self.wc_path, new_wc_path)
+        newrepo = hg.repository(test_util.testui(), new_wc_path)
+        newrepo.ui.setconfig('hooks', 'changegroup.meta',
+                'python:hgsubversion.hooks.updatemeta.hook')
+
+        # Commit a rev that should trigger svn meta update
+        self.add_svn_rev(repo_path, {'trunk/alpha': 'Changed Again'})
+        commands.pull(self.repo.ui, self.repo)
+
+        self.called = False
+        import hgsubversion.svncommands
+        oldupdatemeta = hgsubversion.svncommands.updatemeta
+        def _updatemeta(ui, repo, args=[]):
+            self.called = True
+        hgsubversion.svncommands.updatemeta = _updatemeta
+
+        # Pull and make sure our updatemeta function gets called
+        commands.pull(newrepo.ui, newrepo)
+        hgsubversion.svncommands.updatemeta = oldupdatemeta
+        self.assertTrue(self.called)
+
+def suite():
+    return unittest.findTestCases(sys.modules[__name__])


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Augie Fackler  
View profile  
 More options Jul 26 2012, 7:07 pm
From: Augie Fackler <r...@durin42.com>
Date: Thu, 26 Jul 2012 18:07:55 -0500
Local: Thurs, Jul 26 2012 7:07 pm
Subject: Re: [PATCH] Add a changegroup hook to update svn metadata
Queued, thanks.

On Jul 21, 2012, at 11:46 PM, Brad Hall wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »