unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH v3] nmbug: Add an 'init' command
@ 2014-10-28 21:39 W. Trevor King
  2014-11-29  9:40 ` Michal Sojka
  0 siblings, 1 reply; 4+ messages in thread
From: W. Trevor King @ 2014-10-28 21:39 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 (which doesn't exist on Windows, for example).

[1]: id:87y4vu6uvf.fsf@maritornes.cs.unb.ca
     http://thread.gmane.org/gmane.mail.notmuch.general/18626/focus=18720
---
The only change since v2 [1] is a commit-message tweak:

* Mention Windows as an OS with stdin but no /dev/null [2].

Cheers,
Trevor

[1]: id:eaa9cf1cb3c00c591dc675c0f314ca31909ff74c.1412965476.git.wking@tremily.us
     http://thread.gmane.org/gmane.mail.notmuch.general/19289
[2]: id:20141011071000.GB10926@odin.tremily.us
     http://article.gmane.org/gmane.mail.notmuch.general/19294

 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] 4+ messages in thread

* Re: [PATCH v3] nmbug: Add an 'init' command
  2014-10-28 21:39 [PATCH v3] nmbug: Add an 'init' command W. Trevor King
@ 2014-11-29  9:40 ` Michal Sojka
  2014-11-29 20:09   ` W. Trevor King
  0 siblings, 1 reply; 4+ messages in thread
From: Michal Sojka @ 2014-11-29  9:40 UTC (permalink / raw)
  To: W. Trevor King, notmuch

Hi Trevor,

On Út, říj 28 2014, W. Trevor King wrote:
> 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 (which doesn't exist on Windows, for example).
>
> [1]: id:87y4vu6uvf.fsf@maritornes.cs.unb.ca
>      http://thread.gmane.org/gmane.mail.notmuch.general/18626/focus=18720
> ---
> The only change since v2 [1] is a commit-message tweak:
>
> * Mention Windows as an OS with stdin but no /dev/null [2].
>
> Cheers,
> Trevor
>
> [1]: id:eaa9cf1cb3c00c591dc675c0f314ca31909ff74c.1412965476.git.wking@tremily.us
>      http://thread.gmane.org/gmane.mail.notmuch.general/19289
> [2]: id:20141011071000.GB10926@odin.tremily.us
>      http://article.gmane.org/gmane.mail.notmuch.general/19294
>
>  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)

Why do you create a non-bare repository and then make it bare? Before I
discovered this patch, I created the nmbug repository by hand and it was
possible to do it with bare repo from beginning. The following code
seems to work and is a bit simpler:

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.
    """
    _spawn(
        args=['git', '--git-dir', NMBGIT, 'init', '--bare'],
        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': NMBGIT},
        wait=True)

Note that in the initial commit I set the work tree to NMBGIT. This is
because 'git commit' needs some work tree, but in our case it doesn't
matter which one because the commit is empty.

-Michal


> +        # 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
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

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

* Re: [PATCH v3] nmbug: Add an 'init' command
  2014-11-29  9:40 ` Michal Sojka
@ 2014-11-29 20:09   ` W. Trevor King
  2014-11-29 20:18     ` W. Trevor King
  0 siblings, 1 reply; 4+ messages in thread
From: W. Trevor King @ 2014-11-29 20:09 UTC (permalink / raw)
  To: Michal Sojka; +Cc: notmuch

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

On Sat, Nov 29, 2014 at 10:40:01AM +0100, Michal Sojka wrote:
> On Út, říj 28 2014, W. Trevor King wrote:
> > +        _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)
> 
> Why do you create a non-bare repository and then make it bare?

Bare repositories don't usually have upstream tracking branches.  See
the commit message for c2001674 (nmbug: Add 'clone' and replace
FETCH_HEAD with @{upstream}, 2014-03-09) for details [1].  I can
resubmit this patch with a commit message that mentions the
explanation in c2001674 if folks want the extra clarity here.

Cheers,
Trevor

[1]: id:de7dd9d4021cd17350df4423bc13f3da35f2b324.1394410765.git.wking@tremily.us
     http://thread.gmane.org/gmane.mail.notmuch.general/17457

-- 
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] 4+ messages in thread

* Re: [PATCH v3] nmbug: Add an 'init' command
  2014-11-29 20:09   ` W. Trevor King
@ 2014-11-29 20:18     ` W. Trevor King
  0 siblings, 0 replies; 4+ messages in thread
From: W. Trevor King @ 2014-11-29 20:18 UTC (permalink / raw)
  To: Michal Sojka; +Cc: notmuch

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

On Sat, Nov 29, 2014 at 12:09:17PM -0800, W. Trevor King wrote:
> On Sat, Nov 29, 2014 at 10:40:01AM +0100, Michal Sojka wrote:
> > On Út, říj 28 2014, W. Trevor King wrote:
> > > +        _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)
> > 
> > Why do you create a non-bare repository and then make it bare?
> 
> Bare repositories don't usually have upstream tracking branches.  See
> the commit message for c2001674 (nmbug: Add 'clone' and replace
> FETCH_HEAD with @{upstream}, 2014-03-09) for details [1].  I can
> resubmit this patch with a commit message that mentions the
> explanation in c2001674 if folks want the extra clarity here.

Ah, it seems that the lack of remote-tracking branches is unique to
'clone --bare'.  When I compare 'init --bare' with the above (using
Git 2.1.0), the only difference in the resulting repository is that
the the 'init --bare' form doesn't set core.logallrefupdates, while
the form above sets core.logallrefupdates to true.  I'll submit v4
using 'init --bare' and an explicit core.logallrefupdates config.

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] 4+ messages in thread

end of thread, other threads:[~2014-11-29 20:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-28 21:39 [PATCH v3] nmbug: Add an 'init' command W. Trevor King
2014-11-29  9:40 ` Michal Sojka
2014-11-29 20:09   ` W. Trevor King
2014-11-29 20:18     ` 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).