1978
{
1979
return parse_push_cas_option(opt->value, arg, unset);
1980
}
1981
+
1982
+int is_empty_cas(const struct push_cas_option *cas)
1983
+{
1984
+ return !cas->use_tracking_for_rest && !cas->nr;
1985
+}
1986
+
1987
+/*
1988
+ * Look at remote.fetch refspec and see if we have a remote
1989
+ * tracking branch for the refname there. Fill its current
1990
+ * value in sha1[].
1991
+ * If we cannot do so, return negative to signal an error.
1992
+ */
1993
+static int remote_tracking(struct remote *remote, const char *refname,
1994
+ unsigned char sha1[20])
1995
+{
1996
+ char *dst;
1997
+
1998
+ dst = apply_refspecs(remote->fetch, remote->fetch_refspec_nr, refname);
1999
+ if (!dst)
2000
+ return -1; /* no tracking ref for refname at remote */
2001
+ if (read_ref(dst, sha1))
2002
+ return -1; /* we know what the tracking ref is but we cannot read it */
2003
+ return 0;
2004
+}
2005
+
2006
+static void apply_cas(struct push_cas_option *cas,
2007
+ struct remote *remote,
2008
+ struct ref *ref)
2009
+{
2010
+ int i;
2011
+
2012
+ /* Find an explicit --<option>=<name>[:<value>] entry */
2013
+ for (i = 0; i < cas->nr; i++) {
2014
+ struct push_cas *entry = &cas->entry[i];
2015
+ if (!refname_match(entry->refname, ref->name, ref_rev_parse_rules))
2016
+ continue;
2017
+ ref->expect_old_sha1 = 1;
2018
+ if (!entry->use_tracking)
2019
+ hashcpy(ref->old_sha1_expect, cas->entry[i].expect);
2020
+ else if (remote_tracking(remote, ref->name, ref->old_sha1_expect))
2021
+ ref->expect_old_no_trackback = 1;
2022
+ return;
2023
+ }
2024
+
2025
+ /* Are we using "--<option>" to cover all? */
2026
+ if (!cas->use_tracking_for_rest)
2027
+ return;
2028
+
2029
+ ref->expect_old_sha1 = 1;
2030
+ if (remote_tracking(remote, ref->name, ref->old_sha1_expect))
2031
+ ref->expect_old_no_trackback = 1;
2032
+}
2033
+
2034
+void apply_push_cas(struct push_cas_option *cas,
2035
+ struct remote *remote,
2036
+ struct ref *remote_refs)
2037
+{
2038
+ struct ref *ref;
2039
+ for (ref = remote_refs; ref; ref = ref->next)
2040
+ apply_cas(cas, remote, ref);
2041
+}