From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-6.3 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by dcvr.yhbt.net (Postfix) with ESMTP id 9605D20179 for ; Sun, 3 Jul 2016 08:00:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752337AbcGCIAS (ORCPT ); Sun, 3 Jul 2016 04:00:18 -0400 Received: from sub3.mail.dreamhost.com ([69.163.253.7]:55593 "EHLO homiemail-a21.g.dreamhost.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752178AbcGCIAM (ORCPT ); Sun, 3 Jul 2016 04:00:12 -0400 Received: from homiemail-a21.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a21.g.dreamhost.com (Postfix) with ESMTP id 8625C30009A; Sun, 3 Jul 2016 00:58:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=novalis.org; h=from:to:cc :subject:date:message-id:in-reply-to:references; s=novalis.org; bh=ojfblf+Fi2U6WIAMq5Zl+K5E4Kk=; b=Hp6SBn034F2vuN9y2nPjsxASTqpj uZt++Cmjthn2gygFnMFWWnTEB2byGlRd7EihrIceC1s5ymECR8933WbkXlrIZNov +TzkFLIgSiDl44lT4RiVRcYqAX02fhlMeT0XtuhIQedIMpr4bLWLI4kZTQ+Kmfsd XHF3vQ3oPQny2OA= Received: from frank.cable.rcn.com (207-38-164-98.c3-0.43d-ubr2.qens-43d.ny.cable.rcn.com [207.38.164.98]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: novalis@novalis.org) by homiemail-a21.g.dreamhost.com (Postfix) with ESMTPSA id D589C30007B; Sun, 3 Jul 2016 00:58:41 -0700 (PDT) From: David Turner To: git@vger.kernel.org, pclouds@gmail.com, kmaggg@gmail.com Cc: David Turner , Junio C Hamano Subject: [PATCH v14 17/21] index-helper: autorun mode Date: Sun, 3 Jul 2016 03:58:09 -0400 Message-Id: <1467532693-20017-18-git-send-email-novalis@novalis.org> X-Mailer: git-send-email 2.8.0.rc4.11.g9232872.dirty In-Reply-To: <1467532693-20017-1-git-send-email-novalis@novalis.org> References: <1467532693-20017-1-git-send-email-novalis@novalis.org> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: David Turner Soon, we'll want to automatically start index-helper, so we need a mode that silently exits if it can't start up (either because it's not in a git dir, or because another one is already running). Signed-off-by: David Turner Signed-off-by: Junio C Hamano --- Documentation/git-index-helper.txt | 4 ++++ index-helper.c | 29 +++++++++++++++++++++++------ t/t7900-index-helper.sh | 8 ++++++++ 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/Documentation/git-index-helper.txt b/Documentation/git-index-helper.txt index 6f63a9e..eea5a38 100644 --- a/Documentation/git-index-helper.txt +++ b/Documentation/git-index-helper.txt @@ -43,6 +43,10 @@ OPTIONS --kill:: Kill any running index-helper and clean up the socket +--autorun:: + If index-helper is not already running, start it. Else, do + nothing. + NOTES ----- diff --git a/index-helper.c b/index-helper.c index feb09fb..af35485 100644 --- a/index-helper.c +++ b/index-helper.c @@ -381,8 +381,9 @@ static void request_kill(void) int main(int argc, char **argv) { const char *prefix; - int idle_in_seconds = 600, detach = 0, kill = 0; + int idle_in_seconds = 600, detach = 0, kill = 0, autorun = 0; int fd; + int nongit; struct strbuf socket_path = STRBUF_INIT; struct option options[] = { OPT_INTEGER(0, "exit-after", &idle_in_seconds, @@ -391,6 +392,7 @@ int main(int argc, char **argv) N_("verify shared memory after creating")), OPT_BOOL(0, "detach", &detach, N_("detach the process")), OPT_BOOL(0, "kill", &kill, N_("request that existing index helper processes exit")), + OPT_BOOL(0, "autorun", &autorun, N_("this is an automatic run of git index-helper, so certain errors can be solved by silently exiting")), OPT_END() }; @@ -400,7 +402,14 @@ int main(int argc, char **argv) if (argc == 2 && !strcmp(argv[1], "-h")) usage_with_options(usage_text, options); - prefix = setup_git_directory(); + prefix = setup_git_directory_gently(&nongit); + if (nongit) { + if (autorun) + exit(0); + else + die(_("not a git repository")); + } + if (parse_options(argc, (const char **)argv, prefix, options, usage_text, 0)) die(_("too many arguments")); @@ -414,10 +423,18 @@ int main(int argc, char **argv) /* check that no other copy is running */ fd = unix_stream_connect(git_path("index-helper.sock")); - if (fd >= 0) - die(_("Already running")); - if (errno != ECONNREFUSED && errno != ENOENT) - die_errno(_("Unexpected error checking socket")); + if (fd >= 0) { + if (autorun) + exit(0); + else + die(_("Already running")); + } + if (errno != ECONNREFUSED && errno != ENOENT) { + if (autorun) + return 0; + else + die_errno(_("Unexpected error checking socket")); + } atexit(cleanup); sigchain_push_common(cleanup_on_signal); diff --git a/t/t7900-index-helper.sh b/t/t7900-index-helper.sh index 21f1358..7f72e94 100755 --- a/t/t7900-index-helper.sh +++ b/t/t7900-index-helper.sh @@ -40,4 +40,12 @@ test_expect_success 'index-helper will not start if already running' ' grep "Already running" err ' +test_expect_success 'index-helper is quiet with --autorun' ' + test_when_finished "git index-helper --kill" && + git index-helper --kill && + git index-helper --detach && + test -S .git/index-helper.sock && + git index-helper --autorun +' + test_done -- 1.9.1