clean up error conventions of remote.c:match_explicit

match_explicit is called for each push refspec to try to
fully resolve the source and destination sides of the
refspec.  Currently, we look at each refspec and report
errors on both the source and the dest side before aborting.

It makes sense to report errors for each refspec, since an
error in one is independent of an error in the other.
However, reporting errors on the 'dst' side of a refspec if
there has been an error on the 'src' side does not
necessarily make sense, since the interpretation of the
'dst' side depends on the 'src' side (for example, when
creating a new unqualified remote ref, we use the same type
as the src ref).

This patch lets match_explicit return early when the src
side of the refspec is bogus. We still look at all of the
refspecs before aborting the push, though.

At the same time, we clean up the call signature, which
previously took an extra "errs" flag. This was pointless, as
we didn't act on that flag, but rather just passed it back
to the caller. Instead, we now use the more traditional
"return -1" to signal an error, and the caller aggregates
the error count.

This change fixes two bugs, as well:

  - the early return avoids a segfault when passing a NULL
    matched_src to guess_ref()

  - the check for multiple sources pointing to a single dest
    aborted if the "err" flag was set. Presumably the intent
    was not to bother with the check if we had no
    matched_src. However, since the err flag was passed in
    from the caller, we might abort the check just because a
    previous refspec had a problem, which doesn't make
    sense.

    In practice, this didn't matter, since due to the error
    flag we end up aborting the push anyway.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 files changed
tree: cb89f7147813ab167fa249ec681b143e1a737c92
  1. .gitattributes
  2. .gitignore
  3. .mailmap
  4. COPYING
  5. Documentation/
  6. GIT-VERSION-GEN
  7. INSTALL
  8. Makefile
  9. README
  10. alias.c
  11. alloc.c
  12. archive-tar.c
  13. archive-zip.c
  14. archive.c
  15. archive.h
  16. arm/
  17. attr.c
  18. attr.h
  19. base85.c
  20. blob.c
  21. blob.h
  22. branch.c
  23. branch.h
  24. builtin-add.c
  25. builtin-annotate.c
  26. builtin-apply.c
  27. builtin-archive.c
  28. builtin-blame.c
  29. builtin-branch.c
  30. builtin-bundle.c
  31. builtin-cat-file.c
  32. builtin-check-attr.c
  33. builtin-check-ref-format.c
  34. builtin-checkout-index.c
  35. builtin-checkout.c
  36. builtin-clean.c
  37. builtin-clone.c
  38. builtin-commit-tree.c
  39. builtin-commit.c
  40. builtin-config.c
  41. builtin-count-objects.c
  42. builtin-describe.c
  43. builtin-diff-files.c
  44. builtin-diff-index.c
  45. builtin-diff-tree.c
  46. builtin-diff.c
  47. builtin-fast-export.c
  48. builtin-fetch--tool.c
  49. builtin-fetch-pack.c
  50. builtin-fetch.c
  51. builtin-fmt-merge-msg.c
  52. builtin-for-each-ref.c
  53. builtin-fsck.c
  54. builtin-gc.c
  55. builtin-grep.c
  56. builtin-http-fetch.c
  57. builtin-init-db.c
  58. builtin-log.c
  59. builtin-ls-files.c
  60. builtin-ls-remote.c
  61. builtin-ls-tree.c
  62. builtin-mailinfo.c
  63. builtin-mailsplit.c
  64. builtin-merge-base.c
  65. builtin-merge-file.c
  66. builtin-merge-ours.c
  67. builtin-merge-recursive.c
  68. builtin-mv.c
  69. builtin-name-rev.c
  70. builtin-pack-objects.c
  71. builtin-pack-refs.c
  72. builtin-prune-packed.c
  73. builtin-prune.c
  74. builtin-push.c
  75. builtin-read-tree.c
  76. builtin-reflog.c
  77. builtin-remote.c
  78. builtin-rerere.c
  79. builtin-reset.c
  80. builtin-rev-list.c
  81. builtin-rev-parse.c
  82. builtin-revert.c
  83. builtin-rm.c
  84. builtin-send-pack.c
  85. builtin-shortlog.c
  86. builtin-show-branch.c
  87. builtin-show-ref.c
  88. builtin-stripspace.c
  89. builtin-symbolic-ref.c
  90. builtin-tag.c
  91. builtin-tar-tree.c
  92. builtin-unpack-objects.c
  93. builtin-update-index.c
  94. builtin-update-ref.c
  95. builtin-upload-archive.c
  96. builtin-verify-pack.c
  97. builtin-verify-tag.c
  98. builtin-write-tree.c
  99. builtin.h
  100. bundle.c
  101. bundle.h
  102. cache-tree.c
  103. cache-tree.h
  104. cache.h
  105. check-builtins.sh
  106. check-racy.c
  107. color.c
  108. color.h
  109. combine-diff.c
  110. command-list.txt
  111. commit.c
  112. commit.h
  113. compat/
  114. config.c
  115. config.mak.in
  116. configure.ac
  117. connect.c
  118. contrib/
  119. convert.c
  120. copy.c
  121. csum-file.c
  122. csum-file.h
  123. ctype.c
  124. daemon.c
  125. date.c
  126. decorate.c
  127. decorate.h
  128. delta.h
  129. diff-delta.c
  130. diff-lib.c
  131. diff-no-index.c
  132. diff.c
  133. diff.h
  134. diffcore-break.c
  135. diffcore-delta.c
  136. diffcore-order.c
  137. diffcore-pickaxe.c
  138. diffcore-rename.c
  139. diffcore.h
  140. dir.c
  141. dir.h
  142. dump-cache-tree.c
  143. entry.c
  144. environment.c
  145. exec_cmd.c
  146. exec_cmd.h
  147. fast-import.c
  148. fetch-pack.h
  149. fixup-builtins
  150. fsck.c
  151. fsck.h
  152. generate-cmdlist.sh
  153. git-add--interactive.perl
  154. git-am.sh
  155. git-archimport.perl
  156. git-bisect.sh
  157. git-compat-util.h
  158. git-cvsexportcommit.perl
  159. git-cvsimport.perl
  160. git-cvsserver.perl
  161. git-filter-branch.sh
  162. git-gui/
  163. git-instaweb.sh
  164. git-lost-found.sh
  165. git-merge-octopus.sh
  166. git-merge-one-file.sh
  167. git-merge-resolve.sh
  168. git-merge-stupid.sh
  169. git-merge.sh
  170. git-mergetool.sh
  171. git-parse-remote.sh
  172. git-pull.sh
  173. git-quiltimport.sh
  174. git-rebase--interactive.sh
  175. git-rebase.sh
  176. git-relink.perl
  177. git-repack.sh
  178. git-request-pull.sh
  179. git-send-email.perl
  180. git-sh-setup.sh
  181. git-stash.sh
  182. git-submodule.sh
  183. git-svn.perl
  184. git-web--browse.sh
  185. git.c
  186. git.spec.in
  187. gitk-git/
  188. gitweb/
  189. graph.c
  190. graph.h
  191. grep.c
  192. grep.h
  193. hash-object.c
  194. hash.c
  195. hash.h
  196. help.c
  197. http-push.c
  198. http-walker.c
  199. http.c
  200. http.h
  201. ident.c
  202. imap-send.c
  203. index-pack.c
  204. interpolate.c
  205. interpolate.h
  206. list-objects.c
  207. list-objects.h
  208. ll-merge.c
  209. ll-merge.h
  210. lockfile.c
  211. log-tree.c
  212. log-tree.h
  213. mailmap.c
  214. mailmap.h
  215. match-trees.c
  216. merge-file.c
  217. merge-index.c
  218. merge-recursive.h
  219. merge-tree.c
  220. mktag.c
  221. mktree.c
  222. mozilla-sha1/
  223. name-hash.c
  224. object.c
  225. object.h
  226. pack-check.c
  227. pack-redundant.c
  228. pack-revindex.c
  229. pack-revindex.h
  230. pack-write.c
  231. pack.h
  232. pager.c
  233. parse-options.c
  234. parse-options.h
  235. patch-delta.c
  236. patch-id.c
  237. patch-ids.c
  238. patch-ids.h
  239. path-list.c
  240. path-list.h
  241. path.c
  242. perl/
  243. pkt-line.c
  244. pkt-line.h
  245. ppc/
  246. pretty.c
  247. progress.c
  248. progress.h
  249. quote.c
  250. quote.h
  251. reachable.c
  252. reachable.h
  253. read-cache.c
  254. receive-pack.c
  255. reflog-walk.c
  256. reflog-walk.h
  257. refs.c
  258. refs.h
  259. remote.c
  260. remote.h
  261. revision.c
  262. revision.h
  263. run-command.c
  264. run-command.h
  265. send-pack.h
  266. server-info.c
  267. setup.c
  268. sha1-lookup.c
  269. sha1-lookup.h
  270. sha1_file.c
  271. sha1_name.c
  272. shallow.c
  273. shell.c
  274. shortlog.h
  275. show-index.c
  276. sideband.c
  277. sideband.h
  278. strbuf.c
  279. strbuf.h
  280. symlinks.c
  281. t/
  282. tag.c
  283. tag.h
  284. tar.h
  285. templates/
  286. test-absolute-path.c
  287. test-chmtime.c
  288. test-date.c
  289. test-delta.c
  290. test-genrandom.c
  291. test-match-trees.c
  292. test-parse-options.c
  293. test-sha1.c
  294. test-sha1.sh
  295. thread-utils.c
  296. thread-utils.h
  297. trace.c
  298. transport.c
  299. transport.h
  300. tree-diff.c
  301. tree-walk.c
  302. tree-walk.h
  303. tree.c
  304. tree.h
  305. unpack-file.c
  306. unpack-trees.c
  307. unpack-trees.h
  308. update-server-info.c
  309. upload-pack.c
  310. usage.c
  311. utf8.c
  312. utf8.h
  313. var.c
  314. walker.c
  315. walker.h
  316. write_or_die.c
  317. ws.c
  318. wt-status.c
  319. wt-status.h
  320. xdiff-interface.c
  321. xdiff-interface.h
  322. xdiff/