[PATCH V2] extensions: add onsub extension

Angel Ezquerra angel.ezquerra at gmail.com
Sun Oct 12 13:03:18 CDT 2014


On Sun, Oct 12, 2014 at 5:40 PM, Yuya Nishihara <yuya at tcha.org> wrote:
> On Sun, 12 Oct 2014 16:09:15 +0200, Angel Ezquerra wrote:
>> # HG changeset patch
>> # User Angel Ezquerra <angel.ezquerra at gmail.com>
>> # Date 1409641307 -7200
>> #      Tue Sep 02 09:01:47 2014 +0200
>> # Node ID 76a648d782cfadf1dac3dbc194a8ffc74c385cb5
>> # Parent  1533e642262de32c5a2445789710f49237019fd6
>> extensions: add onsub extension
>
>> +    def execCmd(sub, cmd, kind):
>> +        """if sub == None, cmd is executed inside repo; else, inside sub.
>> +        If cmd == None, do nothing. If cmd == '', do only the print0 (if needed).
>> +        Else, do either print0 or the debugging message, then execute the command.
>> +        kind is the type of the (sub)repo.
>> +        """
>> +        if sub == None:
>> +            envargdict = dict(HG_SUBPATH='.',
>> +                              HG_SUBURL='.',
>> +                              HG_SUBSTATE=repo['.'].hex(),
>> +                              HG_REPO=repo.root,
>> +                              HG_SUBTYPE=kind)
>> +            relpath = '.'
>> +            cmdwd = repo.root
>> +        else:
>> +            # subrepo.relpath was renamed to subrepo.subrelpath in
>> +            # 18b5b6392fcf.
>> +            if hasattr(subrepo, 'relpath'):
>> +                relpath = subrepo.relpath(sub)
>> +            else:
>> +                relpath = subrepo.subrelpath(sub)
>> +            envargdict = dict(HG_SUBPATH=relpath,
>> +                              HG_SUBURL=sub._path,
>> +                              HG_SUBSTATE=sub._state[1],
>> +                              HG_REPO=repo.root,
>> +                              HG_SUBTYPE=kind)
>> +            cmdwd = os.path.join(repo.root, relpath)
>> +        if cmd != None and (repotypefilter == '' or repotypefilter == kind):
>> +            if print0:
>> +                ui.write(relpath, "\0")
>> +            if cmd != '':
>> +                if not print0: ui.note(_("executing '%s' in %s\n") % (cmd, relpath))
>> +                util.system(cmd, environ=envargdict, cwd=cmdwd, onerr=onerr,
>> +                            errprefix=_('terminated onsub in %s') % relpath)
>
> I didn't look through the onsub extension, but this util.system() call will
> break the command-server channel.
>
> https://bitbucket.org/tortoisehg/thg/issue/3924/
> (no response yet, as usual)

Wow, that seems easy to get wrong! I can fix it following your
suggestion in that bitbucket issue and send it again.

I did a quick search of util.system calls in mercurial's code base and
I found one in sshpeer.py, line 55:

res = util.system(cmd)

There is another one in the last line of hgk.py.

Should those be changed then?

Cheers,

Angel


More information about the Mercurial-devel mailing list