Evil Merge branch 'jc/status' (early part) into js/diff-ni

* 'jc/status' (early part):
  run_diff_{files,index}(): update calling convention.
  update-index: do not die too early in a read-only repository.
  git-status: do not be totally useless in a read-only repository.

This is to resolve semantic conflict (which is not textual) that
changes the calling convention of run_diff_files() early.
maint
Junio C Hamano 2007-02-24 02:20:13 -08:00
commit efdfd6c8d4
6 changed files with 44 additions and 22 deletions

View File

@ -38,5 +38,9 @@ int cmd_diff_index(int argc, const char **argv, const char *prefix)
if (rev.pending.nr != 1 || if (rev.pending.nr != 1 ||
rev.max_count != -1 || rev.min_age != -1 || rev.max_age != -1) rev.max_count != -1 || rev.min_age != -1 || rev.max_age != -1)
usage(diff_cache_usage); usage(diff_cache_usage);
if (read_cache() < 0) {
perror("read_cache");
return -1;
}
return run_diff_index(&rev, cached); return run_diff_index(&rev, cached);
} }

View File

@ -117,6 +117,10 @@ static int builtin_diff_index(struct rev_info *revs,
revs->max_count != -1 || revs->min_age != -1 || revs->max_count != -1 || revs->min_age != -1 ||
revs->max_age != -1) revs->max_age != -1)
usage(builtin_diff_usage); usage(builtin_diff_usage);
if (read_cache() < 0) {
perror("read_cache");
return -1;
}
return run_diff_index(revs, cached); return run_diff_index(revs, cached);
} }



View File

@ -487,6 +487,7 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)
int prefix_length = prefix ? strlen(prefix) : 0; int prefix_length = prefix ? strlen(prefix) : 0;
char set_executable_bit = 0; char set_executable_bit = 0;
unsigned int refresh_flags = 0; unsigned int refresh_flags = 0;
int lock_error = 0;
struct lock_file *lock_file; struct lock_file *lock_file;


git_config(git_default_config); git_config(git_default_config);
@ -494,7 +495,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() */ /* We can't free this memory, it becomes part of a linked list parsed atexit() */
lock_file = xcalloc(1, sizeof(struct lock_file)); 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(); entries = read_cache();
if (entries < 0) if (entries < 0)
@ -651,6 +654,12 @@ int cmd_update_index(int argc, const char **argv, const char *prefix)


finish: finish:
if (active_cache_changed) { 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) || if (write_cache(newfd, active_cache, active_nr) ||
close(newfd) || commit_lock_file(lock_file)) close(newfd) || commit_lock_file(lock_file))
die("Unable to write new index file"); die("Unable to write new index file");

View File

@ -217,6 +217,10 @@ int run_diff_files_cmd(struct rev_info *revs, int argc, const char **argv)
return 0; return 0;
} }


if (read_cache() < 0) {
perror("read_cache");
return -1;
}
return run_diff_files(revs, silent_on_removed); return run_diff_files(revs, silent_on_removed);
} }


@ -227,11 +231,7 @@ int run_diff_files(struct rev_info *revs, int silent_on_removed)


if (diff_unmerged_stage < 0) if (diff_unmerged_stage < 0)
diff_unmerged_stage = 2; diff_unmerged_stage = 2;
entries = read_cache(); entries = active_nr;
if (entries < 0) {
perror("read_cache");
return -1;
}
for (i = 0; i < entries; i++) { for (i = 0; i < entries; i++) {
struct stat st; struct stat st;
unsigned int oldmode, newmode; unsigned int oldmode, newmode;
@ -559,10 +559,6 @@ int run_diff_index(struct rev_info *revs, int cached)
if (!revs->ignore_merges) if (!revs->ignore_merges)
match_missing = 1; match_missing = 1;


if (read_cache() < 0) {
perror("read_cache");
return -1;
}
mark_merge_entries(); mark_merge_entries();


ent = revs->pending.objects[0].item; ent = revs->pending.objects[0].item;

View File

@ -13,10 +13,10 @@ git-rev-parse --verify HEAD >/dev/null 2>&1 || initial_commit=t
case "$0" in case "$0" in
*status) *status)
status_only=t status_only=t
unmerged_ok_if_status=--unmerged ;; ;;
*commit) *commit)
status_only= status_only=
unmerged_ok_if_status= ;; ;;
esac esac


refuse_partial () { refuse_partial () {
@ -389,16 +389,17 @@ else
USE_INDEX="$THIS_INDEX" USE_INDEX="$THIS_INDEX"
fi fi


GIT_INDEX_FILE="$USE_INDEX" \ case "$status_only" in
git-update-index -q $unmerged_ok_if_status --refresh || exit t)

# This will silently fail in a read-only repository, which is
################################################################ # what we want.
# If the request is status, just show it and exit. GIT_INDEX_FILE="$USE_INDEX" git-update-index -q --unmerged --refresh

case "$0" in
*status)
run_status run_status
exit $? exit $?
;;
'')
GIT_INDEX_FILE="$USE_INDEX" git-update-index -q --refresh || exit
;;
esac esac


################################################################ ################################################################

View File

@ -191,12 +191,18 @@ static void wt_status_print_changed_cb(struct diff_queue_struct *q,
wt_status_print_trailer(); 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) void wt_status_print_initial(struct wt_status *s)
{ {
int i; int i;
char buf[PATH_MAX]; char buf[PATH_MAX];


read_cache(); wt_read_cache(s);
if (active_nr) { if (active_nr) {
s->commitable = 1; s->commitable = 1;
wt_status_print_cached_header(NULL); 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 = wt_status_print_updated_cb;
rev.diffopt.format_callback_data = s; rev.diffopt.format_callback_data = s;
rev.diffopt.detect_rename = 1; rev.diffopt.detect_rename = 1;
wt_read_cache(s);
run_diff_index(&rev, 1); 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.output_format |= DIFF_FORMAT_CALLBACK;
rev.diffopt.format_callback = wt_status_print_changed_cb; rev.diffopt.format_callback = wt_status_print_changed_cb;
rev.diffopt.format_callback_data = s; rev.diffopt.format_callback_data = s;
wt_read_cache(s);
run_diff_files(&rev, 0); 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); setup_revisions(0, NULL, &rev, s->reference);
rev.diffopt.output_format |= DIFF_FORMAT_PATCH; rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
rev.diffopt.detect_rename = 1; rev.diffopt.detect_rename = 1;
wt_read_cache(s);
run_diff_index(&rev, 1); run_diff_index(&rev, 1);
} }


@ -316,7 +325,6 @@ void wt_status_print(struct wt_status *s)
} }
else { else {
wt_status_print_updated(s); wt_status_print_updated(s);
discard_cache();
} }


wt_status_print_changed(s); wt_status_print_changed(s);