refspec.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #ifndef REFSPEC_H
  2. #define REFSPEC_H
  3. #define TAG_REFSPEC "refs/tags/*:refs/tags/*"
  4. extern const struct refspec_item *tag_refspec;
  5. /**
  6. * A struct refspec_item holds the parsed interpretation of a refspec. If it
  7. * will force updates (starts with a '+'), force is true. If it is a pattern
  8. * (sides end with '*') pattern is true. If it is a negative refspec, (starts
  9. * with '^'), negative is true. src and dest are the two sides (including '*'
  10. * characters if present); if there is only one side, it is src, and dst is
  11. * NULL; if sides exist but are empty (i.e., the refspec either starts or ends
  12. * with ':'), the corresponding side is "".
  13. *
  14. * remote_find_tracking(), given a remote and a struct refspec_item with either src
  15. * or dst filled out, will fill out the other such that the result is in the
  16. * "fetch" specification for the remote (note that this evaluates patterns and
  17. * returns a single result).
  18. */
  19. struct refspec_item {
  20. unsigned force : 1;
  21. unsigned pattern : 1;
  22. unsigned matching : 1;
  23. unsigned exact_sha1 : 1;
  24. unsigned negative : 1;
  25. char *src;
  26. char *dst;
  27. };
  28. #define REFSPEC_FETCH 1
  29. #define REFSPEC_PUSH 0
  30. #define REFSPEC_INIT_FETCH { .fetch = REFSPEC_FETCH }
  31. #define REFSPEC_INIT_PUSH { .fetch = REFSPEC_PUSH }
  32. /**
  33. * An array of strings can be parsed into a struct refspec using
  34. * parse_fetch_refspec() or parse_push_refspec().
  35. */
  36. struct refspec {
  37. struct refspec_item *items;
  38. int alloc;
  39. int nr;
  40. const char **raw;
  41. int raw_alloc;
  42. int raw_nr;
  43. int fetch;
  44. };
  45. int refspec_item_init(struct refspec_item *item, const char *refspec,
  46. int fetch);
  47. void refspec_item_init_or_die(struct refspec_item *item, const char *refspec,
  48. int fetch);
  49. void refspec_item_clear(struct refspec_item *item);
  50. void refspec_init(struct refspec *rs, int fetch);
  51. void refspec_append(struct refspec *rs, const char *refspec);
  52. __attribute__((format (printf,2,3)))
  53. void refspec_appendf(struct refspec *rs, const char *fmt, ...);
  54. void refspec_appendn(struct refspec *rs, const char **refspecs, int nr);
  55. void refspec_clear(struct refspec *rs);
  56. int valid_fetch_refspec(const char *refspec);
  57. struct strvec;
  58. /*
  59. * Determine what <prefix> values to pass to the peer in ref-prefix lines
  60. * (see Documentation/technical/protocol-v2.txt).
  61. */
  62. void refspec_ref_prefixes(const struct refspec *rs,
  63. struct strvec *ref_prefixes);
  64. #endif /* REFSPEC_H */