OSDN Git Service

Merge branch 'jc/push-cas'
authorJunio C Hamano <gitster@pobox.com>
Mon, 9 Sep 2013 21:30:29 +0000 (14:30 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 9 Sep 2013 21:30:29 +0000 (14:30 -0700)
Allow a safer "rewind of the remote tip" push than blind "--force",
by requiring that the overwritten remote ref to be unchanged since
the new history to replace it was prepared.

The machinery is more or less ready.  The "--force" option is again
the big red button to override any safety, thanks to J6t's sanity
(the original round allowed --lockref to defeat --force).

The logic to choose the default implemented here is fragile
(e.g. "git fetch" after seeing a failure will update the
remote-tracking branch and will make the next "push" pass,
defeating the safety pretty easily).  It is suitable only for the
simplest workflows, and it may hurt users more than it helps them.

* jc/push-cas:
  push: teach --force-with-lease to smart-http transport
  send-pack: fix parsing of --force-with-lease option
  t5540/5541: smart-http does not support "--force-with-lease"
  t5533: test "push --force-with-lease"
  push --force-with-lease: tie it all together
  push --force-with-lease: implement logic to populate old_sha1_expect[]
  remote.c: add command line option parser for "--force-with-lease"
  builtin/push.c: use OPT_BOOL, not OPT_BOOLEAN
  cache.h: move remote/connect API out of it

1  2 
builtin/fetch-pack.c
builtin/push.c
cache.h
fetch-pack.c
refs.c
remote-curl.c
remote.c
remote.h
transport-helper.c

Simple merge
diff --cc builtin/push.c
Simple merge
diff --cc cache.h
Simple merge
diff --cc fetch-pack.c
@@@ -9,9 -9,9 +9,10 @@@
  #include "fetch-pack.h"
  #include "remote.h"
  #include "run-command.h"
+ #include "connect.h"
  #include "transport.h"
  #include "version.h"
 +#include "prio-queue.h"
  
  static int transfer_unpack_limit = -1;
  static int fetch_unpack_limit = -1;
diff --cc refs.c
Simple merge
diff --cc remote-curl.c
@@@ -6,8 -6,8 +6,9 @@@
  #include "exec_cmd.h"
  #include "run-command.h"
  #include "pkt-line.h"
+ #include "string-list.h"
  #include "sideband.h"
 +#include "argv-array.h"
  
  static struct remote *remote;
  static const char *url; /* always ends with a trailing slash */
@@@ -68,15 -68,13 +70,22 @@@ static int set_option(const char *name
                        return -1;
                return 0;
        }
 +      else if (!strcmp(name, "check-connectivity")) {
 +              if (!strcmp(value, "true"))
 +                      options.check_self_contained_and_connected = 1;
 +              else if (!strcmp(value, "false"))
 +                      options.check_self_contained_and_connected = 0;
 +              else
 +                      return -1;
 +              return 0;
 +      }
+       else if (!strcmp(name, "cas")) {
+               struct strbuf val = STRBUF_INIT;
+               strbuf_addf(&val, "--" CAS_OPT_NAME "=%s", value);
+               string_list_append(&cas_options, val.buf);
+               strbuf_release(&val);
+               return 0;
+       }
        else {
                return 1 /* unsupported */;
        }
@@@ -800,25 -796,31 +809,28 @@@ static int push_dav(int nr_spec, char *
  static int push_git(struct discovery *heads, int nr_spec, char **specs)
  {
        struct rpc_state rpc;
 -      const char **argv;
 -      int argc = 0, i, err;
 +      int i, err;
 +      struct argv_array args;
+       struct string_list_item *cas_option;
  
 -      argv = xmalloc((10 + nr_spec + cas_options.nr) * sizeof(char *));
 -      argv[argc++] = "send-pack";
 -      argv[argc++] = "--stateless-rpc";
 -      argv[argc++] = "--helper-status";
 +      argv_array_init(&args);
 +      argv_array_pushl(&args, "send-pack", "--stateless-rpc", "--helper-status",
 +                       NULL);
 +
        if (options.thin)
 -              argv[argc++] = "--thin";
 +              argv_array_push(&args, "--thin");
        if (options.dry_run)
 -              argv[argc++] = "--dry-run";
 +              argv_array_push(&args, "--dry-run");
        if (options.verbosity == 0)
 -              argv[argc++] = "--quiet";
 +              argv_array_push(&args, "--quiet");
        else if (options.verbosity > 1)
 -              argv[argc++] = "--verbose";
 -      argv[argc++] = options.progress ? "--progress" : "--no-progress";
 -
 +              argv_array_push(&args, "--verbose");
 +      argv_array_push(&args, options.progress ? "--progress" : "--no-progress");
+       for_each_string_list_item(cas_option, &cas_options)
 -              argv[argc++] = cas_option->string;
 -
 -      argv[argc++] = url;
++              argv_array_push(&args, cas_option->string);
 +      argv_array_push(&args, url);
        for (i = 0; i < nr_spec; i++)
 -              argv[argc++] = specs[i];
 -      argv[argc++] = NULL;
 +              argv_array_push(&args, specs[i]);
  
        memset(&rpc, 0, sizeof(rpc));
        rpc.service_name = "git-receive-pack",
diff --cc remote.c
+++ b/remote.c
@@@ -1305,14 -1302,14 +1305,22 @@@ static void add_missing_tags(struct re
        free(sent_tips.tip);
  }
  
+ struct ref *find_ref_by_name(const struct ref *list, const char *name)
+ {
+       for ( ; list; list = list->next)
+               if (!strcmp(list->name, name))
+                       return (struct ref *)list;
+       return NULL;
+ }
 +static void prepare_ref_index(struct string_list *ref_index, struct ref *ref)
 +{
 +      for ( ; ref; ref = ref->next)
 +              string_list_append_nodup(ref_index, ref->name)->util = ref;
 +
 +      sort_string_list(ref_index);
 +}
 +
  /*
   * Given the set of refs the local repository has, the set of refs the
   * remote repository has, and the refspec used for push, determine
diff --cc remote.h
Simple merge
Simple merge