1
0
mirror of https://github.com/git/git.git synced 2024-10-20 05:18:11 +02:00

Merge branch 'mm/reset-report'

* mm/reset-report:
  reset: make the reminder output consistent with "checkout"
  Rename REFRESH_SAY_CHANGED to REFRESH_IN_PORCELAIN.
This commit is contained in:
Junio C Hamano 2009-08-28 19:39:26 -07:00
commit 235db154f8
5 changed files with 31 additions and 15 deletions

@ -105,8 +105,8 @@ static void refresh(int verbose, const char **pathspec)
for (specs = 0; pathspec[specs]; specs++) for (specs = 0; pathspec[specs]; specs++)
/* nothing */; /* nothing */;
seen = xcalloc(specs, 1); seen = xcalloc(specs, 1);
refresh_index(&the_index, verbose ? REFRESH_SAY_CHANGED : REFRESH_QUIET, refresh_index(&the_index, verbose ? REFRESH_IN_PORCELAIN : REFRESH_QUIET,
pathspec, seen); pathspec, seen, "Unstaged changes after refreshing the index:");
for (i = 0; i < specs; i++) { for (i = 0; i < specs; i++) {
if (!seen[i]) if (!seen[i])
die("pathspec '%s' did not match any files", pathspec[i]); die("pathspec '%s' did not match any files", pathspec[i]);

@ -108,7 +108,8 @@ static int update_index_refresh(int fd, struct lock_file *index_lock, int flags)
if (read_cache() < 0) if (read_cache() < 0)
return error("Could not read index"); return error("Could not read index");
result = refresh_cache(flags) ? 1 : 0; result = refresh_index(&the_index, (flags), NULL, NULL,
"Unstaged changes after reset:") ? 1 : 0;
if (write_cache(fd, active_cache, active_nr) || if (write_cache(fd, active_cache, active_nr) ||
commit_locked_index(index_lock)) commit_locked_index(index_lock))
return error ("Could not refresh index"); return error ("Could not refresh index");
@ -261,7 +262,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
die("Cannot do %s reset with paths.", die("Cannot do %s reset with paths.",
reset_type_names[reset_type]); reset_type_names[reset_type]);
return read_from_tree(prefix, argv + i, sha1, return read_from_tree(prefix, argv + i, sha1,
quiet ? REFRESH_QUIET : REFRESH_SAY_CHANGED); quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN);
} }
if (reset_type == NONE) if (reset_type == NONE)
reset_type = MIXED; /* by default */ reset_type = MIXED; /* by default */
@ -302,7 +303,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
break; break;
case MIXED: /* Report what has not been updated. */ case MIXED: /* Report what has not been updated. */
update_index_refresh(0, NULL, update_index_refresh(0, NULL,
quiet ? REFRESH_QUIET : REFRESH_SAY_CHANGED); quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN);
break; break;
} }

@ -330,7 +330,7 @@ static inline void remove_name_hash(struct cache_entry *ce)
#define remove_file_from_cache(path) remove_file_from_index(&the_index, (path)) #define remove_file_from_cache(path) remove_file_from_index(&the_index, (path))
#define add_to_cache(path, st, flags) add_to_index(&the_index, (path), (st), (flags)) #define add_to_cache(path, st, flags) add_to_index(&the_index, (path), (st), (flags))
#define add_file_to_cache(path, flags) add_file_to_index(&the_index, (path), (flags)) #define add_file_to_cache(path, flags) add_file_to_index(&the_index, (path), (flags))
#define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL) #define refresh_cache(flags) refresh_index(&the_index, (flags), NULL, NULL, NULL)
#define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options)) #define ce_match_stat(ce, st, options) ie_match_stat(&the_index, (ce), (st), (options))
#define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options)) #define ce_modified(ce, st, options) ie_modified(&the_index, (ce), (st), (options))
#define cache_name_exists(name, namelen, igncase) index_name_exists(&the_index, (name), (namelen), (igncase)) #define cache_name_exists(name, namelen, igncase) index_name_exists(&the_index, (name), (namelen), (igncase))
@ -476,8 +476,8 @@ extern int check_path(const char *path, int len, struct stat *st, int skiplen);
#define REFRESH_QUIET 0x0004 /* be quiet about it */ #define REFRESH_QUIET 0x0004 /* be quiet about it */
#define REFRESH_IGNORE_MISSING 0x0008 /* ignore non-existent */ #define REFRESH_IGNORE_MISSING 0x0008 /* ignore non-existent */
#define REFRESH_IGNORE_SUBMODULES 0x0010 /* ignore submodules */ #define REFRESH_IGNORE_SUBMODULES 0x0010 /* ignore submodules */
#define REFRESH_SAY_CHANGED 0x0020 /* say "changed" not "needs update" */ #define REFRESH_IN_PORCELAIN 0x0020 /* user friendly output, not "needs update" */
extern int refresh_index(struct index_state *, unsigned int flags, const char **pathspec, char *seen); extern int refresh_index(struct index_state *, unsigned int flags, const char **pathspec, char *seen, char *header_msg);
struct lock_file { struct lock_file {
struct lock_file *next; struct lock_file *next;

@ -1065,7 +1065,18 @@ static struct cache_entry *refresh_cache_ent(struct index_state *istate,
return updated; return updated;
} }
int refresh_index(struct index_state *istate, unsigned int flags, const char **pathspec, char *seen) static void show_file(const char * fmt, const char * name, int in_porcelain,
int * first, char *header_msg)
{
if (in_porcelain && *first && header_msg) {
printf("%s\n", header_msg);
*first=0;
}
printf(fmt, name);
}
int refresh_index(struct index_state *istate, unsigned int flags, const char **pathspec,
char *seen, char *header_msg)
{ {
int i; int i;
int has_errors = 0; int has_errors = 0;
@ -1074,11 +1085,14 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
int quiet = (flags & REFRESH_QUIET) != 0; int quiet = (flags & REFRESH_QUIET) != 0;
int not_new = (flags & REFRESH_IGNORE_MISSING) != 0; int not_new = (flags & REFRESH_IGNORE_MISSING) != 0;
int ignore_submodules = (flags & REFRESH_IGNORE_SUBMODULES) != 0; int ignore_submodules = (flags & REFRESH_IGNORE_SUBMODULES) != 0;
int first = 1;
int in_porcelain = (flags & REFRESH_IN_PORCELAIN);
unsigned int options = really ? CE_MATCH_IGNORE_VALID : 0; unsigned int options = really ? CE_MATCH_IGNORE_VALID : 0;
const char *needs_update_message; const char *needs_update_fmt;
const char *needs_merge_fmt;
needs_update_message = ((flags & REFRESH_SAY_CHANGED) needs_update_fmt = (in_porcelain ? "M\t%s\n" : "%s: needs update\n");
? "locally modified" : "needs update"); needs_merge_fmt = (in_porcelain ? "U\t%s\n" : "%s: needs merge\n");
for (i = 0; i < istate->cache_nr; i++) { for (i = 0; i < istate->cache_nr; i++) {
struct cache_entry *ce, *new; struct cache_entry *ce, *new;
int cache_errno = 0; int cache_errno = 0;
@ -1094,7 +1108,7 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
i--; i--;
if (allow_unmerged) if (allow_unmerged)
continue; continue;
printf("%s: needs merge\n", ce->name); show_file(needs_merge_fmt, ce->name, in_porcelain, &first, header_msg);
has_errors = 1; has_errors = 1;
continue; continue;
} }
@ -1117,7 +1131,7 @@ int refresh_index(struct index_state *istate, unsigned int flags, const char **p
} }
if (quiet) if (quiet)
continue; continue;
printf("%s: %s\n", ce->name, needs_update_message); show_file(needs_update_fmt, ce->name, in_porcelain, &first, header_msg);
has_errors = 1; has_errors = 1;
continue; continue;
} }

@ -419,7 +419,8 @@ test_expect_success 'resetting an unmodified path is a no-op' '
' '
cat > expect << EOF cat > expect << EOF
file2: locally modified Unstaged changes after reset:
M file2
EOF EOF
test_expect_success '--mixed refreshes the index' ' test_expect_success '--mixed refreshes the index' '