Merge branch 'mh/refs-have-new'
authorJunio C Hamano <gitster@pobox.com>
Thu, 5 Mar 2015 20:45:39 +0000 (12:45 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 5 Mar 2015 20:45:39 +0000 (12:45 -0800)
Simplify the ref transaction API around how "the ref should be
pointing at this object" is specified.

* mh/refs-have-new:
refs.h: remove duplication in function docstrings
update_ref(): improve documentation
ref_transaction_verify(): new function to check a reference's value
ref_transaction_delete(): check that old_sha1 is not null_sha1
ref_transaction_create(): check that new_sha1 is valid
commit: avoid race when creating orphan commits
commit: add tests of commit races
ref_transaction_delete(): remove "have_old" parameter
ref_transaction_update(): remove "have_old" parameter
struct ref_update: move "have_old" into "flags"
refs.c: change some "flags" to "unsigned int"
refs: remove the gap in the REF_* constant values
refs: move REF_DELETING to refs.c

1  2 
builtin/commit.c
builtin/fetch.c
cache.h
fast-import.c
diff --combined builtin/commit.c
index 6055c760f037617637eb7bffebe82213748b5e59,682f922c736dbaaa918a9f27c07487e3f15ec286..961e467242747dac07aa6f5e619e2d1a50570b06
@@@ -1050,7 -1050,7 +1050,7 @@@ static const char *find_author_by_nickn
                clear_mailmap(&mailmap);
                return strbuf_detach(&buf, NULL);
        }
 -      die(_("No existing author found with '%s'"), name);
 +      die(_("--author '%s' is not 'Name <email>' and matches no existing author"), name);
  }
  
  
@@@ -1766,8 -1766,8 +1766,8 @@@ int cmd_commit(int argc, const char **a
        if (!transaction ||
            ref_transaction_update(transaction, "HEAD", sha1,
                                   current_head
-                                  ? current_head->object.sha1 : NULL,
-                                  0, !!current_head, sb.buf, &err) ||
+                                  ? current_head->object.sha1 : null_sha1,
+                                  0, sb.buf, &err) ||
            ref_transaction_commit(transaction, &err)) {
                rollback_index_files();
                die("%s", err.buf);
diff --combined builtin/fetch.c
index 75a55e590bdc3411e5e4aeee6275fbfff4451904,719bf4f244ba5e6dcb40c9c8e578aa1cdfeee53e..f9512652cf1389a770bd94fd170d123206e024c5
@@@ -11,6 -11,7 +11,6 @@@
  #include "run-command.h"
  #include "parse-options.h"
  #include "sigchain.h"
 -#include "transport.h"
  #include "submodule.h"
  #include "connected.h"
  #include "argv-array.h"
@@@ -415,8 -416,10 +415,10 @@@ static int s_update_ref(const char *act
  
        transaction = ref_transaction_begin(&err);
        if (!transaction ||
-           ref_transaction_update(transaction, ref->name, ref->new_sha1,
-                                  ref->old_sha1, 0, check_old, msg, &err))
+           ref_transaction_update(transaction, ref->name,
+                                  ref->new_sha1,
+                                  check_old ? ref->old_sha1 : NULL,
+                                  0, msg, &err))
                goto fail;
  
        ret = ref_transaction_commit(transaction, &err);
diff --combined cache.h
index 4d02efc905456e61ce841ec1db2cc19491346257,ab265be1cd0c042e1c83c341e6f4bd39be169d1e..761c5704b2e21f5dcd68fdcc9c3b1247ab0cfd18
+++ b/cache.h
@@@ -568,7 -568,7 +568,7 @@@ extern void update_index_if_able(struc
  extern int hold_locked_index(struct lock_file *, int);
  extern void set_alternate_index_output(const char *);
  
- extern int delete_ref(const char *, const unsigned char *sha1, int delopt);
+ extern int delete_ref(const char *, const unsigned char *sha1, unsigned int flags);
  
  /* Environment bits from configuration mechanism */
  extern int trust_executable_bit;
@@@ -1254,10 -1254,6 +1254,10 @@@ extern int unpack_object_header(struct 
   *
   * Any callback that is NULL will be ignored. Callbacks returning non-zero
   * will end the iteration.
 + *
 + * In the "buf" variant, "path" is a strbuf which will also be used as a
 + * scratch buffer, but restored to its original contents before
 + * the function returns.
   */
  typedef int each_loose_object_fn(const unsigned char *sha1,
                                 const char *path,
@@@ -1273,11 -1269,6 +1273,11 @@@ int for_each_loose_file_in_objdir(cons
                                  each_loose_cruft_fn cruft_cb,
                                  each_loose_subdir_fn subdir_cb,
                                  void *data);
 +int for_each_loose_file_in_objdir_buf(struct strbuf *path,
 +                                    each_loose_object_fn obj_cb,
 +                                    each_loose_cruft_fn cruft_cb,
 +                                    each_loose_subdir_fn subdir_cb,
 +                                    void *data);
  
  /*
   * Iterate over loose and packed objects in both the local
@@@ -1507,7 -1498,7 +1507,7 @@@ extern const char *pager_program
  extern int pager_in_use(void);
  extern int pager_use_color;
  extern int term_columns(void);
 -extern int decimal_width(int);
 +extern int decimal_width(uintmax_t);
  extern int check_pager_config(const char *cmd);
  
  extern const char *editor_program;
diff --combined fast-import.c
index aac2c24f74e496d11b66e1cc2806c55555f71496,1e72bfbd4c6a7fabbc3fb447696b4101db5463db..b82fcdd24e34d9191aae33fed4e8afb3ca4b6f6a
@@@ -947,12 -947,9 +947,12 @@@ static void unkeep_all_packs(void
  
  static void end_packfile(void)
  {
 -      if (!pack_data)
 +      static int running;
 +
 +      if (running || !pack_data)
                return;
  
 +      running = 1;
        clear_delta_base_cache();
        if (object_count) {
                struct packed_git *new_p;
        }
        free(pack_data);
        pack_data = NULL;
 +      running = 0;
  
        /* We can't carry a delta across packfiles. */
        strbuf_release(&last_blob.data);
@@@ -1720,7 -1716,7 +1720,7 @@@ static int update_branch(struct branch 
        transaction = ref_transaction_begin(&err);
        if (!transaction ||
            ref_transaction_update(transaction, b->name, b->sha1, old_sha1,
-                                  0, 1, msg, &err) ||
+                                  0, msg, &err) ||
            ref_transaction_commit(transaction, &err)) {
                ref_transaction_free(transaction);
                error("%s", err.buf);
@@@ -1760,8 -1756,8 +1760,8 @@@ static void dump_tags(void
                strbuf_reset(&ref_name);
                strbuf_addf(&ref_name, "refs/tags/%s", t->name);
  
-               if (ref_transaction_update(transaction, ref_name.buf, t->sha1,
-                                          NULL, 0, 0, msg, &err)) {
+               if (ref_transaction_update(transaction, ref_name.buf,
+                                          t->sha1, NULL, 0, msg, &err)) {
                        failure |= error("%s", err.buf);
                        goto cleanup;
                }