Merge branch 'jc/replacing'
authorJunio C Hamano <gitster@pobox.com>
Fri, 20 May 2011 03:37:21 +0000 (20:37 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 20 May 2011 03:37:21 +0000 (20:37 -0700)
* jc/replacing:
read_sha1_file(): allow selective bypassing of replacement mechanism
inline lookup_replace_object() calls
read_sha1_file(): get rid of read_sha1_file_repl() madness
t6050: make sure we test not just commit replacement
Declare lookup_replace_object() in cache.h, not in commit.h

Conflicts:
environment.c

1  2 
cache.h
commit.h
environment.c
sha1_file.c
diff --combined cache.h
index 4ae773647ff5545ecd885d316f77fe6ae8cedad9,5f1f5c33953510bbdc7d31139b5e33bd1aaa7a4c..66ddfb71b66922e47d95efed4a80df39f1e829da
+++ b/cache.h
@@@ -606,7 -606,7 +606,7 @@@ enum eol 
  #endif
  };
  
 -extern enum eol eol;
 +extern enum eol core_eol;
  
  enum branch_track {
        BRANCH_TRACK_UNSPECIFIED = -1,
@@@ -756,13 -756,23 +756,23 @@@ char *strip_path_suffix(const char *pat
  int daemon_avoid_alias(const char *path);
  int offset_1st_component(const char *path);
  
- /* Read and unpack a sha1 file into memory, write memory to a sha1 file */
- extern int sha1_object_info(const unsigned char *, unsigned long *);
- extern void *read_sha1_file_repl(const unsigned char *sha1, enum object_type *type, unsigned long *size, const unsigned char **replacement);
+ /* object replacement */
+ #define READ_SHA1_FILE_REPLACE 1
+ extern void *read_sha1_file_extended(const unsigned char *sha1, enum object_type *type, unsigned long *size, unsigned flag);
  static inline void *read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size)
  {
-       return read_sha1_file_repl(sha1, type, size, NULL);
+       return read_sha1_file_extended(sha1, type, size, READ_SHA1_FILE_REPLACE);
+ }
+ extern const unsigned char *do_lookup_replace_object(const unsigned char *sha1);
+ static inline const unsigned char *lookup_replace_object(const unsigned char *sha1)
+ {
+       if (!read_replace_refs)
+               return sha1;
+       return do_lookup_replace_object(sha1);
  }
+ /* Read and unpack a sha1 file into memory, write memory to a sha1 file */
+ extern int sha1_object_info(const unsigned char *, unsigned long *);
  extern int hash_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *sha1);
  extern int write_sha1_file(const void *buf, unsigned long len, const char *type, unsigned char *return_sha1);
  extern int pretend_sha1_file(void *, unsigned long, enum object_type, unsigned char *);
@@@ -975,7 -985,6 +985,7 @@@ extern struct ref *find_ref_by_name(con
  extern char *git_getpass(const char *prompt);
  extern struct child_process *git_connect(int fd[2], const char *url, const char *prog, int flags);
  extern int finish_connect(struct child_process *conn);
 +extern int git_connection_is_socket(struct child_process *conn);
  extern int path_match(const char *path, int nr, char **match);
  struct extra_have_objects {
        int nr, alloc;
diff --combined commit.h
index 43940e2bddcc34d2b74d2ddb76c045939c413c52,f251e75a5b4c4bf9064f53ae57b6613ff07349e6..3114bd1781c3c5e735dfc1b1a7b4131270992f14
+++ b/commit.h
@@@ -145,8 -145,6 +145,6 @@@ struct commit_graft *read_graft_line(ch
  int register_commit_graft(struct commit_graft *, int);
  struct commit_graft *lookup_commit_graft(const unsigned char *sha1);
  
- const unsigned char *lookup_replace_object(const unsigned char *sha1);
  extern struct commit_list *get_merge_bases(struct commit *rev1, struct commit *rev2, int cleanup);
  extern struct commit_list *get_merge_bases_many(struct commit *one, int n, struct commit **twos, int cleanup);
  extern struct commit_list *get_octopus_merge_bases(struct commit_list *in);
@@@ -161,7 -159,7 +159,7 @@@ extern struct commit_list *get_shallow_
  int is_descendant_of(struct commit *, struct commit_list *);
  int in_merge_bases(struct commit *, struct commit **, int);
  
 -extern int interactive_add(int argc, const char **argv, const char *prefix);
 +extern int interactive_add(int argc, const char **argv, const char *prefix, int patch);
  extern int run_add_interactive(const char *revision, const char *patch_mode,
                               const char **pathspec);
  
diff --combined environment.c
index 7fe9f101243d9063ff06fe2c6ea10f220b6a2549,91828201d87daf4c1035ac27bc6e9f07c01c8d90..94d58fd24413ec1d1a5769029bd5149b609f0d4e
@@@ -42,8 -42,8 +42,8 @@@ const char *editor_program
  const char *askpass_program;
  const char *excludes_file;
  enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
- int read_replace_refs = 1;
+ int read_replace_refs = 1; /* NEEDSWORK: rename to use_replace_refs */
 -enum eol eol = EOL_UNSET;
 +enum eol core_eol = EOL_UNSET;
  enum safe_crlf safe_crlf = SAFE_CRLF_WARN;
  unsigned whitespace_rule_cfg = WS_DEFAULT_RULE;
  enum branch_track git_branch_track = BRANCH_TRACK_REMOTE;
diff --combined sha1_file.c
index 1a7e41070efa6327859d3c09ede07317cc91ba7d,7e6e976c23024c575a1eba73ed8dd70424ec09ff..357f9ab7ff6aad644857986f36fd55da8348744f
@@@ -31,6 -31,8 +31,6 @@@ static inline uintmax_t sz_fmt(size_t s
  
  const unsigned char null_sha1[20];
  
 -static int git_open_noatime(const char *name, struct packed_git *p);
 -
  /*
   * This is meant to hold a *small* number of objects that you would
   * want read_sha1_file() to be able to return, but yet you do not want
@@@ -225,7 -227,6 +225,7 @@@ struct alternate_object_database *alt_o
  static struct alternate_object_database **alt_odb_tail;
  
  static void read_info_alternates(const char * alternates, int depth);
 +static int git_open_noatime(const char *name);
  
  /*
   * Prepare alternate object database registry.
@@@ -359,7 -360,7 +359,7 @@@ static void read_info_alternates(const 
        int fd;
  
        sprintf(path, "%s/%s", relative_base, alt_file_name);
 -      fd = git_open_noatime(path, NULL);
 +      fd = git_open_noatime(path);
        if (fd < 0)
                return;
        if (fstat(fd, &st) || (st.st_size == 0)) {
@@@ -474,7 -475,7 +474,7 @@@ static int check_packed_git_idx(const c
        struct pack_idx_header *hdr;
        size_t idx_size;
        uint32_t version, nr, i, *index;
 -      int fd = git_open_noatime(path, p);
 +      int fd = git_open_noatime(path);
        struct stat st;
  
        if (fd < 0)
@@@ -756,7 -757,7 +756,7 @@@ static int open_packed_git_1(struct pac
        while (pack_max_fds <= pack_open_fds && unuse_one_window(NULL, -1))
                ; /* nothing */
  
 -      p->pack_fd = git_open_noatime(p->pack_name, p);
 +      p->pack_fd = git_open_noatime(p->pack_name);
        if (p->pack_fd < 0 || fstat(p->pack_fd, &st))
                return -1;
        pack_open_fds++;
@@@ -1144,7 -1145,7 +1144,7 @@@ int check_sha1_signature(const unsigne
        return hashcmp(sha1, real_sha1) ? -1 : 0;
  }
  
 -static int git_open_noatime(const char *name, struct packed_git *p)
 +static int git_open_noatime(const char *name)
  {
        static int sha1_file_open_flag = O_NOATIME;
  
@@@ -1169,7 -1170,7 +1169,7 @@@ static int open_sha1_file(const unsigne
        char *name = sha1_file_name(sha1);
        struct alternate_object_database *alt;
  
 -      fd = git_open_noatime(name, NULL);
 +      fd = git_open_noatime(name);
        if (fd >= 0)
                return fd;
  
        for (alt = alt_odb_list; alt; alt = alt->next) {
                name = alt->name;
                fill_sha1_path(name, sha1);
 -              fd = git_open_noatime(alt->base, NULL);
 +              fd = git_open_noatime(alt->base);
                if (fd >= 0)
                        return fd;
        }
@@@ -1307,7 -1308,7 +1307,7 @@@ static void *unpack_sha1_rest(z_stream 
                /*
                 * The above condition must be (bytes <= size), not
                 * (bytes < size).  In other words, even though we
 -               * expect no more output and set avail_out to zer0,
 +               * expect no more output and set avail_out to zero,
                 * the input zlib stream may have bytes that express
                 * "this concludes the stream", and we *do* want to
                 * eat that input.
@@@ -2205,23 -2206,21 +2205,21 @@@ static void *read_object(const unsigne
   * deal with them should arrange to call read_object() and give error
   * messages themselves.
   */
- void *read_sha1_file_repl(const unsigned char *sha1,
-                         enum object_type *type,
-                         unsigned long *size,
-                         const unsigned char **replacement)
+ void *read_sha1_file_extended(const unsigned char *sha1,
+                             enum object_type *type,
+                             unsigned long *size,
+                             unsigned flag)
  {
-       const unsigned char *repl = lookup_replace_object(sha1);
        void *data;
        char *path;
        const struct packed_git *p;
+       const unsigned char *repl = (flag & READ_SHA1_FILE_REPLACE)
+               ? lookup_replace_object(sha1) : sha1;
  
        errno = 0;
        data = read_object(repl, type, size);
-       if (data) {
-               if (replacement)
-                       *replacement = repl;
+       if (data)
                return data;
-       }
  
        if (errno && errno != ENOENT)
                die_errno("failed to read object %s", sha1_to_hex(sha1));