* Re: [PATCH 4/4] git status: refresh the index
2010-04-02 12:27 ` [PATCH 4/4] git status: refresh " Markus Heidelberg
@ 2010-04-02 16:57 ` Jeff King
2010-04-02 20:37 ` Markus Heidelberg
2010-04-02 18:56 ` Junio C Hamano
2010-04-02 21:44 ` [PATCH v2 4/4] git status: refresh the index if possible Markus Heidelberg
2 siblings, 1 reply; 15+ messages in thread
From: Jeff King @ 2010-04-02 16:57 UTC (permalink / raw)
To: Markus Heidelberg; +Cc: Junio C Hamano, git
On Fri, Apr 02, 2010 at 02:27:21PM +0200, Markus Heidelberg wrote:
> + fd = hold_locked_index(&index_lock, 1);
> + if (write_cache(fd, active_cache, active_nr) ||
> + commit_locked_index(&index_lock))
> + die("unable to write new_index file");
Does this mean we will fail to run in a read-only repository? I think
that status, like diff, should refresh the index on disk if it _can_,
but as that refresh is a side effect of the main purpose (which is to
output information), it should not be fatal if it cannot do so.
-Peff
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 4/4] git status: refresh the index
2010-04-02 16:57 ` Jeff King
@ 2010-04-02 20:37 ` Markus Heidelberg
2010-04-02 21:21 ` Jeff King
0 siblings, 1 reply; 15+ messages in thread
From: Markus Heidelberg @ 2010-04-02 20:37 UTC (permalink / raw)
To: Jeff King; +Cc: Junio C Hamano, git
Jeff King, 2010-04-02 18:57:
> On Fri, Apr 02, 2010 at 02:27:21PM +0200, Markus Heidelberg wrote:
>
> > + fd = hold_locked_index(&index_lock, 1);
> > + if (write_cache(fd, active_cache, active_nr) ||
> > + commit_locked_index(&index_lock))
> > + die("unable to write new_index file");
>
> Does this mean we will fail to run in a read-only repository?
You're right.
But that was already the case when "status" was "commit --dry-run".
I have to admit, I didn't think about this scenario, but simply looked
for the differences between these two commands.
> I think
> that status, like diff, should refresh the index on disk if it _can_,
> but as that refresh is a side effect of the main purpose (which is to
> output information), it should not be fatal if it cannot do so.
Sounds sensible.
Markus
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 4/4] git status: refresh the index
2010-04-02 20:37 ` Markus Heidelberg
@ 2010-04-02 21:21 ` Jeff King
0 siblings, 0 replies; 15+ messages in thread
From: Jeff King @ 2010-04-02 21:21 UTC (permalink / raw)
To: Markus Heidelberg; +Cc: Junio C Hamano, git
On Fri, Apr 02, 2010 at 09:37:03PM +0100, Markus Heidelberg wrote:
> > Does this mean we will fail to run in a read-only repository?
>
> You're right.
> But that was already the case when "status" was "commit --dry-run".
> I have to admit, I didn't think about this scenario, but simply looked
> for the differences between these two commands.
Sort of. See ab68545 (status: don't require the repository to be
writable, 2010-01-19), which went onto maint while the "status is no
longer commit --dry-run" topic was cooking elsewhere. So I think it
would be a regression from 1.6.6.2 onwards.
At any rate, I think we all agree on what it _should_ do, so if you're
willing to do an updated patch, that would be great. The patch from
ab68545 may be helpful, as the code it changed is quite similar to what
you posted in this series.
-Peff
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 4/4] git status: refresh the index
2010-04-02 12:27 ` [PATCH 4/4] git status: refresh " Markus Heidelberg
2010-04-02 16:57 ` Jeff King
@ 2010-04-02 18:56 ` Junio C Hamano
2010-04-02 20:39 ` Markus Heidelberg
2010-04-02 21:44 ` [PATCH v2 4/4] git status: refresh the index if possible Markus Heidelberg
2 siblings, 1 reply; 15+ messages in thread
From: Junio C Hamano @ 2010-04-02 18:56 UTC (permalink / raw)
To: Markus Heidelberg; +Cc: git
Markus Heidelberg <markus.heidelberg@web.de> writes:
> This was already the case before commit 9e4b7ab6 (git status: not
> "commit --dry-run" anymore, 2009-08-15) and got lost during the
> conversion, which was meant to only change behaviour when invoked with
> arguments.
>
> Signed-off-by: Markus Heidelberg <markus.heidelberg@web.de>
> ---
> builtin/commit.c | 5 +++++
> t/t7508-status.sh | 2 +-
> 2 files changed, 6 insertions(+), 1 deletions(-)
>
> diff --git a/builtin/commit.c b/builtin/commit.c
> index c5ab683..2262734 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -1017,6 +1017,7 @@ static int git_status_config(const char *k, const char *v, void *cb)
> int cmd_status(int argc, const char **argv, const char *prefix)
> {
> struct wt_status s;
> + int fd;
> unsigned char sha1[20];
> static struct option builtin_status_options[] = {
> OPT__VERBOSE(&verbose),
> @@ -1050,6 +1051,10 @@ int cmd_status(int argc, const char **argv, const char *prefix)
>
> read_cache_preload(s.pathspec);
> refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, s.pathspec, NULL, NULL);
> + fd = hold_locked_index(&index_lock, 1);
> + if (write_cache(fd, active_cache, active_nr) ||
> + commit_locked_index(&index_lock))
> + die("unable to write new_index file");
This is a regression, I think.
The first two patches are trivially correct and I'll queue them to
'master'.
Thanks.
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH 4/4] git status: refresh the index
2010-04-02 18:56 ` Junio C Hamano
@ 2010-04-02 20:39 ` Markus Heidelberg
0 siblings, 0 replies; 15+ messages in thread
From: Markus Heidelberg @ 2010-04-02 20:39 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Junio C Hamano, 2010-04-02 20:56:
> Markus Heidelberg <markus.heidelberg@web.de> writes:
>
> > This was already the case before commit 9e4b7ab6 (git status: not
> > "commit --dry-run" anymore, 2009-08-15) and got lost during the
> > conversion, which was meant to only change behaviour when invoked with
> > arguments.
> >
> > Signed-off-by: Markus Heidelberg <markus.heidelberg@web.de>
> > ---
> > builtin/commit.c | 5 +++++
> > t/t7508-status.sh | 2 +-
> > 2 files changed, 6 insertions(+), 1 deletions(-)
> >
> > diff --git a/builtin/commit.c b/builtin/commit.c
> > index c5ab683..2262734 100644
> > --- a/builtin/commit.c
> > +++ b/builtin/commit.c
> > @@ -1017,6 +1017,7 @@ static int git_status_config(const char *k, const char *v, void *cb)
> > int cmd_status(int argc, const char **argv, const char *prefix)
> > {
> > struct wt_status s;
> > + int fd;
> > unsigned char sha1[20];
> > static struct option builtin_status_options[] = {
> > OPT__VERBOSE(&verbose),
> > @@ -1050,6 +1051,10 @@ int cmd_status(int argc, const char **argv, const char *prefix)
> >
> > read_cache_preload(s.pathspec);
> > refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, s.pathspec, NULL, NULL);
> > + fd = hold_locked_index(&index_lock, 1);
> > + if (write_cache(fd, active_cache, active_nr) ||
> > + commit_locked_index(&index_lock))
> > + die("unable to write new_index file");
>
> This is a regression, I think.
A regressions in comparison with the current behaviour, but not with the
former "commit --dry-run".
I'll send a second attempt without regression.
Markus
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH v2 4/4] git status: refresh the index if possible
2010-04-02 12:27 ` [PATCH 4/4] git status: refresh " Markus Heidelberg
2010-04-02 16:57 ` Jeff King
2010-04-02 18:56 ` Junio C Hamano
@ 2010-04-02 21:44 ` Markus Heidelberg
2010-04-03 4:33 ` Junio C Hamano
2 siblings, 1 reply; 15+ messages in thread
From: Markus Heidelberg @ 2010-04-02 21:44 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Jeff King, Markus Heidelberg
This was already the case before commit 9e4b7ab6 (git status: not
"commit --dry-run" anymore, 2009-08-15) with the difference that it died
at failure.
It got lost during the new implementation of "git status", which was
meant to only change behaviour when invoked with arguments.
Signed-off-by: Markus Heidelberg <markus.heidelberg@web.de>
---
v2:
Doesn't die when writing the index fails and so works for read-only
repositories.
Is rollback_lock_file(&index_lock) necessary? It isn't used in
"git commit --dry-run" when commit_style is COMMIT_AS_IS.
builtin/commit.c | 9 +++++++++
t/t7508-status.sh | 2 +-
2 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/builtin/commit.c b/builtin/commit.c
index c5ab683..3c14ade 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1017,6 +1017,7 @@ static int git_status_config(const char *k, const char *v, void *cb)
int cmd_status(int argc, const char **argv, const char *prefix)
{
struct wt_status s;
+ int fd;
unsigned char sha1[20];
static struct option builtin_status_options[] = {
OPT__VERBOSE(&verbose),
@@ -1050,6 +1051,14 @@ int cmd_status(int argc, const char **argv, const char *prefix)
read_cache_preload(s.pathspec);
refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, s.pathspec, NULL, NULL);
+
+ fd = hold_locked_index(&index_lock, 0);
+ if (0 <= fd) {
+ if (!write_cache(fd, active_cache, active_nr))
+ commit_locked_index(&index_lock);
+ rollback_lock_file(&index_lock);
+ }
+
s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
s.in_merge = in_merge;
wt_status_collect(&s);
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index 086ec3a..c317bde 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -499,7 +499,7 @@ test_expect_success 'dry-run of partial commit excluding new file in index' '
cat >expect <<EOF
:100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0000000000000000000000000000000000000000 M dir1/modified
EOF
-test_expect_failure 'status refreshes the index' '
+test_expect_success 'status refreshes the index' '
touch dir2/added &&
git status &&
git diff-files >output &&
--
1.7.0.4.300.ge0630
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v2 4/4] git status: refresh the index if possible
2010-04-02 21:44 ` [PATCH v2 4/4] git status: refresh the index if possible Markus Heidelberg
@ 2010-04-03 4:33 ` Junio C Hamano
2010-04-03 10:11 ` [PATCH] t7508: add a test for "git status" in a read-only repository Markus Heidelberg
2010-04-03 10:33 ` [PATCH v2 4/4] git status: refresh the index if possible Markus Heidelberg
0 siblings, 2 replies; 15+ messages in thread
From: Junio C Hamano @ 2010-04-03 4:33 UTC (permalink / raw)
To: Markus Heidelberg; +Cc: git, Jeff King
Markus Heidelberg <markus.heidelberg@web.de> writes:
> Is rollback_lock_file(&index_lock) necessary? It isn't used in
> "git commit --dry-run" when commit_style is COMMIT_AS_IS.
That is because AS_IS commit does not even lock anything for writing, as
AS_IS means just that: "git commit" does not touch the index but just
writes tree out of the index.
Upon program exit (unless you get an uncontrolled crash), the lockfile API
arranges atexit(3) to roll back the lockfiles, so it probably may not make
much of a difference if you omitted rollback_lock_file(&index_lock)
yourself, but it is a good idea to clean up the mess you made after you
are done, especially if the mess is not something the operating system
will clean up for us (e.g. open file descriptors, malloc'ed region of
memory etc.)
To make sure that the failure case is covered, you may also want to add a
test case where you run "chmod a-w $GIT_DIR" and then run status (but that
test needs to be conditional on POSIXPERM).
Thanks.
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH] t7508: add a test for "git status" in a read-only repository
2010-04-03 4:33 ` Junio C Hamano
@ 2010-04-03 10:11 ` Markus Heidelberg
2010-04-06 6:20 ` Junio C Hamano
2010-04-03 10:33 ` [PATCH v2 4/4] git status: refresh the index if possible Markus Heidelberg
1 sibling, 1 reply; 15+ messages in thread
From: Markus Heidelberg @ 2010-04-03 10:11 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Markus Heidelberg
Signed-off-by: Markus Heidelberg <markus.heidelberg@web.de>
---
t/t7508-status.sh | 10 ++++++++++
1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index c317bde..baa8d7b 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -703,4 +703,14 @@ test_expect_success 'commit --dry-run submodule summary (--amend)' '
test_cmp expect output
'
+test_expect_success POSIXPERM 'status succeeds in a read-only repository' '
+ (
+ chmod a-w .git &&
+ git status
+ )
+ status=$?
+ chmod 775 .git
+ (exit $status)
+'
+
test_done
--
1.7.0.4.304.gc2d16
^ permalink raw reply related [flat|nested] 15+ messages in thread
* Re: [PATCH v2 4/4] git status: refresh the index if possible
2010-04-03 4:33 ` Junio C Hamano
2010-04-03 10:11 ` [PATCH] t7508: add a test for "git status" in a read-only repository Markus Heidelberg
@ 2010-04-03 10:33 ` Markus Heidelberg
1 sibling, 0 replies; 15+ messages in thread
From: Markus Heidelberg @ 2010-04-03 10:33 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Jeff King
Junio C Hamano, 2010-04-03 06:33:
> Markus Heidelberg <markus.heidelberg@web.de> writes:
>
> > Is rollback_lock_file(&index_lock) necessary? It isn't used in
> > "git commit --dry-run" when commit_style is COMMIT_AS_IS.
>
> That is because AS_IS commit does not even lock anything for writing, as
> AS_IS means just that: "git commit" does not touch the index but just
> writes tree out of the index.
Hmm, it does lock and write the index, doesn't it?
/*
* As-is commit.
*
* (1) return the name of the real index file.
*
* The caller should run hooks on the real index,
* and create commit from the_index.
* We still need to refresh the index here.
*/
if (!pathspec || !*pathspec) {
fd = hold_locked_index(&index_lock, 1);
refresh_cache_or_die(refresh_flags);
if (write_cache(fd, active_cache, active_nr) ||
commit_locked_index(&index_lock))
die("unable to write new_index file");
commit_style = COMMIT_AS_IS;
return get_index_file();
}
$ stat .git/index
Access: 2010-04-03 12:31:11.000000000 +0200
Modify: 2010-04-03 12:31:11.000000000 +0200
Change: 2010-04-03 12:31:11.000000000 +0200
$ git commit --dry-run
$ stat .git/index
Access: 2010-04-03 12:31:52.000000000 +0200
Modify: 2010-04-03 12:31:52.000000000 +0200
Change: 2010-04-03 12:31:52.000000000 +0200
$ chmod a-w .git
$ git commit --dry-run
fatal: Unable to create '/home/markus/git/git/.git/index.lock': Permission denied
> Upon program exit (unless you get an uncontrolled crash), the lockfile API
> arranges atexit(3) to roll back the lockfiles, so it probably may not make
> much of a difference if you omitted rollback_lock_file(&index_lock)
> yourself, but it is a good idea to clean up the mess you made after you
> are done, especially if the mess is not something the operating system
> will clean up for us (e.g. open file descriptors, malloc'ed region of
> memory etc.)
Thanks for the explanation!
> To make sure that the failure case is covered, you may also want to add a
> test case where you run "chmod a-w $GIT_DIR" and then run status (but that
> test needs to be conditional on POSIXPERM).
Patch has been sent.
Markus
^ permalink raw reply [flat|nested] 15+ messages in thread