From 2b5f9a8c0cff511f2bb0833b1ee02645b79323f4 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 22 Feb 2007 00:28:49 -0800 Subject: [PATCH 1/3] git-status: do not be totally useless in a read-only repository. This makes git-status work semi-decently in a read-only repository. Earlier, the command simply died with "cannot lock the index file" before giving any useful information to the user. Because index won't be updated in a read-only repository, stat-dirty paths appear in the "Changed but not updated" list. Signed-off-by: Junio C Hamano --- git-commit.sh | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/git-commit.sh b/git-commit.sh index ec506d956f..cfa15110f6 100755 --- a/git-commit.sh +++ b/git-commit.sh @@ -13,10 +13,10 @@ git-rev-parse --verify HEAD >/dev/null 2>&1 || initial_commit=t case "$0" in *status) status_only=t - unmerged_ok_if_status=--unmerged ;; + ;; *commit) status_only= - unmerged_ok_if_status= ;; + ;; esac refuse_partial () { @@ -389,16 +389,17 @@ else USE_INDEX="$THIS_INDEX" fi -GIT_INDEX_FILE="$USE_INDEX" \ - git-update-index -q $unmerged_ok_if_status --refresh || exit - -################################################################ -# If the request is status, just show it and exit. - -case "$0" in -*status) +case "$status_only" in +t) + # This will silently fail in a read-only repository, which is + # what we want. + GIT_INDEX_FILE="$USE_INDEX" git-update-index -q --unmerged --refresh run_status exit $? + ;; +'') + GIT_INDEX_FILE="$USE_INDEX" git-update-index -q --refresh || exit + ;; esac ################################################################ From 7b802b86a6734a47c964d84922af2a016d836882 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 22 Feb 2007 00:30:45 -0800 Subject: [PATCH 2/3] update-index: do not die too early in a read-only repository. This delays the error exit from hold_lock_file_for_update() in update-index, so that "update-index --refresh" in a read-only repository can still report what paths are stat-dirty before exiting. Also it makes -q to squelch the error message. Signed-off-by: Junio C Hamano --- builtin-update-index.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/builtin-update-index.c b/builtin-update-index.c index 1ac613a788..3fbdc67b88 100644 --- a/builtin-update-index.c +++ b/builtin-update-index.c @@ -486,6 +486,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) int prefix_length = prefix ? strlen(prefix) : 0; char set_executable_bit = 0; unsigned int refresh_flags = 0; + int lock_error = 0; struct lock_file *lock_file; git_config(git_default_config); @@ -493,7 +494,9 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) /* We can't free this memory, it becomes part of a linked list parsed atexit() */ lock_file = xcalloc(1, sizeof(struct lock_file)); - newfd = hold_lock_file_for_update(lock_file, get_index_file(), 1); + newfd = hold_lock_file_for_update(lock_file, get_index_file(), 0); + if (newfd < 0) + lock_error = errno; entries = read_cache(); if (entries < 0) @@ -650,6 +653,12 @@ int cmd_update_index(int argc, const char **argv, const char *prefix) finish: if (active_cache_changed) { + if (newfd < 0) { + if (refresh_flags & REFRESH_QUIET) + exit(128); + die("unable to create '%s.lock': %s", + get_index_file(), strerror(lock_error)); + } if (write_cache(newfd, active_cache, active_nr) || close(newfd) || commit_lock_file(lock_file)) die("Unable to write new index file"); From b4e1e4a787d3771f617182b3344dcdd9224bd0cb Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 9 Feb 2007 18:51:40 -0800 Subject: [PATCH 3/3] run_diff_{files,index}(): update calling convention. They used to open and read index themselves, but they now expect their callers to do so. Signed-off-by: Junio C Hamano --- builtin-diff-files.c | 4 ++++ builtin-diff-index.c | 4 ++++ builtin-diff.c | 8 ++++++++ diff-lib.c | 10 +--------- wt-status.c | 12 ++++++++++-- 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/builtin-diff-files.c b/builtin-diff-files.c index 5d4a5c5828..3ee26059fc 100644 --- a/builtin-diff-files.c +++ b/builtin-diff-files.c @@ -47,5 +47,9 @@ int cmd_diff_files(int argc, const char **argv, const char *prefix) if (rev.pending.nr || rev.min_age != -1 || rev.max_age != -1) usage(diff_files_usage); + if (read_cache() < 0) { + perror("read_cache"); + return -1; + } return run_diff_files(&rev, silent); } diff --git a/builtin-diff-index.c b/builtin-diff-index.c index 95a3db156b..083599d5c4 100644 --- a/builtin-diff-index.c +++ b/builtin-diff-index.c @@ -38,5 +38,9 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix) if (rev.pending.nr != 1 || rev.max_count != -1 || rev.min_age != -1 || rev.max_age != -1) usage(diff_cache_usage); + if (read_cache() < 0) { + perror("read_cache"); + return -1; + } return run_diff_index(&rev, cached); } diff --git a/builtin-diff.c b/builtin-diff.c index a6590205e8..12d11f0c55 100644 --- a/builtin-diff.c +++ b/builtin-diff.c @@ -56,6 +56,10 @@ static int builtin_diff_files(struct rev_info *revs, if (revs->max_count < 0 && (revs->diffopt.output_format & DIFF_FORMAT_PATCH)) revs->combine_merges = revs->dense_combined_merges = 1; + if (read_cache() < 0) { + perror("read_cache"); + return -1; + } return run_diff_files(revs, silent); } @@ -151,6 +155,10 @@ static int builtin_diff_index(struct rev_info *revs, revs->max_count != -1 || revs->min_age != -1 || revs->max_age != -1) usage(builtin_diff_usage); + if (read_cache() < 0) { + perror("read_cache"); + return -1; + } return run_diff_index(revs, cached); } diff --git a/diff-lib.c b/diff-lib.c index 91cd87742f..278ba79ee6 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -20,11 +20,7 @@ int run_diff_files(struct rev_info *revs, int silent_on_removed) if (diff_unmerged_stage < 0) diff_unmerged_stage = 2; - entries = read_cache(); - if (entries < 0) { - perror("read_cache"); - return -1; - } + entries = active_nr; for (i = 0; i < entries; i++) { struct stat st; unsigned int oldmode, newmode; @@ -354,10 +350,6 @@ int run_diff_index(struct rev_info *revs, int cached) if (!revs->ignore_merges) match_missing = 1; - if (read_cache() < 0) { - perror("read_cache"); - return -1; - } mark_merge_entries(); ent = revs->pending.objects[0].item; diff --git a/wt-status.c b/wt-status.c index 2879c3d5ec..e346511153 100644 --- a/wt-status.c +++ b/wt-status.c @@ -191,12 +191,18 @@ static void wt_status_print_changed_cb(struct diff_queue_struct *q, wt_status_print_trailer(); } +static void wt_read_cache(struct wt_status *s) +{ + discard_cache(); + read_cache(); +} + void wt_status_print_initial(struct wt_status *s) { int i; char buf[PATH_MAX]; - read_cache(); + wt_read_cache(s); if (active_nr) { s->commitable = 1; wt_status_print_cached_header(NULL); @@ -220,6 +226,7 @@ static void wt_status_print_updated(struct wt_status *s) rev.diffopt.format_callback = wt_status_print_updated_cb; rev.diffopt.format_callback_data = s; rev.diffopt.detect_rename = 1; + wt_read_cache(s); run_diff_index(&rev, 1); } @@ -231,6 +238,7 @@ static void wt_status_print_changed(struct wt_status *s) rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK; rev.diffopt.format_callback = wt_status_print_changed_cb; rev.diffopt.format_callback_data = s; + wt_read_cache(s); run_diff_files(&rev, 0); } @@ -287,6 +295,7 @@ static void wt_status_print_verbose(struct wt_status *s) setup_revisions(0, NULL, &rev, s->reference); rev.diffopt.output_format |= DIFF_FORMAT_PATCH; rev.diffopt.detect_rename = 1; + wt_read_cache(s); run_diff_index(&rev, 1); } @@ -316,7 +325,6 @@ void wt_status_print(struct wt_status *s) } else { wt_status_print_updated(s); - discard_cache(); } wt_status_print_changed(s);