Merge branch 'jc/shared-literally' into maint
authorJunio C Hamano <gitster@pobox.com>
Thu, 9 Apr 2009 06:23:41 +0000 (23:23 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 9 Apr 2009 06:23:41 +0000 (23:23 -0700)
* jc/shared-literally:
t1301: loosen test for forced modes
set_shared_perm(): sometimes we know what the final mode bits should look like
move_temp_to_file(): do not forget to chmod() in "Coda hack" codepath
Move chmod(foo, 0444) into move_temp_to_file()
"core.sharedrepository = 0mode" should set, not loosen

1  2 
cache.h
sha1_file.c
diff --combined cache.h
index 50179687b5fc9ed37933d06bb4cbfe988ce8b6c9,e283bbe1736ad7ba321c815b48e58cb41e781e16..dfeb1e9c860ed1407e5a2d7a5f5a7d822f460045
+++ b/cache.h
@@@ -613,7 -613,8 +613,8 @@@ enum sharedrepo 
        PERM_EVERYBODY      = 0664,
  };
  int git_config_perm(const char *var, const char *value);
- int adjust_shared_perm(const char *path);
+ int set_shared_perm(const char *path, int mode);
+ #define adjust_shared_perm(path) set_shared_perm((path), 0)
  int safe_create_leading_directories(char *path);
  int safe_create_leading_directories_const(const char *path);
  char *enter_repo(char *path, int strict);
@@@ -644,7 -645,7 +645,7 @@@ extern int check_sha1_signature(const u
  
  extern int move_temp_to_file(const char *tmpfile, const char *filename);
  
 -extern int has_sha1_pack(const unsigned char *sha1, const char **ignore);
 +extern int has_sha1_pack(const unsigned char *sha1);
  extern int has_sha1_file(const unsigned char *sha1);
  extern int has_loose_object_nonlocal(const unsigned char *sha1);
  
@@@ -839,6 -840,7 +840,6 @@@ extern void *unpack_entry(struct packed
  extern unsigned long unpack_object_header_buffer(const unsigned char *buf, unsigned long len, enum object_type *type, unsigned long *sizep);
  extern unsigned long get_size_from_delta(struct packed_git *, struct pack_window **, off_t);
  extern const char *packed_object_info_detail(struct packed_git *, off_t, unsigned long *, unsigned long *, unsigned int *, unsigned char *);
 -extern int matches_pack_name(struct packed_git *p, const char *name);
  
  /* Dumb servers support */
  extern int update_server_info(int);
diff --combined sha1_file.c
index 37e833b77d1ee556d18256154073a706ab11b3a4,d978abf43d26a47c73f98c030802e4c7dffe049f..8fe135dc61908103cf2d7de700794843f83db057
@@@ -1919,7 -1919,25 +1919,7 @@@ off_t find_pack_entry_one(const unsigne
        return 0;
  }
  
 -int matches_pack_name(struct packed_git *p, const char *name)
 -{
 -      const char *last_c, *c;
 -
 -      if (!strcmp(p->pack_name, name))
 -              return 1;
 -
 -      for (c = p->pack_name, last_c = c; *c;)
 -              if (*c == '/')
 -                      last_c = ++c;
 -              else
 -                      ++c;
 -      if (!strcmp(last_c, name))
 -              return 1;
 -
 -      return 0;
 -}
 -
 -static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e, const char **ignore_packed)
 +static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e)
  {
        static struct packed_git *last_found = (void *)1;
        struct packed_git *p;
        p = (last_found == (void *)1) ? packed_git : last_found;
  
        do {
 -              if (ignore_packed) {
 -                      const char **ig;
 -                      for (ig = ignore_packed; *ig; ig++)
 -                              if (matches_pack_name(p, *ig))
 -                                      break;
 -                      if (*ig)
 -                              goto next;
 -              }
 -
                if (p->num_bad_objects) {
                        unsigned i;
                        for (i = 0; i < p->num_bad_objects; i++)
@@@ -2011,7 -2038,7 +2011,7 @@@ int sha1_object_info(const unsigned cha
        struct pack_entry e;
        int status;
  
 -      if (!find_pack_entry(sha1, &e, NULL)) {
 +      if (!find_pack_entry(sha1, &e)) {
                /* Most likely it's a loose object. */
                status = sha1_loose_object_info(sha1, sizep);
                if (status >= 0)
  
                /* Not a loose object; someone else may have just packed it. */
                reprepare_packed_git();
 -              if (!find_pack_entry(sha1, &e, NULL))
 +              if (!find_pack_entry(sha1, &e))
                        return status;
        }
  
@@@ -2038,7 -2065,7 +2038,7 @@@ static void *read_packed_sha1(const uns
        struct pack_entry e;
        void *data;
  
 -      if (!find_pack_entry(sha1, &e, NULL))
 +      if (!find_pack_entry(sha1, &e))
                return NULL;
        data = cache_or_unpack_entry(e.p, e.offset, size, type, 1);
        if (!data) {
@@@ -2216,11 -2243,15 +2216,15 @@@ static void write_sha1_file_prepare(con
  }
  
  /*
-  * Move the just written object into its final resting place
+  * Move the just written object into its final resting place.
+  * NEEDSWORK: this should be renamed to finalize_temp_file() as
+  * "moving" is only a part of what it does, when no patch between
+  * master to pu changes the call sites of this function.
   */
  int move_temp_to_file(const char *tmpfile, const char *filename)
  {
        int ret = 0;
        if (link(tmpfile, filename))
                ret = errno;
  
         *
         * The same holds for FAT formatted media.
         *
-        * When this succeeds, we just return 0. We have nothing
+        * When this succeeds, we just return We have nothing
         * left to unlink.
         */
        if (ret && ret != EEXIST) {
                if (!rename(tmpfile, filename))
-                       return 0;
+                       goto out;
                ret = errno;
        }
        unlink(tmpfile);
                /* FIXME!!! Collision check here ? */
        }
  
+ out:
+       if (set_shared_perm(filename, (S_IFREG|0444)))
+               return error("unable to set permission to '%s'", filename);
        return 0;
  }
  
@@@ -2272,7 -2306,6 +2279,6 @@@ static void close_sha1_file(int fd
  {
        if (fsync_object_files)
                fsync_or_die(fd, "sha1 file");
-       fchmod(fd, 0444);
        if (close(fd) != 0)
                die("error when closing sha1 file (%s)", strerror(errno));
  }
@@@ -2437,17 -2470,17 +2443,17 @@@ int has_pack_file(const unsigned char *
        return 1;
  }
  
 -int has_sha1_pack(const unsigned char *sha1, const char **ignore_packed)
 +int has_sha1_pack(const unsigned char *sha1)
  {
        struct pack_entry e;
 -      return find_pack_entry(sha1, &e, ignore_packed);
 +      return find_pack_entry(sha1, &e);
  }
  
  int has_sha1_file(const unsigned char *sha1)
  {
        struct pack_entry e;
  
 -      if (find_pack_entry(sha1, &e, NULL))
 +      if (find_pack_entry(sha1, &e))
                return 1;
        return has_loose_object(sha1);
  }