Commit Graph

982 Commits

Author SHA1 Message Date
Martin von Zweigbergk
0016bace9c amend: use context manager for locking 2017-06-19 11:21:37 -07:00
Yuya Nishihara
1e4e9f46f4 commit: select template by spec.ref name
And load all templates defined in [committemplate] since the selected
template is no longer be named as 'changeset'.
2017-04-22 20:29:45 +09:00
Yuya Nishihara
762b9db3ef commit: do not look up committemplate in template paths (BC)
From 0b3f9fe7a730 and 5b9e4c6dd140, I don't think the current behavior is
intended. Commit templates should be processed as literal templates.
2017-04-22 15:28:29 +09:00
Yuya Nishihara
75bcdb63fb formatter: load templates section like a map file
Since a map file has another level to select a template (spec -> mapfile
-> topic), this isn't exactly the same as how a map file works. But I believe
most users would expect the new behavior.

A literal template is stored as an unnamed template so that it will never
conflict with the templates defined in [templates] section.
2017-04-22 20:14:55 +09:00
Yuya Nishihara
41654e97a9 templater: add simple interface for unnamed template (API)
This provides a simpler API for callers which don't need full templating
stack. Instead of storing the given template as the name specified by topic,
use '' as the default template to be rendered.
2017-04-22 19:56:47 +09:00
Pulkit Goyal
dee99e29f8 py3: explicitly convert dict.values() to a list on py3
dict.values() returns a dict_values() object, so we need to pass it into
list() explicitly to get one.
2017-06-16 01:28:23 +05:30
Yuya Nishihara
10f4660637 changeset_templater: render template specified by templatespec tuple 2017-04-11 21:38:24 +09:00
Yuya Nishihara
4fc90a661f formatter: put topic in templatespec tuple
This will allow us to change the initial template reference depending on how
the template is looked up. For example,

  -Tdefault => (ref='changeset', tmpl=None, mapfile='map-cmdline.default')
  -T'{rev}' => (ref='', tmpl='{rev}', mapfile=None)

A literal template given by -T option will be stored as an unnamed template,
which will free up the template namespace so that we can load named templates
from [templates] section of user config.
2017-04-22 19:07:00 +09:00
Yuya Nishihara
5249aa5b36 cmdutil: pass templatespec tuple directly to changeset_templater (API)
A fewer number of arguments should be better.
2017-04-22 19:02:47 +09:00
Yuya Nishihara
7242ce7327 formatter: wrap (tmpl, mapfile) by named tuple
I'm going to add more options to the templatespec tuple.

cmdutil.logtemplatespec() is just an alias now, but it will be changed to
a factory function later.
2017-04-22 18:48:38 +09:00
Yuya Nishihara
ca018ac743 cmdutil: factor out helper to create changeset_templater with literal template
changeset_templater has lots of arguments, but most callers only need to
specify a literal template 'tmpl'.

"hg debugtemplate" has no diff option, which means 'opts' were effectively {},
so dropped opts.
2017-04-22 18:42:03 +09:00
Yuya Nishihara
a0674d4810 formatter: document lookuptemplate() 2017-05-06 16:24:21 +09:00
Yuya Nishihara
c4a72a1290 cmdutil: rename gettemplate() to _lookuplogtemplate()
This function is only useful when processing log options.
2017-04-22 15:30:27 +09:00
Yuya Nishihara
cb89cb49a0 formatter: factor out function to create templater from literal or map file
(tmpl, mapfile) will be packed into a named tuple later.
2017-04-22 15:06:06 +09:00
Yuya Nishihara
8712d0ee3b graphlog: do not look up graphnodetemplate in template paths (BC)
ui.graphnodetemplate config should be a literal template as ui.logtemplate is.
The use of formatter.gettemplater() is valid only for a template string
given by -T/--template option.
2017-04-22 14:53:05 +09:00
Sean Farley
1221c3301c context: inline makememctx (API)
I have always thought it weird that we have a helper method instead of
just using __init__. So, I ripped it out.
2017-06-10 10:24:33 -04:00
Yuya Nishihara
d2ef5f6afb export: map wctx.node() to 'ff...' node id (issue5438) 2017-06-03 19:17:19 +09:00
Yuya Nishihara
32b5726eef scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
It seemed silly to convert ctx.hex() back to binary to use node.hex/short(),
or to use [:12] instead of node.short() because ctx.node() could be None.

Eventually I want to change wctx.rev() and wctx.node() to return wdirrev and
wdirid respectively, but that's quite big API breakage and can't be achieved
without some compatibility wrappers.
2017-06-03 19:12:01 +09:00
Yuya Nishihara
ca7d54c6e1 scmutil: pass ctx object to intrev()
This makes it slightly easier to sort basectx objects by key=scmutil.intrev.
We're most likely to have ctx objects where changectx/workingctx abstraction
is necessary, so this won't increase the abstraction overhead.
2017-06-03 18:57:28 +09:00
Yuya Nishihara
f287cab367 cmdutil: use isstdiofilename() where appropriate 2017-06-01 23:08:23 +09:00
Yuya Nishihara
eff4d5e967 cat: add formatter support
This is an example showing how formatter can handle the --output option.
git subrepo isn't supported for now.
2017-05-25 21:53:44 +09:00
Yuya Nishihara
4980841c12 cat: use with statement to close output file 2017-05-27 17:58:36 +09:00
Yuya Nishihara
de43565bcb cat: stop using makefileobj()
Prepares for porting to the formatter API. We won't be able to utilize the
abstraction provided by makefilename() because formatter must be instantiated
per file.
2017-05-25 21:43:09 +09:00
Yuya Nishihara
1d54e26edc cat: pass filename template as explicit argument
I'll move the handling of the '-' filename to commands.cat().
2017-05-27 18:50:05 +09:00
Yuya Nishihara
3070054965 cmdutil: extract function checking if pattern should be taken as stdin/out
This will be used in commands.cat().
2017-05-25 21:28:08 +09:00
Yuya Nishihara
c171e2c0bc cmdutil: drop deprecated hack to pass file object to makefileobj() (API)
All callers pass a string 'pat' or None.
2017-05-25 21:25:49 +09:00
Augie Fackler
fa101cc823 cmdutil: use sorted(dict) instead of x = dict.keys(); x.sort()
The former both does less work and has the virtue of working on Python 3.
2017-05-28 14:02:14 -04:00
Augie Fackler
b90ae820de cmdutil: avoid redefining write() function in export if possible
Doing less work inside the loop just feels better to me.
2017-05-22 15:05:18 -04:00
Augie Fackler
cab9b6d957 cmdutil: extract closure that performs the actual export formatting
This simplifies things a little by making the actual act of turning a
revision into patch data a single function. After this, adding
formatter support to `hg export` should be much simpler.
2017-05-22 13:34:03 -04:00
Augie Fackler
c84213bcdd cmdutil: use a generator expression instead of a list comprehension 2017-05-22 13:35:22 -04:00
Augie Fackler
414ee4894d cmdutil: rename template param to export to fntemplate
It's actually a template for the filename, not a formatter template.
2017-05-20 20:15:05 -04:00
Augie Fackler
47d21819fe cmdutil: comprehensively document the interface of export
I want to make some improvements here, but in order to make future
patches easier to review I want to document the current state of the
world.
2017-05-20 17:58:04 -04:00
Martin von Zweigbergk
d0f5db29a6 cleanup: reuse existing wctx variables instead of calling repo[None]
Incidentally, this apparently means we load .hgsub one time less as
well, which affects a test case.
2017-05-20 22:27:52 -07:00
Yuya Nishihara
6c2103bc71 commands: move templates of common command options to cmdutil (API)
The goal is to get rid of the debugcommands -> commands dependency.

Since globalopts is the property of the commands, it's kept in the commands
module.
2017-05-14 16:19:47 +09:00
Augie Fackler
b92dbee43c cmdutil: use repo[None].walk instead of repo.walk 2017-05-18 18:00:52 -04:00
Yuya Nishihara
7b77796abc extensions: show deprecation warning for the use of cmdutil.command
Since this is a fundamental API for extensions, we set 1-year period until
actually removing it.
2016-01-09 23:24:52 +09:00
Yuya Nishihara
3e663dde68 registrar: move cmdutil.command to registrar module (API)
cmdutil.command wasn't a member of the registrar framework only for a
historical reason. Let's make that happen. This patch keeps cmdutil.command
as an alias for extension compatibility.
2016-01-09 23:07:20 +09:00
Durham Goode
77dcefda06 obsolete: add operation metadata to rebase/amend/histedit obsmarkers
By recording what operation created the obsmarker, we can show very intuitive
messages to the user in various UIs. For instance, log output could have
messages like "Amended as XXX" to show why a commit is old and has an 'x' on it.

     @  ac28e3  durham
    /   First commit
   |
   | o  d4afe7 durham
   | |  Second commit
   | |
   | x  8e9a5d (Amended as ac28e3)  durham
   |/   First commit
   |
2017-05-09 16:29:31 -07:00
Martin von Zweigbergk
c3406ac3db cleanup: use set literals
We no longer support Python 2.6, so we can now use set literals.
2017-02-10 16:56:29 -08:00
Pulkit Goyal
edb3048605 py3: convert kwargs' keys to str using pycompat.strkwargs 2017-05-04 00:24:21 +05:30
Martin von Zweigbergk
0a45a04c8a forget: access status fields by name, not index 2017-05-04 21:11:40 -07:00
Pulkit Goyal
b69219d4a1 py3: use %d to format integers into bytestrings 2017-05-05 01:41:54 +05:30
Pulkit Goyal
7b5053db1f py3: slice over bytes to prevent getting ascii values 2017-05-05 01:26:13 +05:30
Pulkit Goyal
5e026b2f2b py3: handle opts correctly for hg add
opts in add command were passed again to cmdutil.add() as kwargs so we need
to convert them again to str. Intstead we convert them to bytes when passing
scmutil.match(). Opts handling is also corrected for all the functions which
are called from cmdutil.add().
2017-04-25 01:52:30 +05:30
Pulkit Goyal
deceb69003 py3: convert opts to bytes in cmdutil.dorecord()
commands.commit() calls cmdutil.dorecord() where opts are passed as unicodes
being keyword arguments. This patch converts them back to bytes as they are
required.
2017-04-21 02:20:46 +05:30
Yuya Nishihara
9466c3179f commit: optionally strip quotes from commit template (BC)
For consistency with the other template options.
2017-02-25 19:32:39 +09:00
Yuya Nishihara
5fbb2d3cd5 graphlog: optionally strip quotes from graphnode template (BC)
For consistency with the other template options.
2017-02-25 19:28:16 +09:00
Matt Harbison
6d898e296f serve: add support for Mercurial subrepositories
I've been using `hg serve --web-conf ...` with a simple '/=projects/**' [paths]
configuration for awhile without issue.  Let's ditch the need for the manual
configuration in this case, and limit the repos served to the actual subrepos.

This doesn't attempt to handle the case where a new subrepo appears while the
server is running.  That could probably be handled with a hook if somebody wants
it.  But it's such a rare case, it probably doesn't matter for the temporary
serves.

The main repo is served at '/', just like a repository without subrepos.  I'm
not sure why the duplicate 'adding ...' lines appear on Linux.  They don't
appear on Windows (see 3f4ff1bdf101), so they are optional.

Subrepositories that are configured with '../path' or absolute paths are not
cloneable from the server.  (They aren't cloneable locally either, unless they
also exist at their configured source, perhaps via the share extension.)  They
are still served, so that they can be browsed, or cloned individually.  If we
care about that cloning someday, we can probably just add the extra entries to
the webconf dictionary.  Even if the entries use '../' to escape the root, only
the related subrepositories would end up in the dictionary.
2017-04-15 18:05:40 -04:00
Yuya Nishihara
caee220313 templater: provide loop counter as "index" keyword
This was originally written for JSON templating where we would have to be
careful to not add extra comma, but seems generally useful.

Inner loop started by % operator has its own counter.
2016-04-22 21:46:33 +09:00
Denis Laxalde
2ae8148594 cmdutil: add a "changeset.obsolete" label in changeset_printer
Until now there were no label to highlight obsolete changesets in log output,
only evolution troubles (unstable, bumped, divergent) are supported. We add a
"changeset.obsolete" label on changeset entries produced by changeset_printer
so that obsolete changesets can be highlighted in log output. This is useful
because, unless using a graph log where obsolete changesets have a 'x' marker,
there's no way to identify obsolete changesets. And even in graph mode, when
working directory's parent is obsolete, we get a '@' marker and we do not see
it as obsolete.
2017-03-25 09:39:07 +01:00