]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'jk/pack-name-cleanups' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 28 Mar 2017 20:52:25 +0000 (13:52 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 28 Mar 2017 20:52:25 +0000 (13:52 -0700)
Code clean-up.

* jk/pack-name-cleanups:
  index-pack: make pointer-alias fallbacks safer
  replace snprintf with odb_pack_name()
  odb_pack_keep(): stop generating keepfile name
  sha1_file.c: make pack-name helper globally accessible
  move odb_* declarations out of git-compat-util.h

1  2 
cache.h
environment.c
git-compat-util.h
sha1_file.c

diff --combined cache.h
index b3cf851b59ff80be9f36d27c350099b15f74844d,0c177b7acd683ab41a2bf7c9f435695b38d59148..900796c155be49d8c275c735edf1c7a2dabec70a
+++ b/cache.h
@@@ -1045,6 -1045,9 +1045,6 @@@ static inline int is_empty_tree_oid(con
        return !hashcmp(oid->hash, EMPTY_TREE_SHA1_BIN);
  }
  
 -
 -int git_mkstemp(char *path, size_t n, const char *template);
 -
  /* set default permissions by passing mode arguments to open(2) */
  int git_mkstemps_mode(char *pattern, int suffix_len, int mode);
  int git_mkstemp_mode(char *pattern, int mode);
@@@ -1106,7 -1109,7 +1106,7 @@@ char *strbuf_realpath(struct strbuf *re
                      int die_on_error);
  const char *real_path(const char *path);
  const char *real_path_if_valid(const char *path);
 -char *real_pathdup(const char *path);
 +char *real_pathdup(const char *path, int die_on_error);
  const char *absolute_path(const char *path);
  char *absolute_pathdup(const char *path);
  const char *remove_leading_path(const char *in, const char *prefix);
@@@ -1316,37 -1319,7 +1316,37 @@@ extern char *oid_to_hex_r(char *out, co
  extern char *sha1_to_hex(const unsigned char *sha1);  /* static buffer result! */
  extern char *oid_to_hex(const struct object_id *oid); /* same static buffer as sha1_to_hex */
  
 -extern int interpret_branch_name(const char *str, int len, struct strbuf *);
 +/*
 + * This reads short-hand syntax that not only evaluates to a commit
 + * object name, but also can act as if the end user spelled the name
 + * of the branch from the command line.
 + *
 + * - "@{-N}" finds the name of the Nth previous branch we were on, and
 + *   places the name of the branch in the given buf and returns the
 + *   number of characters parsed if successful.
 + *
 + * - "<branch>@{upstream}" finds the name of the other ref that
 + *   <branch> is configured to merge with (missing <branch> defaults
 + *   to the current branch), and places the name of the branch in the
 + *   given buf and returns the number of characters parsed if
 + *   successful.
 + *
 + * If the input is not of the accepted format, it returns a negative
 + * number to signal an error.
 + *
 + * If the input was ok but there are not N branch switches in the
 + * reflog, it returns 0.
 + *
 + * If "allowed" is non-zero, it is a treated as a bitfield of allowable
 + * expansions: local branches ("refs/heads/"), remote branches
 + * ("refs/remotes/"), or "HEAD". If no "allowed" bits are set, any expansion is
 + * allowed, even ones to refs outside of those namespaces.
 + */
 +#define INTERPRET_BRANCH_LOCAL (1<<0)
 +#define INTERPRET_BRANCH_REMOTE (1<<1)
 +#define INTERPRET_BRANCH_HEAD (1<<2)
 +extern int interpret_branch_name(const char *str, int len, struct strbuf *,
 +                               unsigned allowed);
  extern int get_oid_mb(const char *str, struct object_id *oid);
  
  extern int validate_headref(const char *ref);
@@@ -1590,6 -1563,27 +1590,27 @@@ extern struct packed_git *find_sha1_pac
  
  extern void pack_report(void);
  
+ /*
+  * Create a temporary file rooted in the object database directory.
+  */
+ extern int odb_mkstemp(char *template, size_t limit, const char *pattern);
+ /*
+  * Generate the filename to be used for a pack file with checksum "sha1" and
+  * extension "ext". The result is written into the strbuf "buf", overwriting
+  * any existing contents. A pointer to buf->buf is returned as a convenience.
+  *
+  * Example: odb_pack_name(out, sha1, "idx") => ".git/objects/pack/pack-1234..idx"
+  */
+ extern char *odb_pack_name(struct strbuf *buf, const unsigned char *sha1, const char *ext);
+ /*
+  * Create a pack .keep file named "name" (which should generally be the output
+  * of odb_pack_name). Returns a file descriptor opened for writing, or -1 on
+  * error.
+  */
+ extern int odb_pack_keep(const char *name);
  /*
   * mmap the index file for the specified packfile (if it is not
   * already mmapped).  Return 0 on success.
@@@ -1846,11 -1840,8 +1867,11 @@@ extern int git_config_include(const cha
   *
   * (i.e., what gets handed to a config_fn_t). The caller provides the section;
   * we return -1 if it does not match, 0 otherwise. The subsection and key
 - * out-parameters are filled by the function (and subsection is NULL if it is
 + * out-parameters are filled by the function (and *subsection is NULL if it is
   * missing).
 + *
 + * If the subsection pointer-to-pointer passed in is NULL, returns 0 only if
 + * there is no subsection at all.
   */
  extern int parse_config_key(const char *var,
                            const char *section,
diff --combined environment.c
index 42dc3106d2fae1976dcfdfbf264a1a9ed96a71b6,4cd20d70671532ec2f33cb32bf62e8c3a45d7e8f..2fdba76222b8f5744f1ae84fd11e72a7a3c115cf
@@@ -259,7 -259,7 +259,7 @@@ void set_git_work_tree(const char *new_
                return;
        }
        git_work_tree_initialized = 1;
 -      work_tree = real_pathdup(new_work_tree);
 +      work_tree = real_pathdup(new_work_tree, 1);
  }
  
  const char *get_git_work_tree(void)
@@@ -296,18 -296,16 +296,16 @@@ int odb_mkstemp(char *template, size_t 
        return xmkstemp_mode(template, mode);
  }
  
- int odb_pack_keep(char *name, size_t namesz, const unsigned char *sha1)
+ int odb_pack_keep(const char *name)
  {
        int fd;
  
-       snprintf(name, namesz, "%s/pack/pack-%s.keep",
-                get_object_directory(), sha1_to_hex(sha1));
        fd = open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
        if (0 <= fd)
                return fd;
  
        /* slow path */
-       safe_create_leading_directories(name);
+       safe_create_leading_directories_const(name);
        return open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
  }
  
diff --combined git-compat-util.h
index e626851fe98673b4ac546864030975870ab4dfa7,412703b4ffb2f3061db32d5c779750d07392a882..8a4a3f85e7ba0a658420c477e1af82e804d7fd36
@@@ -639,6 -639,11 +639,6 @@@ extern int gitsetenv(const char *, cons
  extern char *gitmkdtemp(char *);
  #endif
  
 -#ifdef NO_MKSTEMPS
 -#define mkstemps gitmkstemps
 -extern int gitmkstemps(char *, int);
 -#endif
 -
  #ifdef NO_UNSETENV
  #define unsetenv gitunsetenv
  extern void gitunsetenv(const char *);
@@@ -798,8 -803,6 +798,6 @@@ extern FILE *xfopen(const char *path, c
  extern FILE *xfdopen(int fd, const char *mode);
  extern int xmkstemp(char *template);
  extern int xmkstemp_mode(char *template, int mode);
- extern int odb_mkstemp(char *template, size_t limit, const char *pattern);
- extern int odb_pack_keep(char *name, size_t namesz, const unsigned char *sha1);
  extern char *xgetcwd(void);
  extern FILE *fopen_for_writing(const char *path);
  
diff --combined sha1_file.c
index 8ce80d448195de1de9f6a6f712e5e9411301ddd1,df98c7f0dc24f9808ad9b3a84db966ff5938bb7a..d77b915db699f6f58731f645d6bcc188843d9eb8
@@@ -203,31 -203,26 +203,26 @@@ static const char *alt_sha1_path(struc
        return buf->buf;
  }
  
- /*
-  * Return the name of the pack or index file with the specified sha1
-  * in its filename.  *base and *name are scratch space that must be
-  * provided by the caller.  which should be "pack" or "idx".
-  */
- static char *sha1_get_pack_name(const unsigned char *sha1,
-                               struct strbuf *buf,
-                               const char *which)
+  char *odb_pack_name(struct strbuf *buf,
+                    const unsigned char *sha1,
+                    const char *ext)
  {
        strbuf_reset(buf);
        strbuf_addf(buf, "%s/pack/pack-%s.%s", get_object_directory(),
-                   sha1_to_hex(sha1), which);
+                   sha1_to_hex(sha1), ext);
        return buf->buf;
  }
  
  char *sha1_pack_name(const unsigned char *sha1)
  {
        static struct strbuf buf = STRBUF_INIT;
-       return sha1_get_pack_name(sha1, &buf, "pack");
+       return odb_pack_name(&buf, sha1, "pack");
  }
  
  char *sha1_pack_index_name(const unsigned char *sha1)
  {
        static struct strbuf buf = STRBUF_INIT;
-       return sha1_get_pack_name(sha1, &buf, "idx");
+       return odb_pack_name(&buf, sha1, "idx");
  }
  
  struct alternate_object_database *alt_odb_list;
@@@ -2532,7 -2527,6 +2527,7 @@@ void *unpack_entry(struct packed_git *p
        while (delta_stack_nr) {
                void *delta_data;
                void *base = data;
 +              void *external_base = NULL;
                unsigned long delta_size, base_size = size;
                int i;
  
                                      p->pack_name);
                                mark_bad_packed_object(p, base_sha1);
                                base = read_object(base_sha1, &type, &base_size);
 +                              external_base = base;
                        }
                }
  
                              "at offset %"PRIuMAX" from %s",
                              (uintmax_t)curpos, p->pack_name);
                        data = NULL;
 +                      free(external_base);
                        continue;
                }
  
                        error("failed to apply delta");
  
                free(delta_data);
 +              free(external_base);
        }
  
        *final_type = type;