unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH v2] nmbug: Add an 'init' command
@ 2014-10-10 18:31 W. Trevor King
  2014-10-11  4:53 ` David Bremner
  0 siblings, 1 reply; 5+ messages in thread
From: W. Trevor King @ 2014-10-10 18:31 UTC (permalink / raw)
  To: notmuch

For folks that want to start versioning a new tag-space, instead of
cloning one that someone else has already started.

The empty-blob hash-object call avoids errors like:

  $ nmbug commit
  error: invalid object 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 for
'tags/...'
  fatal: git-write-tree: error building trees
  'git HASH(0x9ef3eb8) write-tree' exited with nonzero value

David Bremner suggested [1]:

  $ git hash-object -w /dev/null

instead of my Python version of:

  $ git hash-object -w --stdin <&-

but I expect that closing stdin is more portable than the /dev/null
path.

[1]: id:87y4vu6uvf.fsf@maritornes.cs.unb.ca
     http://thread.gmane.org/gmane.mail.notmuch.general/18626/focus=18720
---
This is just like v1 [1], but rebased into the new Python nmbug.  I'd
initially supported the /dev/null approach [2], but have since gone
back to my original --stdin approach for the empty blob object (as
explained in the commit message).  Sorry for waffling ;).

Cheers,
Trevor

[1]: id:05ccd672f55444f74da62250e2305fb84fdc6c42.1404678709.git.wking@tremily.us
     http://thread.gmane.org/gmane.mail.notmuch.general/18626/focus=18630
[2]: id:20140716001239.GH30232@odin
     http://article.gmane.org/gmane.mail.notmuch.general/18722
 devel/nmbug/nmbug | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/devel/nmbug/nmbug b/devel/nmbug/nmbug
index 9402ead..23bac5c 100755
--- a/devel/nmbug/nmbug
+++ b/devel/nmbug/nmbug
@@ -373,6 +373,29 @@ def fetch(remote=None):
     _git(args=args, wait=True)
 
 
+def init(remote=None):
+    """
+    Create an empty nmbug repository.
+
+    This wraps 'git init' with a few extra steps to support subsequent
+    status and commit commands.
+    """
+    with _tempfile.TemporaryDirectory(prefix='nmbug-init.') as workdir:
+        _spawn(
+            args=['git', 'init', '--separate-git-dir', NMBGIT, workdir],
+            wait=True)
+        _git(args=['config', '--unset', 'core.worktree'], wait=True)
+        _git(args=['config', 'core.bare', 'true'], wait=True)
+        # create an empty blob (e69de29bb2d1d6434b8b29ae775ad8c2e48c5391)
+        _git(args=['hash-object', '-w', '--stdin'], input='', wait=True)
+        _git(
+            args=[
+                'commit', '--allow-empty', '-m', 'Start a new nmbug repository'
+                ],
+            additional_env={'GIT_WORK_TREE': workdir},
+            wait=True)
+
+
 def checkout():
     """
     Update the notmuch database from Git.
@@ -703,6 +726,7 @@ if __name__ == '__main__':
             'clone',
             'commit',
             'fetch',
+            'init',
             'log',
             'merge',
             'pull',
-- 
2.1.0.60.g85f0837

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] nmbug: Add an 'init' command
  2014-10-10 18:31 [PATCH v2] nmbug: Add an 'init' command W. Trevor King
@ 2014-10-11  4:53 ` David Bremner
  2014-10-11  5:11   ` W. Trevor King
  0 siblings, 1 reply; 5+ messages in thread
From: David Bremner @ 2014-10-11  4:53 UTC (permalink / raw)
  To: W. Trevor King, notmuch

"W. Trevor King" <wking@tremily.us> writes:
>
> but I expect that closing stdin is more portable than the /dev/null
> path.

/dev/null is part of POSIX

          http://pubs.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap10.html

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] nmbug: Add an 'init' command
  2014-10-11  4:53 ` David Bremner
@ 2014-10-11  5:11   ` W. Trevor King
  2014-10-11  7:02     ` David Bremner
  0 siblings, 1 reply; 5+ messages in thread
From: W. Trevor King @ 2014-10-11  5:11 UTC (permalink / raw)
  To: David Bremner; +Cc: notmuch

[-- Attachment #1: Type: text/plain, Size: 874 bytes --]

On Sat, Oct 11, 2014 at 06:53:11AM +0200, David Bremner wrote:
> W. Trevor King writes:
> > but I expect that closing stdin is more portable than the /dev/null
> > path.
> 
> /dev/null is part of POSIX

Maybe folks want to use nmbug on Windows or some other crazy non-POSIX
OS?  I don't know how Windows-compatible the rest of notmuch is (it
looks like Xapian can be built with MSYS+mingw or MSVC [1,2]), and I
don't think supporting non-POSIX OSes is worth a lot of effort, but
using stdin instead here is easy ;).

Cheers,
Trevor

[1]: http://xapian.org/download (this seems to be down now, so see
     here [2] instead)
[2]: https://web.archive.org/web/20140902022239/http://xapian.org/download

-- 
This email may be signed or encrypted with GnuPG (http://www.gnupg.org).
For more information, see http://en.wikipedia.org/wiki/Pretty_Good_Privacy

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] nmbug: Add an 'init' command
  2014-10-11  5:11   ` W. Trevor King
@ 2014-10-11  7:02     ` David Bremner
  2014-10-11  7:10       ` W. Trevor King
  0 siblings, 1 reply; 5+ messages in thread
From: David Bremner @ 2014-10-11  7:02 UTC (permalink / raw)
  To: W. Trevor King; +Cc: notmuch

"W. Trevor King" <wking@tremily.us> writes:

> On Sat, Oct 11, 2014 at 06:53:11AM +0200, David Bremner wrote:
>> W. Trevor King writes:
>> > but I expect that closing stdin is more portable than the /dev/null
>> > path.
>> 
>> /dev/null is part of POSIX
>
> Maybe folks want to use nmbug on Windows or some other crazy non-POSIX
> OS?  I don't know how Windows-compatible the rest of notmuch is (it
> looks like Xapian can be built with MSYS+mingw or MSVC [1,2]), and I
> don't think supporting non-POSIX OSes is worth a lot of effort, but
> using stdin instead here is easy ;).

I have no objection to the code, but I think the comment about
portability just causes confusion. As witnessed by this discussion.

d

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] nmbug: Add an 'init' command
  2014-10-11  7:02     ` David Bremner
@ 2014-10-11  7:10       ` W. Trevor King
  0 siblings, 0 replies; 5+ messages in thread
From: W. Trevor King @ 2014-10-11  7:10 UTC (permalink / raw)
  To: David Bremner; +Cc: notmuch

[-- Attachment #1: Type: text/plain, Size: 1463 bytes --]

On Sat, Oct 11, 2014 at 09:02:20AM +0200, David Bremner wrote:
> W. Trevor King writes:
> > On Sat, Oct 11, 2014 at 06:53:11AM +0200, David Bremner wrote:
> >> W. Trevor King writes:
> >> > but I expect that closing stdin is more portable than the
> >> > /dev/null path.
> >> 
> >> /dev/null is part of POSIX
> >
> > Maybe folks want to use nmbug on Windows or some other crazy
> > non-POSIX OS?  I don't know how Windows-compatible the rest of
> > notmuch is (it looks like Xapian can be built with MSYS+mingw or
> > MSVC [1,2]), and I don't think supporting non-POSIX OSes is worth
> > a lot of effort, but using stdin instead here is easy ;).
> 
> I have no objection to the code, but I think the comment about
> portability just causes confusion. As witnessed by this discussion.

I wanted to explain why I wasn't using /dev/null, especially since
that's what the Perl version used and that phrasing is preserved in
the current comment:

  # magic hash for Git (git hash-object -t blob /dev/null)                        
  _EMPTYBLOB = 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'

So how should I more clearly explain why I prefer stdin to /dev/null?
Maybe “… is more portable than the /dev/null path (which doesn't exist
on Windows, for example).”?

Cheers,
Trevor

-- 
This email may be signed or encrypted with GnuPG (http://www.gnupg.org).
For more information, see http://en.wikipedia.org/wiki/Pretty_Good_Privacy

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-10-11  7:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-10 18:31 [PATCH v2] nmbug: Add an 'init' command W. Trevor King
2014-10-11  4:53 ` David Bremner
2014-10-11  5:11   ` W. Trevor King
2014-10-11  7:02     ` David Bremner
2014-10-11  7:10       ` W. Trevor King

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).