Patchwork [1,of,4,V3] debugdirstate: add command to rebuildstate test to modify dirstate

login
register
mail settings
Submitter Christian Delahousse
Date Dec. 1, 2015, 7:38 p.m.
Message ID <15de5c7a6042c92f8b4a.1448998705@dev4253.prn1.facebook.com>
Download mbox | patch
Permalink /patch/11726/
State Accepted
Headers show

Comments

Christian Delahousse - Dec. 1, 2015, 7:38 p.m.
# HG changeset patch
# User Christian Delahousse <cdelahousse@fb.com>
# Date 1448997434 28800
#      Tue Dec 01 11:17:14 2015 -0800
# Node ID 15de5c7a6042c92f8b4a3a0c0ee265ec72ba2f5e
# Parent  61fbf5dc12b23e7a2a30cf04ebd9f096c42a1f61
debugdirstate: add command to rebuildstate test to modify dirstate

Debugging the dirstate helps if you have options to add files for normal lookup
or drop them from the dirstate. This patch adds a convenience command to
test-rebuilddirstate.t to modify the dirstate. It will be used in the next patch
to write proper tests for debugrebuilddirstate --minimal

Patch

diff --git a/tests/test-rebuildstate.t b/tests/test-rebuildstate.t
--- a/tests/test-rebuildstate.t
+++ b/tests/test-rebuildstate.t
@@ -1,3 +1,34 @@ 
+
+  $ cat > adddrop.py <<EOF
+  > from mercurial import cmdutil
+  > cmdtable = {}
+  > command = cmdutil.command(cmdtable)
+  > @command('debugadddrop',
+  >   [('', 'drop', False, 'drop file from dirstate', 'FILE'),
+  >    ('', 'normal-lookup', False, 'add file to dirstate', 'FILE')],
+  >     'hg debugadddrop')
+  > def debugadddrop(ui, repo, *pats, **opts):
+  >   '''Add or drop unnamed arguments to or from the dirstate'''
+  >   drop = opts.get('drop')
+  >   nl = opts.get('normal_lookup')
+  >   if nl and drop:
+  >       raise error.Abort('drop and normal-lookup are mutually exclusive')
+  >   wlock = repo.wlock()
+  >   try:
+  >     for file in pats:
+  >       if opts.get('normal_lookup'):
+  >         repo.dirstate.normallookup(file)
+  >       else:
+  >         repo.dirstate.drop(file)
+  > 
+  >     repo.dirstate.write(repo.currenttransaction())
+  >   finally:
+  >     wlock.release()
+  > EOF
+
+  $ echo "[extensions]" >> $HGRCPATH
+  $ echo "debugadddrop=`pwd`/adddrop.py" >> $HGRCPATH
+
 basic test for hg debugrebuildstate
 
   $ hg init repo
@@ -20,6 +51,15 @@ 
   n 644         -1 set                 bar
   n 644         -1 set                 foo
 
+  $ hg debugadddrop --normal-lookup file1 file2
+  $ hg debugadddrop --drop bar
+  $ hg debugadddrop --drop
+  $ hg debugstate --nodates
+  n   0         -1 unset               file1
+  n   0         -1 unset               file2
+  n 644         -1 set                 foo
+  $ hg debugrebuildstate
+
 status
 
   $ hg st -A