Patchwork D7025: rewriteutil: add configurable check to disallow obsoleting someone else cset

login
register
mail settings
Submitter phabricator
Date Oct. 8, 2019, 7:25 p.m.
Message ID <differential-rev-PHID-DREV-oxfxo3jkplcqyoaeoyea-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/42119/
State New
Headers show

Comments

phabricator - Oct. 8, 2019, 7:25 p.m.
pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  One of the things about obsolete markers (especially prune markers) is that
  sharing them can lead to cases where you loose your data. The best example is
  that someone else prune your changeset and you pull from them and your commit
  disappears locally.
  
  There are two parts of solving the above mentioned problem:
  
  1. disallow obsoleting changesets which are not authored by you unless some
  
  config or force is passed
  
  2. notifying the end user and creating a journal of obsolete markers which the
  
  user recieves on their cset from someone else
  
  This patch tries to tackle the first one.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D7025

AFFECTED FILES
  mercurial/rewriteutil.py

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-devel
phabricator - Oct. 9, 2019, 3:57 p.m.
marmoute added a comment.


  This should probably be controled by a config option instead of a keyword argument to this function (we want the control of this to be unified)
  
  I would prefer a prompt than an abort.
  
  We talked about the pre-checking topic with Sushil on Sunday. The result of the discussion is synthetised in this plan page: https://www.mercurial-scm.org/wiki/CEDPrecheckPlan

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7025/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7025

To: pulkit, #hg-reviewers
Cc: marmoute, mercurial-devel

Patch

diff --git a/mercurial/rewriteutil.py b/mercurial/rewriteutil.py
--- a/mercurial/rewriteutil.py
+++ b/mercurial/rewriteutil.py
@@ -16,9 +16,11 @@ 
     revset,
 )
 
-def precheck(repo, revs, action='rewrite'):
+def precheck(repo, revs, action='rewrite', allowotherusers=True):
     """check if revs can be rewritten
     action is used to control the error message.
+    allowotherusers can be passed as false if you want to disallow users to
+    obsolete someone else changesets
 
     Make sure this function is called after taking the lock.
     """
@@ -40,6 +42,13 @@ 
     if newunstable:
         raise error.Abort(_("cannot %s changeset with children") % action)
 
+    if not allowotherusers:
+        curuser = repo.ui.username()
+        for r in revs:
+            if repo[r].user() != curuser:
+                raise error.Abort(_("cannot obsolete %s changeset which is not"
+                                    " authored by you") % r)
+
 def disallowednewunstable(repo, revs):
     """Checks whether editing the revs will create new unstable changesets and
     are we allowed to create them.