[PATCH] nmbug: Translate to Python

2014-07-21 Thread Jani Nikula
On Jul 21, 2014 12:43 AM, "W. Trevor King"  wrote:
>
>  devel/nmbug/nmbug | 1450
-
>  1 file changed, 755 insertions(+), 695 deletions(-)

See git format-patch --break-rewrites option.

BR,
Jani.
-- next part --
An HTML attachment was scrubbed...
URL: 



[PATCH] nmbug: Translate to Python

2014-07-20 Thread W. Trevor King
This allows us to capture stdout and stderr separately, and do other
explicit subprocess manipulation without resorting to external
packages.  It should be compatible with Python 2.6 and later
(including the 3.x series), although with 2.6 you'll need the external
argparse package.

Most of the user-facing interface is the same, but there are a few
changes, where reproducing the original interface was too difficult or
I saw a change to make the underlying Git UI accessible:

* 'nmbug help' has been split between the general 'nmbug --help' and
  the command-specific 'nmbug COMMAND --help'.

* Commands are no longer split into "most common", "other useful", and
  "less common" sets.  If we need something like this, I'd prefer
  workflow examples highlighting common commands in the module
  docstring (available with 'nmbug --help').

* The default repository for 'nmbug push' and 'nmbug fetch' is now the
  current branch's upstream (branch..remote) instead of
  'origin'.  When we have to, we extract this remote by hand, but
  where possible we just call the Git command without a repository
  argument, and leave it to Git to figure out the default.

* 'nmbug push' accepts multiple refspecs if you want to explicitly
  specify what to push.  Otherwise, the refspec(s) pushed depend on
  push.default.  The Perl version hardcoded 'master' as the pushed
  refspec.

* 'nmbug pull' defaults to the current branch's upstream
  (branch..remote and branch..merge) instead of hardcoding
  'origin' and 'master'.  It also supports multiple refspecs if for
  some crazy reason you need an octopus merge (but mostly to avoid
  breaking consistency with 'git pull').

* 'nmbug log' now execs 'git log', as there's no need to keep the
  Python process around once we've launched Git there.

* 'nmbug status' now catches stderr, and doesn't print errors like:

No upstream configured for branch 'master'

  The Perl implementation had just learned to avoid crashing on that
  case, but wasn't yet catching the dying subprocess's stderr.

* 'nmbug archive' now accepts positional arguments for the tree-ish
  and additional 'git archive' options.  For example, you can run:

$ nmbug archive HEAD -- --format tar.gz

  I wish I could have preserved the argument order from 'git archive'
  (with the tree-ish at the end), but I'm not sure how to make
  argparse accept arbitrary possitional arguments (some of which take
  arguments).  Flipping the order to put the tree-ish first seemed
  easiest.
---
As discussed here [1], this may also make it easier for others to
contribute.  A future patches can slot in the notmuch Python bindings,
which will likely be faster than spawning zillions of subprocesses to
check for message-id existence in get_status when there are many
maybe-deleted tags.

Once (if?) this lands, I'll submit an additional patch with the 'init'
command [2].

Cheers,
Trevor

[1]: id:87y4vt8vrw.fsf at maritornes.cs.unb.ca
 http://article.gmane.org/gmane.mail.notmuch.general/18729
[2]: id:05ccd672f55444f74da62250e2305fb84fdc6c42.1404678709.git.wking at 
tremily.us
 http://http://article.gmane.org/gmane.mail.notmuch.general/18630

 devel/nmbug/nmbug | 1450 -
 1 file changed, 755 insertions(+), 695 deletions(-)

diff --git a/devel/nmbug/nmbug b/devel/nmbug/nmbug
index 998ee6b..208f893 100755
--- a/devel/nmbug/nmbug
+++ b/devel/nmbug/nmbug
@@ -1,708 +1,768 @@
-#!/usr/bin/env perl
+#!/usr/bin/env python
 # Copyright (c) 2011 David Bremner
 # License: same as notmuch

-use strict;
-use warnings;
-use File::Temp qw(tempdir);
-use Pod::Usage;
-
-no encoding;
-
-my $NMBGIT = $ENV{NMBGIT} || $ENV{HOME}.'/.nmbug';
-
-$NMBGIT .= '/.git' if (-d $NMBGIT.'/.git');
-
-my $TAGPREFIX = defined($ENV{NMBPREFIX}) ? $ENV{NMBPREFIX} : 'notmuch::';
-
-# for encoding
-
-my $ESCAPE_CHAR =  '%';
-my $NO_ESCAPE =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.
-   '0123456789+-_@=.:,';
-my $MUST_ENCODE =  qr{[^\Q$NO_ESCAPE\E]};
-my $ESCAPED_RX =   qr{$ESCAPE_CHAR([A-Fa-f0-9]{2})};
-
-my %command = (
-archive=> \_archive,
-checkout   => \_checkout,
-clone  => \_clone,
-commit => \_commit,
-fetch  => \_fetch,
-help   => \_help,
-log=> \_log,
-merge  => \_merge,
-pull   => \_pull,
-push   => \_push,
-status => \_status,
-);
-
-# Convert prefix into form suitable for literal matching against
-# notmuch dump --format=batch-tag output.
-my $ENCPREFIX = encode_for_fs ($TAGPREFIX);
-$ENCPREFIX =~ s/:/%3a/g;
-
-my $subcommand = shift || usage ();
-
-if (!exists $command{$subcommand}) {
-  usage ();
-}
-
-# magic hash for git
-my $EMPTYBLOB = git (qw{hash-object -t blob /dev/null});
-
-&{$command{$subcommand}}(@ARGV);
-
-sub git_pipe {
-  my $envref = (ref $_[0] eq 

[PATCH] nmbug: Translate to Python

2014-07-20 Thread W. Trevor King
This allows us to capture stdout and stderr separately, and do other
explicit subprocess manipulation without resorting to external
packages.  It should be compatible with Python 2.6 and later
(including the 3.x series), although with 2.6 you'll need the external
argparse package.

Most of the user-facing interface is the same, but there are a few
changes, where reproducing the original interface was too difficult or
I saw a change to make the underlying Git UI accessible:

* 'nmbug help' has been split between the general 'nmbug --help' and
  the command-specific 'nmbug COMMAND --help'.

* Commands are no longer split into most common, other useful, and
  less common sets.  If we need something like this, I'd prefer
  workflow examples highlighting common commands in the module
  docstring (available with 'nmbug --help').

* The default repository for 'nmbug push' and 'nmbug fetch' is now the
  current branch's upstream (branch.name.remote) instead of
  'origin'.  When we have to, we extract this remote by hand, but
  where possible we just call the Git command without a repository
  argument, and leave it to Git to figure out the default.

* 'nmbug push' accepts multiple refspecs if you want to explicitly
  specify what to push.  Otherwise, the refspec(s) pushed depend on
  push.default.  The Perl version hardcoded 'master' as the pushed
  refspec.

* 'nmbug pull' defaults to the current branch's upstream
  (branch.name.remote and branch.name.merge) instead of hardcoding
  'origin' and 'master'.  It also supports multiple refspecs if for
  some crazy reason you need an octopus merge (but mostly to avoid
  breaking consistency with 'git pull').

* 'nmbug log' now execs 'git log', as there's no need to keep the
  Python process around once we've launched Git there.

* 'nmbug status' now catches stderr, and doesn't print errors like:

No upstream configured for branch 'master'

  The Perl implementation had just learned to avoid crashing on that
  case, but wasn't yet catching the dying subprocess's stderr.

* 'nmbug archive' now accepts positional arguments for the tree-ish
  and additional 'git archive' options.  For example, you can run:

$ nmbug archive HEAD -- --format tar.gz

  I wish I could have preserved the argument order from 'git archive'
  (with the tree-ish at the end), but I'm not sure how to make
  argparse accept arbitrary possitional arguments (some of which take
  arguments).  Flipping the order to put the tree-ish first seemed
  easiest.
---
As discussed here [1], this may also make it easier for others to
contribute.  A future patches can slot in the notmuch Python bindings,
which will likely be faster than spawning zillions of subprocesses to
check for message-id existence in get_status when there are many
maybe-deleted tags.

Once (if?) this lands, I'll submit an additional patch with the 'init'
command [2].

Cheers,
Trevor

[1]: id:87y4vt8vrw@maritornes.cs.unb.ca
 http://article.gmane.org/gmane.mail.notmuch.general/18729
[2]: id:05ccd672f55444f74da62250e2305fb84fdc6c42.1404678709.git.wk...@tremily.us
 http://http://article.gmane.org/gmane.mail.notmuch.general/18630

 devel/nmbug/nmbug | 1450 -
 1 file changed, 755 insertions(+), 695 deletions(-)

diff --git a/devel/nmbug/nmbug b/devel/nmbug/nmbug
index 998ee6b..208f893 100755
--- a/devel/nmbug/nmbug
+++ b/devel/nmbug/nmbug
@@ -1,708 +1,768 @@
-#!/usr/bin/env perl
+#!/usr/bin/env python
 # Copyright (c) 2011 David Bremner
 # License: same as notmuch
 
-use strict;
-use warnings;
-use File::Temp qw(tempdir);
-use Pod::Usage;
-
-no encoding;
-
-my $NMBGIT = $ENV{NMBGIT} || $ENV{HOME}.'/.nmbug';
-
-$NMBGIT .= '/.git' if (-d $NMBGIT.'/.git');
-
-my $TAGPREFIX = defined($ENV{NMBPREFIX}) ? $ENV{NMBPREFIX} : 'notmuch::';
-
-# for encoding
-
-my $ESCAPE_CHAR =  '%';
-my $NO_ESCAPE =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.
-   '0123456789+-_@=.:,';
-my $MUST_ENCODE =  qr{[^\Q$NO_ESCAPE\E]};
-my $ESCAPED_RX =   qr{$ESCAPE_CHAR([A-Fa-f0-9]{2})};
-
-my %command = (
-archive= \do_archive,
-checkout   = \do_checkout,
-clone  = \do_clone,
-commit = \do_commit,
-fetch  = \do_fetch,
-help   = \do_help,
-log= \do_log,
-merge  = \do_merge,
-pull   = \do_pull,
-push   = \do_push,
-status = \do_status,
-);
-
-# Convert prefix into form suitable for literal matching against
-# notmuch dump --format=batch-tag output.
-my $ENCPREFIX = encode_for_fs ($TAGPREFIX);
-$ENCPREFIX =~ s/:/%3a/g;
-
-my $subcommand = shift || usage ();
-
-if (!exists $command{$subcommand}) {
-  usage ();
-}
-
-# magic hash for git
-my $EMPTYBLOB = git (qw{hash-object -t blob /dev/null});
-
-{$command{$subcommand}}(@ARGV);
-
-sub git_pipe {
-  my $envref = (ref $_[0] 

Re: [PATCH] nmbug: Translate to Python

2014-07-20 Thread Jani Nikula
On Jul 21, 2014 12:43 AM, W. Trevor King wk...@tremily.us wrote:

  devel/nmbug/nmbug | 1450
-
  1 file changed, 755 insertions(+), 695 deletions(-)

See git format-patch --break-rewrites option.

BR,
Jani.
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch