for-each-ref: `:short` format for `refname`

Tries to shorten the refname to a non-ambiguous name.

Szeder Gábor noticed that the git bash completion takes a
tremendous amount of time to strip leading components from
heads and tags refs (i.e. refs/heads, refs/tags, ...). He
proposed a new atom called 'refbasename' which removes at
most two leading components from the ref name.

I myself, proposed a more dynamic solution, which strips off
common leading components with the matched pattern.

But the current bash solution and both proposals suffer from
one mayor problem: ambiguous refs.

A ref is ambiguous, if it resolves to more than one full refs.
I.e. given the refs refs/heads/xyzzy and refs/tags/xyzzy. The
(short) ref xyzzy can point to both refs.

( Note: Its irrelevant whether the referenced objects are the
  same or not. )

This proposal solves this by checking for ambiguity of the
shorten ref name.

The shortening is done with the same rules for resolving refs
but in the reverse order. The short name is checked if it
resolves to a different ref.

To continue the above example, the output would be like this:

heads/xyzzy
xyzzy

So, if you want just tags, xyzzy is not ambiguous, because it
will resolve to a tag. If you need the heads you get a also
a non-ambiguous short form of the ref.

To integrate this new format into the bash completion to get
only non-ambiguous refs is beyond the scope of this patch.

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