git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] init: show "Reinit" message even in an (existing) empty repository
Date: Tue, 25 Mar 2008 00:35:18 -0700	[thread overview]
Message-ID: <7viqzbmf2h.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <alpine.LSU.1.00.0803241613480.4353@racer.site> (Johannes Schindelin's message of "Mon, 24 Mar 2008 16:14:52 +0100 (CET)")

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> diff --git a/builtin-init-db.c b/builtin-init-db.c
> index 1975910..ceb4727 100644
> --- a/builtin-init-db.c
> +++ b/builtin-init-db.c
> @@ -168,10 +168,9 @@ static int create_default_files(const char *git_dir, const char *template_path)
>  {
>  	unsigned len = strlen(git_dir);
>  	static char path[PATH_MAX];
> -	unsigned char sha1[20];
>  	struct stat st1;
>  	char repo_version_string[10];
> 	int reinit;

Here I saw a hand-edit, but that is less of a problem...

>  	int filemode;
>  
>  	if (len > sizeof(path)-50)
> @@ -220,7 +219,7 @@ static int create_default_files(const char *git_dir, const char *template_path)
>  	 * branch, if it does not exist yet.
>  	 */
>  	strcpy(path + len, "HEAD");
> -	reinit = !read_ref("HEAD", sha1);
> +	reinit = !access(path, R_OK);

If this is a HEAD (or .git/HEAD) that is a dangling symlink (we do still
support them, don't we?) wouldn't this access fail?

-- >8 --
From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Date: Mon, 24 Mar 2008 16:14:52 +0100
Subject: [PATCH] init: show "Reinit" message even in an (existing) empty repository

Earlier, git-init tested for a valid HEAD ref, but if the repository
was empty, there was none.  Instead, test for the existence of
the file $GIT_DIR/HEAD.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin-init-db.c |    5 +++--
 t/t0001-init.sh   |   17 +++++++++++++++++
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/builtin-init-db.c b/builtin-init-db.c
index 79eaf8d..2854868 100644
--- a/builtin-init-db.c
+++ b/builtin-init-db.c
@@ -167,9 +167,9 @@ static int create_default_files(const char *git_dir, const char *template_path)
 {
 	unsigned len = strlen(git_dir);
 	static char path[PATH_MAX];
-	unsigned char sha1[20];
 	struct stat st1;
 	char repo_version_string[10];
+	char junk[2];
 	int reinit;
 	int filemode;
 
@@ -219,7 +219,8 @@ static int create_default_files(const char *git_dir, const char *template_path)
 	 * branch, if it does not exist yet.
 	 */
 	strcpy(path + len, "HEAD");
-	reinit = !read_ref("HEAD", sha1);
+	reinit = (!access(path, R_OK)
+		  || readlink(path, junk, sizeof(junk)-1) != -1);
 	if (!reinit) {
 		if (create_symref("HEAD", "refs/heads/master", NULL) < 0)
 			exit(1);
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index c015405..b0289e3 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -113,4 +113,21 @@ test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' '
 	fi
 '
 
+test_expect_success 'reinit' '
+
+	(
+		unset GIT_CONFIG GIT_WORK_TREE GIT_CONFIG
+
+		mkdir again &&
+		cd again &&
+		git init >out1 2>err1 &&
+		git init >out2 2>err2
+	) &&
+	grep "Initialized empty" again/out1 &&
+	grep "Reinitialized existing" again/out2 &&
+	>again/empty &&
+	test_cmp again/empty again/err1 &&
+	test_cmp again/empty again/err2
+'
+
 test_done
-- 
1.5.5.rc1.121.g1594

  reply	other threads:[~2008-03-25  7:36 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <f5d99ae7-e4b3-4632-ad86-8ebe0e683d49@d62g2000hsf.googlegroups.com>
     [not found] ` <alpine.LSU.1.00.0803101327390.3975@racer.site>
     [not found]   ` <bdca99240803100611s3c8b3b9djb1b993c9fbad712@mail.gmail.com>
     [not found]     ` <alpine.LSU.1.00.0803101448430.3975@racer.site>
     [not found]       ` <cb8f4255-2bf8-4489-aeb0-c18d6e932342@s13g2000prd.googlegroups.com>
     [not found]         ` <ab311292-809f-4e45-a19d-a600c2333ab6@a23g2000hsc.googlegroups.com>
     [not found]           ` <alpine.OSX.1.00.0803221036230.7618@cougar>
     [not found]             ` <7vzlsqfe2h.fsf@gitster.siamese.dyndns.org>
     [not found]               ` <alpine.LSU.1.00.0803230310500.4353@racer.site>
2008-03-23  9:31                 ` Store autocrlf during init-db (was [msysGit] autocrlf problems with Git-preview20080301.exe) Steffen Prohaska
2008-03-23  9:34                   ` [PATCH] init-db: Store current value of autocrlf Steffen Prohaska
2008-03-24  0:16                     ` Dmitry Potapov
2008-03-23 11:01                   ` Store autocrlf during init-db (was [msysGit] autocrlf problems with Git-preview20080301.exe) Johannes Schindelin
2008-03-23 12:30                     ` Steffen Prohaska
2008-03-23 13:05                       ` [msysGit] " Johannes Schindelin
2008-03-23 13:42                         ` Steffen Prohaska
2008-03-23 14:07                           ` [msysGit] " Johannes Schindelin
2008-03-23 15:50                             ` Steffen Prohaska
2008-03-23 16:35                               ` Johannes Schindelin
2008-03-23 22:53                                 ` Steffen Prohaska
2008-03-23 23:39                                   ` [msysGit] " Johannes Schindelin
2008-03-23 23:56                           ` Dmitry Potapov
2008-03-24  0:01                             ` [msysGit] " Johannes Schindelin
2008-03-24  0:23                               ` Dmitry Potapov
2008-03-24 10:57                                 ` Johannes Schindelin
2008-03-24 12:21                                   ` Dmitry Potapov
2008-03-24 15:12                                     ` [PATCH] Introduce core.initHook Johannes Schindelin
2008-03-24 15:14                                       ` [PATCH] init: show "Reinit" message even in an (existing) empty repository Johannes Schindelin
2008-03-25  7:35                                         ` Junio C Hamano [this message]
2008-03-25  9:55                                           ` Johannes Schindelin
2008-03-24 20:25                                       ` [PATCH] Introduce core.initHook Junio C Hamano
2008-03-24 21:40                                         ` [PATCH v2] " Johannes Schindelin
2008-03-24 22:40                                           ` Junio C Hamano
2008-03-24 23:21                                             ` [PATCH v3] " Johannes Schindelin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7viqzbmf2h.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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 NNTP newsgroup(s).