Merge branch 'jc/ident'
authorJunio C Hamano <gitster@pobox.com>
Wed, 20 Jan 2010 22:39:52 +0000 (14:39 -0800)
committerJunio C Hamano <gitster@pobox.com>
Wed, 20 Jan 2010 22:39:52 +0000 (14:39 -0800)
* jc/ident:
ident.c: replace fprintf with fputs to suppress compiler warning
user_ident_sufficiently_given(): refactor the logic to be usable from elsewhere
ident.c: treat $EMAIL as giving user.email identity explicitly
ident.c: check explicit identity for name and email separately
ident.c: remove unused variables

1  2 
builtin-commit.c
cache.h
config.c
diff --combined builtin-commit.c
index 69241f8ed6245b4f80f8758540bdd1aba926c4ce,b76f327e1f559dedef609ad010d3444fb1d64764..9b9dbaa5bf3a42c079d67902f1d8a125d0dacbba
@@@ -68,7 -68,7 +68,7 @@@ static enum 
  } cleanup_mode;
  static char *cleanup_arg;
  
 -static int use_editor = 1, initial_commit, in_merge;
 +static int use_editor = 1, initial_commit, in_merge, include_status = 1;
  static const char *only_include_assumed;
  static struct strbuf message;
  
@@@ -107,7 -107,6 +107,7 @@@ static struct option builtin_commit_opt
        OPT_FILENAME('t', "template", &template_file, "use specified template file"),
        OPT_BOOLEAN('e', "edit", &edit_flag, "force edit of commit"),
        OPT_STRING(0, "cleanup", &cleanup_arg, "default", "how to strip spaces and #comments from message"),
 +      OPT_BOOLEAN(0, "status", &include_status, "include status in commit message template"),
        /* end commit message options */
  
        OPT_GROUP("Commit contents options"),
@@@ -184,15 -183,11 +184,15 @@@ static int list_paths(struct string_lis
  
        for (i = 0; i < active_nr; i++) {
                struct cache_entry *ce = active_cache[i];
 +              struct string_list_item *item;
 +
                if (ce->ce_flags & CE_UPDATE)
                        continue;
                if (!match_pathspec(pattern, ce->name, ce_namelen(ce), 0, m))
                        continue;
 -              string_list_insert(ce->name, list);
 +              item = string_list_insert(ce->name, list);
 +              if (ce_skip_worktree(ce))
 +                      item->util = item; /* better a valid pointer than a fake one */
        }
  
        return report_path_error(m, pattern, prefix ? strlen(prefix) : 0);
@@@ -205,10 -200,6 +205,10 @@@ static void add_remove_files(struct str
                struct stat st;
                struct string_list_item *p = &(list->items[i]);
  
 +              /* p->util is skip-worktree */
 +              if (p->util)
 +                      continue;
 +
                if (!lstat(p->string, &st)) {
                        if (add_to_cache(p->string, &st, 0))
                                die("updating files failed");
@@@ -591,7 -582,7 +591,7 @@@ static int prepare_to_commit(const cha
  
        /* This checks if committer ident is explicitly given */
        git_committer_info(0);
 -      if (use_editor) {
 +      if (use_editor && include_status) {
                char *author_ident;
                const char *committer_ident;
  
                                author_ident);
                free(author_ident);
  
-               if (!user_ident_explicitly_given)
+               if (!user_ident_sufficiently_given())
                        fprintf(fp,
                                "%s"
                                "# Committer: %s\n",
@@@ -1106,10 -1097,6 +1106,10 @@@ static int git_commit_config(const cha
  
        if (!strcmp(k, "commit.template"))
                return git_config_pathname(&template_file, k, v);
 +      if (!strcmp(k, "commit.status")) {
 +              include_status = git_config_bool(k, v);
 +              return 0;
 +      }
  
        return git_status_config(k, v, s);
  }
@@@ -1255,7 -1242,7 +1255,7 @@@ int cmd_commit(int argc, const char **a
                     "new_index file. Check that disk is not full or quota is\n"
                     "not exceeded, and then \"git reset HEAD\" to recover.");
  
 -      rerere();
 +      rerere(0);
        run_hook(get_index_file(), "post-commit", NULL);
        if (!quiet)
                print_summary(prefix, commit_sha1);
diff --combined cache.h
index caeafb229245afe5be081684094ef81f6a6a8b6b,f7a287cbc6af7609db2adc4d4844ff3c1116fc13..bebe1a891da7afdf22431a7b8816fa729fe7eb75
+++ b/cache.h
@@@ -177,20 -177,15 +177,20 @@@ struct cache_entry 
  
  #define CE_HASHED    (0x100000)
  #define CE_UNHASHED  (0x200000)
 +#define CE_CONFLICTED (0x800000)
 +
 +/* Only remove in work directory, not index */
 +#define CE_WT_REMOVE (0x400000)
  
  /*
   * Extended on-disk flags
   */
  #define CE_INTENT_TO_ADD 0x20000000
 +#define CE_SKIP_WORKTREE 0x40000000
  /* CE_EXTENDED2 is for future extension */
  #define CE_EXTENDED2 0x80000000
  
 -#define CE_EXTENDED_FLAGS (CE_INTENT_TO_ADD)
 +#define CE_EXTENDED_FLAGS (CE_INTENT_TO_ADD | CE_SKIP_WORKTREE)
  
  /*
   * Safeguard to avoid saving wrong flags:
@@@ -239,7 -234,6 +239,7 @@@ static inline size_t ce_namelen(const s
                            ondisk_cache_entry_size(ce_namelen(ce)))
  #define ce_stage(ce) ((CE_STAGEMASK & (ce)->ce_flags) >> CE_STAGESHIFT)
  #define ce_uptodate(ce) ((ce)->ce_flags & CE_UPTODATE)
 +#define ce_skip_worktree(ce) ((ce)->ce_flags & CE_SKIP_WORKTREE)
  #define ce_mark_uptodate(ce) ((ce)->ce_flags |= CE_UPTODATE)
  
  #define ce_permissions(mode) (((mode) & 0100) ? 0755 : 0644)
@@@ -451,6 -445,7 +451,6 @@@ extern int index_name_pos(const struct 
  #define ADD_CACHE_JUST_APPEND 8               /* Append only; tree.c::read_tree() */
  #define ADD_CACHE_NEW_ONLY 16         /* Do not replace existing ones */
  extern int add_index_entry(struct index_state *, struct cache_entry *ce, int option);
 -extern struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int really);
  extern void rename_index_entry_at(struct index_state *, int pos, const char *new_name);
  extern int remove_index_entry_at(struct index_state *, int pos);
  extern void remove_marked_cache_entries(struct index_state *istate);
@@@ -469,9 -464,7 +469,9 @@@ extern int index_name_is_other(const st
  /* do stat comparison even if CE_VALID is true */
  #define CE_MATCH_IGNORE_VALID         01
  /* do not check the contents but report dirty on racily-clean entries */
 -#define CE_MATCH_RACY_IS_DIRTY        02
 +#define CE_MATCH_RACY_IS_DIRTY                02
 +/* do stat comparison even if CE_SKIP_WORKTREE is true */
 +#define CE_MATCH_IGNORE_SKIP_WORKTREE 04
  extern int ie_match_stat(const struct index_state *, struct cache_entry *, struct stat *, unsigned int);
  extern int ie_modified(const struct index_state *, struct cache_entry *, struct stat *, unsigned int);
  
@@@ -480,6 -473,9 +480,6 @@@ extern int index_fd(unsigned char *sha1
  extern int index_path(unsigned char *sha1, const char *path, struct stat *st, int write_object);
  extern void fill_stat_cache_info(struct cache_entry *ce, struct stat *st);
  
 -/* "careful lstat()" */
 -extern int check_path(const char *path, int len, struct stat *st, int skiplen);
 -
  #define REFRESH_REALLY                0x0001  /* ignore_valid */
  #define REFRESH_UNMERGED      0x0002  /* allow unmerged */
  #define REFRESH_QUIET         0x0004  /* be quiet about it */
@@@ -533,7 -529,6 +533,7 @@@ extern int auto_crlf
  extern int read_replace_refs;
  extern int fsync_object_files;
  extern int core_preload_index;
 +extern int core_apply_sparse_checkout;
  
  enum safe_crlf {
        SAFE_CRLF_FALSE = 0,
@@@ -623,6 -618,7 +623,6 @@@ static inline void hashclr(unsigned cha
  {
        memset(hash, 0, 20);
  }
 -extern int is_empty_blob_sha1(const unsigned char *sha1);
  
  #define EMPTY_TREE_SHA1_HEX \
        "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
@@@ -692,6 -688,7 +692,6 @@@ extern int has_sha1_pack(const unsigne
  extern int has_sha1_file(const unsigned char *sha1);
  extern int has_loose_object_nonlocal(const unsigned char *sha1);
  
 -extern int has_pack_file(const unsigned char *sha1);
  extern int has_pack_index(const unsigned char *sha1);
  
  extern const signed char hexval_table[256];
@@@ -705,11 -702,7 +705,11 @@@ static inline unsigned int hexval(unsig
  #define DEFAULT_ABBREV 7
  
  extern int get_sha1(const char *str, unsigned char *sha1);
 -extern int get_sha1_with_mode(const char *str, unsigned char *sha1, unsigned *mode);
 +extern int get_sha1_with_mode_1(const char *str, unsigned char *sha1, unsigned *mode, int gently, const char *prefix);
 +static inline int get_sha1_with_mode(const char *str, unsigned char *sha1, unsigned *mode)
 +{
 +      return get_sha1_with_mode_1(str, sha1, mode, 1, NULL);
 +}
  extern int get_sha1_hex(const char *hex, unsigned char *sha1);
  extern char *sha1_to_hex(const unsigned char *sha1);  /* static buffer result! */
  extern int read_ref(const char *filename, unsigned char *sha1);
@@@ -717,7 -710,6 +717,7 @@@ extern const char *resolve_ref(const ch
  extern int dwim_ref(const char *str, int len, unsigned char *sha1, char **ref);
  extern int dwim_log(const char *str, int len, unsigned char *sha1, char **ref);
  extern int interpret_branch_name(const char *str, struct strbuf *);
 +extern int get_sha1_mb(const char *str, unsigned char *sha1);
  
  extern int refname_match(const char *abbrev_name, const char *full_name, const char **rules);
  extern const char *ref_rev_parse_rules[];
@@@ -792,6 -784,8 +792,6 @@@ extern int has_symlink_leading_path(con
  extern int threaded_has_symlink_leading_path(struct cache_def *, const char *, int);
  extern int has_symlink_or_noent_leading_path(const char *name, int len);
  extern int has_dirs_only_path(const char *name, int len, int prefix_len);
 -extern void invalidate_lstat_cache(const char *name, int len);
 -extern void clear_lstat_cache(void);
  extern void schedule_dir_for_removal(const char *name, int len);
  extern void remove_scheduled_dirs(void);
  
@@@ -931,7 -925,11 +931,11 @@@ extern const char *config_exclusive_fil
  #define MAX_GITNAME (1000)
  extern char git_default_email[MAX_GITNAME];
  extern char git_default_name[MAX_GITNAME];
+ #define IDENT_NAME_GIVEN 01
+ #define IDENT_MAIL_GIVEN 02
+ #define IDENT_ALL_GIVEN (IDENT_NAME_GIVEN|IDENT_MAIL_GIVEN)
  extern int user_ident_explicitly_given;
+ extern int user_ident_sufficiently_given(void);
  
  extern const char *git_commit_encoding;
  extern const char *git_log_output_encoding;
diff --combined config.c
index f4f2c59a34cd9fc70db940871caaf00b94a6ef2e,fa1a0c02998feed88bad3c2358f54a14c765ce0c..6963fbea43e6420f5f8dafc5b94fb5c27de6ffd2
+++ b/config.c
@@@ -518,11 -518,6 +518,11 @@@ static int git_default_core_config(cons
                return 0;
        }
  
 +      if (!strcmp(var, "core.sparsecheckout")) {
 +              core_apply_sparse_checkout = git_config_bool(var, value);
 +              return 0;
 +      }
 +
        /* Add other config variables here and to Documentation/config.txt. */
        return 0;
  }
@@@ -533,8 -528,7 +533,7 @@@ static int git_default_user_config(cons
                if (!value)
                        return config_error_nonbool(var);
                strlcpy(git_default_name, value, sizeof(git_default_name));
-               if (git_default_email[0])
-                       user_ident_explicitly_given = 1;
+               user_ident_explicitly_given |= IDENT_NAME_GIVEN;
                return 0;
        }
  
                if (!value)
                        return config_error_nonbool(var);
                strlcpy(git_default_email, value, sizeof(git_default_email));
-               if (git_default_name[0])
-                       user_ident_explicitly_given = 1;
+               user_ident_explicitly_given |= IDENT_MAIL_GIVEN;
                return 0;
        }