Changeset View
Changeset View
Standalone View
Standalone View
support/hg/arc-hg.py
Show All 15 Lines | |||||
from mercurial import ( | from mercurial import ( | ||||
cmdutil, | cmdutil, | ||||
bookmarks, | bookmarks, | ||||
bundlerepo, | bundlerepo, | ||||
error, | error, | ||||
hg, | hg, | ||||
i18n, | i18n, | ||||
node, | node, | ||||
registrar, | |||||
) | ) | ||||
cspeckmim: Oops this isn't necessary, was doing some testing | |||||
_ = i18n._ | _ = i18n._ | ||||
cmdtable = {} | cmdtable = {} | ||||
# Older veresions of Mercurial (~4.7) moved the command function and the | |||||
# remoteopts object to different modules. Using try/except here to attempt | |||||
# allowing this module to load properly, despite whether individual commands | |||||
# will work properly on older versions of Mercurial or not. | |||||
# https://phab.mercurial-scm.org/rHG46ba2cdda476ac53a8a8f50e4d9435d88267db60 | |||||
# https://phab.mercurial-scm.org/rHG04baab18d60a5c833ab3190506147e01b3c6d12c | |||||
try: | |||||
from mercurial import registrar | |||||
command = registrar.command(cmdtable) | command = registrar.command(cmdtable) | ||||
except: | |||||
command = cmdutil.command(cmdtable) | |||||
try: | |||||
if "remoteopts" in cmdutil: | |||||
Done Inline ActionsThis will allow the extension module to load as far back as Mercurial 3.5, possibly earlier. I tested out a basic arc-ls-markers invocation and that seemed to work properly in 3.5 with this change cspeckmim: This will allow the extension module to load as far back as Mercurial 3.5, possibly earlier. I… | |||||
remoteopts = cmdutil.remoteopts | |||||
except: | |||||
from mercurial import commands | |||||
remoteopts = commands.remoteopts | |||||
@command( | |||||
b'arc-amend', | |||||
[ | |||||
(b'l', | |||||
b'logfile', | |||||
b'', | |||||
_(b'read commit message from file'), | |||||
_(b'FILE')), | |||||
(b'm', | |||||
b'message', | |||||
b'', | |||||
_(b'use text as commit message'), | |||||
_(b'TEXT')), | |||||
(b'u', | |||||
b'user', | |||||
b'', | |||||
_(b'record the specified user as committer'), | |||||
_(b'USER')), | |||||
(b'd', | |||||
b'date', | |||||
b'', | |||||
_(b'record the specified date as commit date'), | |||||
_(b'DATE')), | |||||
(b'A', | |||||
b'addremove', | |||||
False, | |||||
_(b'mark new/missing files as added/removed before committing')), | |||||
(b'n', | |||||
b'note', | |||||
b'', | |||||
_(b'store a note on amend'), | |||||
_(b'TEXT')), | |||||
], | |||||
_(b'[OPTION]')) | |||||
def amend(ui, repo, source=None, **opts): | |||||
"""amend | |||||
Uses Mercurial internal API to amend changes to a non-head commit. | |||||
(This is an Arcanist extension to Mercurial.) | |||||
Returns 0 if amending succeeds, 1 otherwise. | |||||
""" | |||||
Done Inline ActionsComment slightly outdated, we're not removing entries with empty values -- older Mercurial seems to depend on the entries being present despite being empty but newer Mercurial doesn't care cspeckmim: Comment slightly outdated, we're not removing entries with empty values -- older Mercurial… | |||||
# The option keys seem to come in as 'str' type but the cmdutil.amend() code | |||||
# expects them as binary. To account for both Python 2 and Python 3 | |||||
# compatibility, insert the value under both 'str' and binary type. | |||||
newopts = {} | |||||
for key in opts: | |||||
val = opts.get(key) | |||||
newopts[key] = val | |||||
if isinstance(key, str): | |||||
newkey = key.encode('UTF-8') | |||||
newopts[newkey] = val | |||||
orig = repo[b'.'] | |||||
extra = {} | |||||
pats = [] | |||||
cmdutil.amend(ui, repo, orig, extra, pats, newopts) | |||||
""" | |||||
# This will allow running amend on older versions of Mercurial, ~3.5, however | |||||
# the behavior on those versions will squash child commits of the working | |||||
# directory into the amended commit which is undesired. | |||||
try: | |||||
cmdutil.amend(ui, repo, orig, extra, pats, newopts) | |||||
except: | |||||
def commitfunc(ui, repo, message, match, opts): | |||||
return repo.commit( | |||||
message, | |||||
opts.get('user') or orig.user(), | |||||
opts.get('date') or orig.date(), | |||||
match, | |||||
Done Inline ActionsI took this from here However it ended up squashing in addition to the amending which will cause problems cspeckmim: I took this from here
https://phab.mercurial-scm. | |||||
extra=extra) | |||||
cmdutil.amend(ui, repo, commitfunc, orig, extra, pats, newopts) | |||||
""" | |||||
return 0 | |||||
@command( | @command( | ||||
b'arc-ls-markers', | b'arc-ls-markers', | ||||
[(b'', b'output', b'', | [ | ||||
_(b'file to output refs to'), _(b'FILE')), | (b'', | ||||
] + cmdutil.remoteopts, | b'output', | ||||
b'', | |||||
_(b'file to output refs to'), | |||||
_(b'FILE')), | |||||
] + remoteopts, | |||||
_(b'[--output FILENAME] [SOURCE]')) | _(b'[--output FILENAME] [SOURCE]')) | ||||
def lsmarkers(ui, repo, source=None, **opts): | def lsmarkers(ui, repo, source=None, **opts): | ||||
"""list markers | """list markers | ||||
Show the current branch heads and bookmarks in the local working copy, or | Show the current branch heads and bookmarks in the local working copy, or | ||||
Done Inline ActionsI wonder if this should inversely check for b'' keys and insert them as string keys as well, for the Python 2 v 3 situation. cspeckmim: I wonder if this should inversely check for `b''` keys and insert them as string keys as well… | |||||
a specified path/URL. | a specified path/URL. | ||||
Markers are printed to stdout in JSON. | Markers are printed to stdout in JSON. | ||||
(This is an Arcanist extension to Mercurial.) | (This is an Arcanist extension to Mercurial.) | ||||
Returns 0 if listing the markers succeeds, 1 otherwise. | Returns 0 if listing the markers succeeds, 1 otherwise. | ||||
""" | """ | ||||
▲ Show 20 Lines • Show All 151 Lines • Show Last 20 Lines |
Oops this isn't necessary, was doing some testing