THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
git
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

299 lines
8.2KB

  1. #ifndef REMOTE_H
  2. #define REMOTE_H
  3. #include "cache.h"
  4. #include "parse-options.h"
  5. #include "hashmap.h"
  6. #include "refspec.h"
  7. enum {
  8. REMOTE_UNCONFIGURED = 0,
  9. REMOTE_CONFIG,
  10. REMOTE_REMOTES,
  11. REMOTE_BRANCHES
  12. };
  13. struct remote {
  14. struct hashmap_entry ent;
  15. const char *name;
  16. int origin, configured_in_repo;
  17. const char *foreign_vcs;
  18. const char **url;
  19. int url_nr;
  20. int url_alloc;
  21. const char **pushurl;
  22. int pushurl_nr;
  23. int pushurl_alloc;
  24. struct refspec push;
  25. struct refspec fetch;
  26. /*
  27. * -1 to never fetch tags
  28. * 0 to auto-follow tags on heuristic (default)
  29. * 1 to always auto-follow tags
  30. * 2 to always fetch tags
  31. */
  32. int fetch_tags;
  33. int skip_default_update;
  34. int mirror;
  35. int prune;
  36. int prune_tags;
  37. const char *receivepack;
  38. const char *uploadpack;
  39. /*
  40. * for curl remotes only
  41. */
  42. char *http_proxy;
  43. char *http_proxy_authmethod;
  44. };
  45. struct remote *remote_get(const char *name);
  46. struct remote *pushremote_get(const char *name);
  47. int remote_is_configured(struct remote *remote, int in_repo);
  48. typedef int each_remote_fn(struct remote *remote, void *priv);
  49. int for_each_remote(each_remote_fn fn, void *priv);
  50. int remote_has_url(struct remote *remote, const char *url);
  51. struct ref {
  52. struct ref *next;
  53. struct object_id old_oid;
  54. struct object_id new_oid;
  55. struct object_id old_oid_expect; /* used by expect-old */
  56. char *symref;
  57. unsigned int
  58. force:1,
  59. forced_update:1,
  60. expect_old_sha1:1,
  61. exact_oid:1,
  62. deletion:1;
  63. enum {
  64. REF_NOT_MATCHED = 0, /* initial value */
  65. REF_MATCHED,
  66. REF_UNADVERTISED_NOT_ALLOWED
  67. } match_status;
  68. /*
  69. * Order is important here, as we write to FETCH_HEAD
  70. * in numeric order. And the default NOT_FOR_MERGE
  71. * should be 0, so that xcalloc'd structures get it
  72. * by default.
  73. */
  74. enum {
  75. FETCH_HEAD_MERGE = -1,
  76. FETCH_HEAD_NOT_FOR_MERGE = 0,
  77. FETCH_HEAD_IGNORE = 1
  78. } fetch_head_status;
  79. enum {
  80. REF_STATUS_NONE = 0,
  81. REF_STATUS_OK,
  82. REF_STATUS_REJECT_NONFASTFORWARD,
  83. REF_STATUS_REJECT_ALREADY_EXISTS,
  84. REF_STATUS_REJECT_NODELETE,
  85. REF_STATUS_REJECT_FETCH_FIRST,
  86. REF_STATUS_REJECT_NEEDS_FORCE,
  87. REF_STATUS_REJECT_STALE,
  88. REF_STATUS_REJECT_SHALLOW,
  89. REF_STATUS_UPTODATE,
  90. REF_STATUS_REMOTE_REJECT,
  91. REF_STATUS_EXPECTING_REPORT,
  92. REF_STATUS_ATOMIC_PUSH_FAILED
  93. } status;
  94. char *remote_status;
  95. struct ref *peer_ref; /* when renaming */
  96. char name[FLEX_ARRAY]; /* more */
  97. };
  98. #define REF_NORMAL (1u << 0)
  99. #define REF_HEADS (1u << 1)
  100. #define REF_TAGS (1u << 2)
  101. struct ref *find_ref_by_name(const struct ref *list, const char *name);
  102. struct ref *alloc_ref(const char *name);
  103. struct ref *copy_ref(const struct ref *ref);
  104. struct ref *copy_ref_list(const struct ref *ref);
  105. void sort_ref_list(struct ref **, int (*cmp)(const void *, const void *));
  106. int count_refspec_match(const char *, struct ref *refs, struct ref **matched_ref);
  107. int ref_compare_name(const void *, const void *);
  108. int check_ref_type(const struct ref *ref, int flags);
  109. /*
  110. * Free a single ref and its peer, or an entire list of refs and their peers,
  111. * respectively.
  112. */
  113. void free_one_ref(struct ref *ref);
  114. void free_refs(struct ref *ref);
  115. struct oid_array;
  116. struct packet_reader;
  117. struct argv_array;
  118. struct string_list;
  119. struct ref **get_remote_heads(struct packet_reader *reader,
  120. struct ref **list, unsigned int flags,
  121. struct oid_array *extra_have,
  122. struct oid_array *shallow_points);
  123. /* Used for protocol v2 in order to retrieve refs from a remote */
  124. struct ref **get_remote_refs(int fd_out, struct packet_reader *reader,
  125. struct ref **list, int for_push,
  126. const struct argv_array *ref_prefixes,
  127. const struct string_list *server_options);
  128. int resolve_remote_symref(struct ref *ref, struct ref *list);
  129. /*
  130. * Remove and free all but the first of any entries in the input list
  131. * that map the same remote reference to the same local reference. If
  132. * there are two entries that map different remote references to the
  133. * same local reference, emit an error message and die. Return a
  134. * pointer to the head of the resulting list.
  135. */
  136. struct ref *ref_remove_duplicates(struct ref *ref_map);
  137. int query_refspecs(struct refspec *rs, struct refspec_item *query);
  138. char *apply_refspecs(struct refspec *rs, const char *name);
  139. int check_push_refs(struct ref *src, struct refspec *rs);
  140. int match_push_refs(struct ref *src, struct ref **dst,
  141. struct refspec *rs, int flags);
  142. void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
  143. int force_update);
  144. /*
  145. * Given a list of the remote refs and the specification of things to
  146. * fetch, makes a (separate) list of the refs to fetch and the local
  147. * refs to store into.
  148. *
  149. * *tail is the pointer to the tail pointer of the list of results
  150. * beforehand, and will be set to the tail pointer of the list of
  151. * results afterward.
  152. *
  153. * missing_ok is usually false, but when we are adding branch.$name.merge
  154. * it is Ok if the branch is not at the remote anymore.
  155. */
  156. int get_fetch_map(const struct ref *remote_refs, const struct refspec_item *refspec,
  157. struct ref ***tail, int missing_ok);
  158. struct ref *get_remote_ref(const struct ref *remote_refs, const char *name);
  159. /*
  160. * For the given remote, reads the refspec's src and sets the other fields.
  161. */
  162. int remote_find_tracking(struct remote *remote, struct refspec_item *refspec);
  163. struct branch {
  164. const char *name;
  165. const char *refname;
  166. const char *remote_name;
  167. const char *pushremote_name;
  168. const char **merge_name;
  169. struct refspec_item **merge;
  170. int merge_nr;
  171. int merge_alloc;
  172. const char *push_tracking_ref;
  173. };
  174. struct branch *branch_get(const char *name);
  175. const char *remote_for_branch(struct branch *branch, int *explicit);
  176. const char *pushremote_for_branch(struct branch *branch, int *explicit);
  177. const char *remote_ref_for_branch(struct branch *branch, int for_push,
  178. int *explicit);
  179. int branch_has_merge_config(struct branch *branch);
  180. int branch_merge_matches(struct branch *, int n, const char *);
  181. /**
  182. * Return the fully-qualified refname of the tracking branch for `branch`.
  183. * I.e., what "branch@{upstream}" would give you. Returns NULL if no
  184. * upstream is defined.
  185. *
  186. * If `err` is not NULL and no upstream is defined, a more specific error
  187. * message is recorded there (if the function does not return NULL, then
  188. * `err` is not touched).
  189. */
  190. const char *branch_get_upstream(struct branch *branch, struct strbuf *err);
  191. /**
  192. * Return the tracking branch that corresponds to the ref we would push to
  193. * given a bare `git push` while `branch` is checked out.
  194. *
  195. * The return value and `err` conventions match those of `branch_get_upstream`.
  196. */
  197. const char *branch_get_push(struct branch *branch, struct strbuf *err);
  198. /* Flags to match_refs. */
  199. enum match_refs_flags {
  200. MATCH_REFS_NONE = 0,
  201. MATCH_REFS_ALL = (1 << 0),
  202. MATCH_REFS_MIRROR = (1 << 1),
  203. MATCH_REFS_PRUNE = (1 << 2),
  204. MATCH_REFS_FOLLOW_TAGS = (1 << 3)
  205. };
  206. /* Flags for --ahead-behind option. */
  207. enum ahead_behind_flags {
  208. AHEAD_BEHIND_UNSPECIFIED = -1,
  209. AHEAD_BEHIND_QUICK = 0, /* just eq/neq reporting */
  210. AHEAD_BEHIND_FULL = 1, /* traditional a/b reporting */
  211. };
  212. /* Reporting of tracking info */
  213. int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs,
  214. const char **upstream_name, int for_push,
  215. enum ahead_behind_flags abf);
  216. int format_tracking_info(struct branch *branch, struct strbuf *sb,
  217. enum ahead_behind_flags abf);
  218. struct ref *get_local_heads(void);
  219. /*
  220. * Find refs from a list which are likely to be pointed to by the given HEAD
  221. * ref. If 'all' is false, returns the most likely ref; otherwise, returns a
  222. * list of all candidate refs. If no match is found (or 'head' is NULL),
  223. * returns NULL. All returns are newly allocated and should be freed.
  224. */
  225. struct ref *guess_remote_head(const struct ref *head,
  226. const struct ref *refs,
  227. int all);
  228. /* Return refs which no longer exist on remote */
  229. struct ref *get_stale_heads(struct refspec *rs, struct ref *fetch_map);
  230. /*
  231. * Compare-and-swap
  232. */
  233. #define CAS_OPT_NAME "force-with-lease"
  234. struct push_cas_option {
  235. unsigned use_tracking_for_rest:1;
  236. struct push_cas {
  237. struct object_id expect;
  238. unsigned use_tracking:1;
  239. char *refname;
  240. } *entry;
  241. int nr;
  242. int alloc;
  243. };
  244. int parseopt_push_cas_option(const struct option *, const char *arg, int unset);
  245. int is_empty_cas(const struct push_cas_option *);
  246. void apply_push_cas(struct push_cas_option *, struct remote *, struct ref *);
  247. #endif