##// END OF EJS Templates
git: skeleton of a new extension to _directly_ operate on git repos...
git: skeleton of a new extension to _directly_ operate on git repos This is based in part of work I did years ago in hgit, but it's mostly new code since I'm using pygit2 instead of dulwich and the hg storage interfaces have improved. Some cleanup of old hgit code by Pulkit, which I greatly appreciate. test-git-interop.t does not cover a whole lot of cases, but it passes. It includes status, diff, making a new commit, and `hg annotate` working on the git repository. This is _not_ (yet) production quality code: this is an experiment. Known technical debt lurking in this implementation: * Writing bookmarks just totally ignores transactions. * The way progress is threaded down into the gitstore is awful. * Ideally we'd find a way to incrementally reindex DAGs. I'm not sure how to do that efficiently, so we might need a "known only fast-forwards" mode on the DAG indexer for use on `hg commit` and friends. * We don't even _try_ to do anything reasonable for `hg pull` or `hg push`. * Mercurial need an interface for the changelog type. Tests currently require git 2.24 as far as I'm aware: `git status` has some changed output that I didn't try and handle in a compatible way. This patch has produced some interesting cleanups, most recently on the manifest type. I expect continuing down this road will produce other meritorious cleanups throughout our code. Differential Revision: https://phab.mercurial-scm.org/D6734

File last commit:

r43812:2fe6121c default
r44961:ad718271 default
Show More
commitextras.py
89 lines | 2.4 KiB | text/x-python | PythonLexer
Pulkit Goyal
commitextras: move fb extension to core which add extras to a commit...
r33546 # commitextras.py
#
# Copyright 2013 Facebook, Inc.
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
Pulkit Goyal
commitextras: mark the extension as ADVANCED
r33562 '''adds a new flag extras to commit (ADVANCED)'''
Pulkit Goyal
commitextras: move fb extension to core which add extras to a commit...
r33546
from __future__ import absolute_import
Pulkit Goyal
commitextras: make sure keys contains ascii letters, numbers, '_' and '-' only
r33603 import re
Pulkit Goyal
commitextras: move fb extension to core which add extras to a commit...
r33546 from mercurial.i18n import _
from mercurial import (
commands,
Pulkit Goyal
commitextras: check the format of the arguments and no internal key is used...
r33547 error,
Pulkit Goyal
commitextras: move fb extension to core which add extras to a commit...
r33546 extensions,
registrar,
Valentin Gatien-Baron
commitextras: work nicely with other extensions...
r39330 util,
Pulkit Goyal
commitextras: move fb extension to core which add extras to a commit...
r33546 )
cmdtable = {}
command = registrar.command(cmdtable)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 testedwith = b'ships-with-hg-core'
Pulkit Goyal
commitextras: move fb extension to core which add extras to a commit...
r33546
Pulkit Goyal
commitextras: check the format of the arguments and no internal key is used...
r33547 usedinternally = {
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b'amend_source',
b'branch',
b'close',
b'histedit_source',
b'topic',
b'rebase_source',
b'intermediate-source',
b'__touch-noise__',
b'source',
b'transplant_source',
Pulkit Goyal
commitextras: check the format of the arguments and no internal key is used...
r33547 }
Augie Fackler
formatting: blacken the codebase...
r43346
Pulkit Goyal
commitextras: move fb extension to core which add extras to a commit...
r33546 def extsetup(ui):
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 entry = extensions.wrapcommand(commands.table, b'commit', _commit)
Pulkit Goyal
commitextras: move fb extension to core which add extras to a commit...
r33546 options = entry[1]
Augie Fackler
formatting: blacken the codebase...
r43346 options.append(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 (
b'',
b'extra',
[],
_(b'set a changeset\'s extra values'),
_(b"KEY=VALUE"),
)
Augie Fackler
formatting: blacken the codebase...
r43346 )
Pulkit Goyal
commitextras: move fb extension to core which add extras to a commit...
r33546
def _commit(orig, ui, repo, *pats, **opts):
Martin von Zweigbergk
py3: delete b'' prefix from safehasattr arguments...
r43385 if util.safehasattr(repo, 'unfiltered'):
Valentin Gatien-Baron
commitextras: work nicely with other extensions...
r39330 repo = repo.unfiltered()
Augie Fackler
formatting: blacken the codebase...
r43346
Valentin Gatien-Baron
commitextras: work nicely with other extensions...
r39330 class repoextra(repo.__class__):
def commit(self, *innerpats, **inneropts):
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 extras = opts.get('extra')
Valentin Gatien-Baron
commitextras: no need to special case extras=[]...
r39331 for raw in extras:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 if b'=' not in raw:
Augie Fackler
formatting: blacken the codebase...
r43346 msg = _(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"unable to parse '%s', should follow "
b"KEY=VALUE format"
Augie Fackler
formatting: blacken the codebase...
r43346 )
Valentin Gatien-Baron
commitextras: no need to special case extras=[]...
r39331 raise error.Abort(msg % raw)
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 k, v = raw.split(b'=', 1)
Valentin Gatien-Baron
commitextras: no need to special case extras=[]...
r39331 if not k:
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 msg = _(b"unable to parse '%s', keys can't be empty")
Valentin Gatien-Baron
commitextras: no need to special case extras=[]...
r39331 raise error.Abort(msg % raw)
Gregory Szorc
global: use raw strings for regular expressions with escapes...
r41673 if re.search(br'[^\w-]', k):
Augie Fackler
formatting: blacken the codebase...
r43346 msg = _(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"keys can only contain ascii letters, digits,"
b" '_' and '-'"
Augie Fackler
formatting: blacken the codebase...
r43346 )
Valentin Gatien-Baron
commitextras: no need to special case extras=[]...
r39331 raise error.Abort(msg)
if k in usedinternally:
Augie Fackler
formatting: blacken the codebase...
r43346 msg = _(
Augie Fackler
formatting: byteify all mercurial/ and hgext/ string literals...
r43347 b"key '%s' is used internally, can't be set "
b"manually"
Augie Fackler
formatting: blacken the codebase...
r43346 )
Valentin Gatien-Baron
commitextras: no need to special case extras=[]...
r39331 raise error.Abort(msg % k)
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 inneropts['extra'][k] = v
Valentin Gatien-Baron
commitextras: work nicely with other extensions...
r39330 return super(repoextra, self).commit(*innerpats, **inneropts)
Augie Fackler
formatting: blacken the codebase...
r43346
Valentin Gatien-Baron
commitextras: work nicely with other extensions...
r39330 repo.__class__ = repoextra
return orig(ui, repo, *pats, **opts)