[PATCH 51 of 55 RFC c-hglib:level1] hg_tip: creating a high level function for mercurial tip command

Martin Geisler martin at geisler.net
Sun Sep 15 10:25:08 UTC 2013


Giovanni Gherdovich <g.gherdovich at gmail.com> writes:

> Hello Idan and Iulian,
>
> 2013/9/15 Idan Kamara <idankk86 at gmail.com>:
>>
>> My comment was directed at making you question whether you really
>> want to allow the user to pass arbitrary arguments to this function
>> (and every other 'top level' function such as this).
>
> maybe "arbitrary options but not --template"...

In JavaHG we tried to create a type-safe interface to the commands.
Basically you call methods corresponding to each command line flag we
support. Each method sets the flag and returns "this" so you can chain
the calls. For c-hglib you could perhaps pass a struct to the command,
something like this where the default_log_command_flags function creates
a struct with the flags at default values:

  log_command_flags *flags = default_log_command_flags();
  flags->copies = TRUE;
  flags->user = "me";
  flags->branch = "stable";

You then pass the struct to the log command together with any positional
arguments:

  log_command_result *result = hg_log(cmd_server, flags, "README")

and iterate over the results in the way already agreed on.

In JavaHg this is implemented with the LogCommand class which is a
subclass of a LogCommandFlags class:

  https://bitbucket.org/aragost/javahg/src/tip/src/main/java/com/aragost/javahg/commands/LogCommand.java
  https://bitbucket.org/aragost/javahg/src/tip/src/main/java/com/aragost/javahg/commands/flags/LogCommandFlags.java

That class is auto-generated from 'hg help log'. We filter the flags
based on a blacklist of known flags that we don't want to support, such
as --template, --print0, --git, --dry-run. The idea is that the library
takes care of supplying a suitable template and adding --git since we
rely on the output format when parsing the output.

-- 
Martin Geisler
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 835 bytes
Desc: not available
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-devel/attachments/20130915/30e79b41/attachment.asc>


More information about the Mercurial-devel mailing list