Patchwork [2,of,3,v4] strip: strip a list of bookmarks

login
register
mail settings
Submitter Shubhanshu Agrawal
Date Nov. 16, 2015, 8:52 p.m.
Message ID <bf69fb14d9bc27092c45.1447707154@waste.org>
Download mbox | patch
Permalink /patch/11412/
State Superseded
Commit 8279c5d116a04999ba0ed6586f8ce1dcffdfb1ec
Delegated to: Pierre-Yves David
Headers show

Comments

Shubhanshu Agrawal - Nov. 16, 2015, 8:52 p.m.
# HG changeset patch
# User Shubhanshu Agrawal <agrawal.shubhanshu@gmail.com>
# Date 1447601624 -19800
#      Sun Nov 15 21:03:44 2015 +0530
# Node ID bf69fb14d9bc27092c45899218589e372b396011
# Parent  0d18b7f577b8d8a353c668c8b9d93cf4cfd5b129
strip: strip a list of bookmarks

Currently strip works with a single bookmark,
the changes in this patch modifies the strip module
to work with a list of bookmarks

Building on this we can take a list of bookmarks as input
and remove all of them in a single go
Pierre-Yves David - Nov. 18, 2015, 12:43 a.m.
On 11/16/2015 12:52 PM, Shubhanshu Agrawal wrote:
> # HG changeset patch
> # User Shubhanshu Agrawal <agrawal.shubhanshu@gmail.com>
> # Date 1447601624 -19800
> #      Sun Nov 15 21:03:44 2015 +0530
> # Node ID bf69fb14d9bc27092c45899218589e372b396011
> # Parent  0d18b7f577b8d8a353c668c8b9d93cf4cfd5b129
> strip: strip a list of bookmarks

This patches does not apply anymore. Can you rebase and resend?

(another comment below)

> Currently strip works with a single bookmark,
> the changes in this patch modifies the strip module
> to work with a list of bookmarks
>
> Building on this we can take a list of bookmarks as input
> and remove all of them in a single go
>
> diff --git a/hgext/strip.py b/hgext/strip.py
> --- a/hgext/strip.py
> +++ b/hgext/strip.py
> @@ -44,7 +44,7 @@
>               raise error.Abort(_("local changed subrepos found" + excsuffix))
>       return s
>
> -def strip(ui, repo, revs, update=True, backup=True, force=None, bookmark=None):
> +def strip(ui, repo, revs, update=True, backup=True, force=None, bookmarks=None):
>       wlock = lock = None
>       try:
>           wlock = repo.wlock()
> @@ -63,12 +63,14 @@
>           repair.strip(ui, repo, revs, backup)
>
>           repomarks = repo._bookmarks
> -        if bookmark:
> -            if bookmark == repo._activebookmark:
> +        if bookmarks:
> +            if repo._activebookmark in bookmarks:
>                   bookmarksmod.deactivate(repo)
> -            del repomarks[bookmark]
> +            for bookmark in bookmarks:
> +                del repomarks[bookmark]
>               repomarks.write()
> -            ui.write(_("bookmark '%s' deleted\n") % bookmark)
> +            for bookmark in bookmarks:
> +                ui.write(_("bookmark '%s' deleted\n") % bookmark)
>       finally:
>           release(lock, wlock)
>
> @@ -127,27 +129,31 @@
>
>       wlock = repo.wlock()
>       try:
> -        bookmark = opts.get('bookmark')
> -        if bookmark:
> +        bookmarks = None
> +        if opts.get('bookmark'):
> +            bookmarks = set([opts.get('bookmark')])
> +        if bookmarks:
>               repomarks = repo._bookmarks
> -            if bookmark not in repomarks:
> -                raise error.Abort(_("bookmark '%s' not found") % bookmark)
> +            if not bookmarks.issubset(repomarks):
> +                raise error.Abort(_("bookmark '%s' not found") %
> +                    ','.join(list(bookmarks - set(repomarks.keys()))))

It would be better to have the list sorted to make sure the output is 
stable.
Shubhanshu Agrawal - Nov. 18, 2015, 4:58 p.m.
Hi,

Thanks for the feedback, have updated and resent the patch.
re: pull and rebase: I cloned again and added the changes there, the
changes are based on bookmark '@', the node-id for base revision is the
same though.
Also by mistake all my previous mails(patches) were also sent so there
would be multiple mails(sorry for this).

Cheers
Shubhanshu

On Wed, Nov 18, 2015 at 6:13 AM, Pierre-Yves David <
pierre-yves.david@ens-lyon.org> wrote:

>
>
> On 11/16/2015 12:52 PM, Shubhanshu Agrawal wrote:
>
>> # HG changeset patch
>> # User Shubhanshu Agrawal <agrawal.shubhanshu@gmail.com>
>> # Date 1447601624 -19800
>> #      Sun Nov 15 21:03:44 2015 +0530
>> # Node ID bf69fb14d9bc27092c45899218589e372b396011
>> # Parent  0d18b7f577b8d8a353c668c8b9d93cf4cfd5b129
>> strip: strip a list of bookmarks
>>
>
> This patches does not apply anymore. Can you rebase and resend?
>
> (another comment below)
>
> Currently strip works with a single bookmark,
>> the changes in this patch modifies the strip module
>> to work with a list of bookmarks
>>
>> Building on this we can take a list of bookmarks as input
>> and remove all of them in a single go
>>
>> diff --git a/hgext/strip.py b/hgext/strip.py
>> --- a/hgext/strip.py
>> +++ b/hgext/strip.py
>> @@ -44,7 +44,7 @@
>>               raise error.Abort(_("local changed subrepos found" +
>> excsuffix))
>>       return s
>>
>> -def strip(ui, repo, revs, update=True, backup=True, force=None,
>> bookmark=None):
>> +def strip(ui, repo, revs, update=True, backup=True, force=None,
>> bookmarks=None):
>>       wlock = lock = None
>>       try:
>>           wlock = repo.wlock()
>> @@ -63,12 +63,14 @@
>>           repair.strip(ui, repo, revs, backup)
>>
>>           repomarks = repo._bookmarks
>> -        if bookmark:
>> -            if bookmark == repo._activebookmark:
>> +        if bookmarks:
>> +            if repo._activebookmark in bookmarks:
>>                   bookmarksmod.deactivate(repo)
>> -            del repomarks[bookmark]
>> +            for bookmark in bookmarks:
>> +                del repomarks[bookmark]
>>               repomarks.write()
>> -            ui.write(_("bookmark '%s' deleted\n") % bookmark)
>> +            for bookmark in bookmarks:
>> +                ui.write(_("bookmark '%s' deleted\n") % bookmark)
>>       finally:
>>           release(lock, wlock)
>>
>> @@ -127,27 +129,31 @@
>>
>>       wlock = repo.wlock()
>>       try:
>> -        bookmark = opts.get('bookmark')
>> -        if bookmark:
>> +        bookmarks = None
>> +        if opts.get('bookmark'):
>> +            bookmarks = set([opts.get('bookmark')])
>> +        if bookmarks:
>>               repomarks = repo._bookmarks
>> -            if bookmark not in repomarks:
>> -                raise error.Abort(_("bookmark '%s' not found") %
>> bookmark)
>> +            if not bookmarks.issubset(repomarks):
>> +                raise error.Abort(_("bookmark '%s' not found") %
>> +                    ','.join(list(bookmarks - set(repomarks.keys()))))
>>
>
> It would be better to have the list sorted to make sure the output is
> stable.
>
> --
> Pierre-Yves David
>
Pierre-Yves David - Nov. 18, 2015, 5:01 p.m.
On 11/18/2015 08:58 AM, Shubhanshu Agrawal wrote:
> Hi,
>
> Thanks for the feedback, have updated and resent the patch.
> re: pull and rebase: I cloned again and added the changes there, the
> changes are based on bookmark '@', the node-id for base revision is the
> same though.

You do not need to clone again. You can just pull again in the original 
repository you had (this also apply for pulling from multiple repository).

Patch

diff --git a/hgext/strip.py b/hgext/strip.py
--- a/hgext/strip.py
+++ b/hgext/strip.py
@@ -44,7 +44,7 @@ 
             raise error.Abort(_("local changed subrepos found" + excsuffix))
     return s
 
-def strip(ui, repo, revs, update=True, backup=True, force=None, bookmark=None):
+def strip(ui, repo, revs, update=True, backup=True, force=None, bookmarks=None):
     wlock = lock = None
     try:
         wlock = repo.wlock()
@@ -63,12 +63,14 @@ 
         repair.strip(ui, repo, revs, backup)
 
         repomarks = repo._bookmarks
-        if bookmark:
-            if bookmark == repo._activebookmark:
+        if bookmarks:
+            if repo._activebookmark in bookmarks:
                 bookmarksmod.deactivate(repo)
-            del repomarks[bookmark]
+            for bookmark in bookmarks:
+                del repomarks[bookmark]
             repomarks.write()
-            ui.write(_("bookmark '%s' deleted\n") % bookmark)
+            for bookmark in bookmarks:
+                ui.write(_("bookmark '%s' deleted\n") % bookmark)
     finally:
         release(lock, wlock)
 
@@ -127,27 +129,31 @@ 
 
     wlock = repo.wlock()
     try:
-        bookmark = opts.get('bookmark')
-        if bookmark: 
+        bookmarks = None
+        if opts.get('bookmark'):
+            bookmarks = set([opts.get('bookmark')])
+        if bookmarks: 
             repomarks = repo._bookmarks
-            if bookmark not in repomarks:
-                raise error.Abort(_("bookmark '%s' not found") % bookmark)
+            if not bookmarks.issubset(repomarks):
+                raise error.Abort(_("bookmark '%s' not found") %
+                    ','.join(list(bookmarks - set(repomarks.keys()))))
 
             # If the requested bookmark is not the only one pointing to a
             # a revision we have to only delete the bookmark and not strip
             # anything. revsets cannot detect that case.
-            uniquebm = True
-            for m, n in repomarks.iteritems():
-                if m != bookmark and n == repo[bookmark].node():
-                    uniquebm = False
-                    break
-            if uniquebm:
-                rsrevs = repair.stripbmrevset(repo, bookmark)
-                revs.update(set(rsrevs))
+            nodetobookmarks = {}
+            for mark, node in repomarks.iteritems():
+                nodetobookmarks.setdefault(node, []).append(mark)
+            for marks in nodetobookmarks.values():
+                if bookmarks.issuperset(marks):
+                   rsrevs = repair.stripbmrevset(repo, marks[0])
+                   revs.update(set(rsrevs))
             if not revs:
-                del repomarks[bookmark]
+                for bookmark in bookmarks:
+                    del repomarks[bookmark]
                 repomarks.write()
-                ui.write(_("bookmark '%s' deleted\n") % bookmark)
+                for bookmark in bookmarks:
+                    ui.write(_("bookmark '%s' deleted\n") % bookmark)
 
         if not revs:
             raise error.Abort(_('empty revision set'))
@@ -215,7 +221,7 @@ 
 
 
         strip(ui, repo, revs, backup=backup, update=update,
-              force=opts.get('force'), bookmark=bookmark)
+              force=opts.get('force'), bookmarks=bookmarks)
     finally:
         wlock.release()