[PATCH 1 of 3 RFC] context: move dirstate to workingctx

Jun Wu quark at fb.com
Wed May 31 22:05:40 EDT 2017


While this might work in a short term to work with merge.update, I think
dirstate is special and complex enough to be detached from a ctx (ex.
memctx) object, except for wctx.

Ideally, I think the main wctx/mctx API is just __setitem__(path, fctx):

  # change content
  ctx[path] = overlayfilectx(ctx[path], datafunc=lambda: newdata)

  # change exec or symlink
  ctx[path] = overlayfilectx(ctx[path], flags='xl')

  # change copy information
  ctx[path] = overlayfilectx(ctx[path], copied=(path, filenode))

  # remove a file
  ctx[path] = None

Since ctx knows a manifest, the above interface is enough for a mctx to
figure out what's added, modified, removed, copied at commit time. wctx
could use dirstate as an implementation detail to deal with "copied"
change. The benefit of "writing a fctx" allows us to have LFS fast path for
free.

For an extension developer's point of view, I think it's more friendly to
make the following just work:

  mctx = memctx()
  mctx['newfile'] = memfctx(data='new file content')
  mctx['cheap-copy-a-large-file'] = ctx['a-large-file']
  mctx['deleteme'] = None
  mctx.commit()

without requiring a developer to figure out dirstate manually like:

  mctx.dirstate.add('newfile')
  ...

Excerpts from Sean Farley's message of 2017-05-31 17:28:49 -0700:
> Sean Farley <sean at farley.io> writes:
> 
> > # HG changeset patch
> > # User Sean Farley <sean at farley.io>
> > # Date 1494536549 25200
> > #      Thu May 11 14:02:29 2017 -0700
> > # Branch wctxds
> > # Node ID 498dae194ccf1e82caed51a02e6ce0b77f8d92e8
> > # Parent  c8f9bb73d4308b5629ac786fd5e671ed717b2b58
> > context: move dirstate to workingctx
> >
> > This commit eventually needs to be broken up (so consider this a WIP).
> > Currently, dirstate is mostly an implementation optimization to prevent
> > reading the status from disk. It's also a staging area for metadata for
> > the next commit (never mind the branch name ;-)).
> >
> > As such, let's move the dirstate to workingctx and split up the logic
> > for the metadata at some point later.
> 
> This is a request-for-comment about removing the dirstate property from
> localrepo before going all the way through with it. The general idea is
> that things involving the working directory will be migrated to
> workingctx and localrepo will no long having methods to access the disk.
> 
> That would make future work for in-memory operations easy to swap out by
> just passing in a memctx instead of workingctx.


More information about the Mercurial-devel mailing list