branch: fix shortening of non-remote symrefs

Commit aedcb7d (branch.c: use 'ref-filter' APIs, 2015-09-23)
adjusted the symref-printing code to look like this:

    if (item->symref) {
	    skip_prefix(item->symref, "refs/remotes/", &desc);
	    strbuf_addf(&out, " -> %s", desc);
    }

This has three bugs in it:

  1. It always skips past "refs/remotes/", instead of
     skipping past the prefix associated with the branch we
     are showing (so commonly we see "refs/remotes/" for the
     refs/remotes/origin/HEAD symref, but the previous code
     would skip "refs/heads/" when showing a symref it found
     in refs/heads/.

  2. If skip_prefix() does not match, it leaves "desc"
     untouched, and we show whatever happened to be in it
     (which is the refname from a call to skip_prefix()
     earlier in the function).

  3. If we do match with skip_prefix(), we stomp on the
     "desc" variable, which is later passed to
     add_verbose_info(). We probably want to retain the
     original refname there (though it likely doesn't matter
     in practice, since after all, one points to the other).

The fix to match the original code is fairly easy: record
the prefix to strip based on item->kind, and use it here.
However, since we already have a local variable named "prefix",
let's give the two prefixes verbose names so we don't
confuse them.

Signed-off-by: Jeff King <peff@peff.net>
Acked-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2 files changed
tree: bd1e2a04da9bacb9c4cc630ffb54a326f577397f
  1. block-sha1/
  2. builtin/
  3. compat/
  4. contrib/
  5. Documentation/
  6. ewah/
  7. git-gui/
  8. gitk-git/
  9. gitweb/
  10. mergetools/
  11. perl/
  12. po/
  13. ppc/
  14. refs/
  15. t/
  16. templates/
  17. vcs-svn/
  18. xdiff/
  19. .gitattributes
  20. .gitignore
  21. .mailmap
  22. .travis.yml
  23. abspath.c
  24. aclocal.m4
  25. advice.c
  26. advice.h
  27. alias.c
  28. alloc.c
  29. archive-tar.c
  30. archive-zip.c
  31. archive.c
  32. archive.h
  33. argv-array.c
  34. argv-array.h
  35. attr.c
  36. attr.h
  37. base85.c
  38. bisect.c
  39. bisect.h
  40. blob.c
  41. blob.h
  42. branch.c
  43. branch.h
  44. builtin.h
  45. bulk-checkin.c
  46. bulk-checkin.h
  47. bundle.c
  48. bundle.h
  49. cache-tree.c
  50. cache-tree.h
  51. cache.h
  52. check-builtins.sh
  53. check-racy.c
  54. check_bindir
  55. color.c
  56. color.h
  57. column.c
  58. column.h
  59. combine-diff.c
  60. command-list.txt
  61. commit-slab.h
  62. commit.c
  63. commit.h
  64. config.c
  65. config.mak.in
  66. config.mak.uname
  67. configure.ac
  68. connect.c
  69. connect.h
  70. connected.c
  71. connected.h
  72. convert.c
  73. convert.h
  74. copy.c
  75. COPYING
  76. credential-cache--daemon.c
  77. credential-cache.c
  78. credential-store.c
  79. credential.c
  80. credential.h
  81. csum-file.c
  82. csum-file.h
  83. ctype.c
  84. daemon.c
  85. date.c
  86. decorate.c
  87. decorate.h
  88. delta.h
  89. diff-delta.c
  90. diff-lib.c
  91. diff-no-index.c
  92. diff.c
  93. diff.h
  94. diffcore-break.c
  95. diffcore-delta.c
  96. diffcore-order.c
  97. diffcore-pickaxe.c
  98. diffcore-rename.c
  99. diffcore.h
  100. dir.c
  101. dir.h
  102. editor.c
  103. entry.c
  104. environment.c
  105. exec_cmd.c
  106. exec_cmd.h
  107. fast-import.c
  108. fetch-pack.c
  109. fetch-pack.h
  110. fmt-merge-msg.h
  111. fsck.c
  112. fsck.h
  113. generate-cmdlist.sh
  114. gettext.c
  115. gettext.h
  116. git-add--interactive.perl
  117. git-archimport.perl
  118. git-bisect.sh
  119. git-compat-util.h
  120. git-cvsexportcommit.perl
  121. git-cvsimport.perl
  122. git-cvsserver.perl
  123. git-difftool--helper.sh
  124. git-difftool.perl
  125. git-filter-branch.sh
  126. git-instaweb.sh
  127. git-merge-octopus.sh
  128. git-merge-one-file.sh
  129. git-merge-resolve.sh
  130. git-mergetool--lib.sh
  131. git-mergetool.sh
  132. git-p4.py
  133. git-parse-remote.sh
  134. git-quiltimport.sh
  135. git-rebase--am.sh
  136. git-rebase--interactive.sh
  137. git-rebase--merge.sh
  138. git-rebase.sh
  139. git-relink.perl
  140. git-remote-testgit.sh
  141. git-request-pull.sh
  142. git-send-email.perl
  143. git-sh-i18n.sh
  144. git-sh-setup.sh
  145. git-stash.sh
  146. git-submodule.sh
  147. git-svn.perl
  148. GIT-VERSION-GEN
  149. git-web--browse.sh
  150. git.c
  151. git.rc
  152. git.spec.in
  153. gpg-interface.c
  154. gpg-interface.h
  155. graph.c
  156. graph.h
  157. grep.c
  158. grep.h
  159. hashmap.c
  160. hashmap.h
  161. help.c
  162. help.h
  163. hex.c
  164. http-backend.c
  165. http-fetch.c
  166. http-push.c
  167. http-walker.c
  168. http.c
  169. http.h
  170. ident.c
  171. imap-send.c
  172. INSTALL
  173. khash.h
  174. kwset.c
  175. kwset.h
  176. levenshtein.c
  177. levenshtein.h
  178. LGPL-2.1
  179. line-log.c
  180. line-log.h
  181. line-range.c
  182. line-range.h
  183. list-objects.c
  184. list-objects.h
  185. ll-merge.c
  186. ll-merge.h
  187. lockfile.c
  188. lockfile.h
  189. log-tree.c
  190. log-tree.h
  191. mailinfo.c
  192. mailinfo.h
  193. mailmap.c
  194. mailmap.h
  195. Makefile
  196. match-trees.c
  197. merge-blobs.c
  198. merge-blobs.h
  199. merge-recursive.c
  200. merge-recursive.h
  201. merge.c
  202. mergesort.c
  203. mergesort.h
  204. name-hash.c
  205. notes-cache.c
  206. notes-cache.h
  207. notes-merge.c
  208. notes-merge.h
  209. notes-utils.c
  210. notes-utils.h
  211. notes.c
  212. notes.h
  213. object.c
  214. object.h
  215. pack-bitmap-write.c
  216. pack-bitmap.c
  217. pack-bitmap.h
  218. pack-check.c
  219. pack-objects.c
  220. pack-objects.h
  221. pack-revindex.c
  222. pack-revindex.h
  223. pack-write.c
  224. pack.h
  225. pager.c
  226. parse-options-cb.c
  227. parse-options.c
  228. parse-options.h
  229. patch-delta.c
  230. patch-ids.c
  231. patch-ids.h
  232. path.c
  233. pathspec.c
  234. pathspec.h
  235. pkt-line.c
  236. pkt-line.h
  237. preload-index.c
  238. pretty.c
  239. prio-queue.c
  240. prio-queue.h
  241. progress.c
  242. progress.h
  243. prompt.c
  244. prompt.h
  245. quote.c
  246. quote.h
  247. reachable.c
  248. reachable.h
  249. read-cache.c
  250. README
  251. ref-filter.c
  252. ref-filter.h
  253. reflog-walk.c
  254. reflog-walk.h
  255. refs.c
  256. refs.h
  257. remote-curl.c
  258. remote-testsvn.c
  259. remote.c
  260. remote.h
  261. replace_object.c
  262. rerere.c
  263. rerere.h
  264. resolve-undo.c
  265. resolve-undo.h
  266. revision.c
  267. revision.h
  268. run-command.c
  269. run-command.h
  270. send-pack.c
  271. send-pack.h
  272. sequencer.c
  273. sequencer.h
  274. server-info.c
  275. setup.c
  276. sh-i18n--envsubst.c
  277. sha1-array.c
  278. sha1-array.h
  279. sha1-lookup.c
  280. sha1-lookup.h
  281. sha1_file.c
  282. sha1_name.c
  283. shallow.c
  284. shell.c
  285. shortlog.h
  286. show-index.c
  287. sideband.c
  288. sideband.h
  289. sigchain.c
  290. sigchain.h
  291. split-index.c
  292. split-index.h
  293. strbuf.c
  294. strbuf.h
  295. streaming.c
  296. streaming.h
  297. string-list.c
  298. string-list.h
  299. submodule-config.c
  300. submodule-config.h
  301. submodule.c
  302. submodule.h
  303. symlinks.c
  304. tag.c
  305. tag.h
  306. tar.h
  307. tempfile.c
  308. tempfile.h
  309. test-chmtime.c
  310. test-config.c
  311. test-ctype.c
  312. test-date.c
  313. test-delta.c
  314. test-dump-cache-tree.c
  315. test-dump-split-index.c
  316. test-dump-untracked-cache.c
  317. test-genrandom.c
  318. test-hashmap.c
  319. test-index-version.c
  320. test-line-buffer.c
  321. test-match-trees.c
  322. test-mergesort.c
  323. test-mktemp.c
  324. test-parse-options.c
  325. test-path-utils.c
  326. test-prio-queue.c
  327. test-read-cache.c
  328. test-regex.c
  329. test-revision-walking.c
  330. test-run-command.c
  331. test-scrap-cache-tree.c
  332. test-sha1-array.c
  333. test-sha1.c
  334. test-sha1.sh
  335. test-sigchain.c
  336. test-string-list.c
  337. test-submodule-config.c
  338. test-subprocess.c
  339. test-svn-fe.c
  340. test-urlmatch-normalization.c
  341. test-wildmatch.c
  342. thread-utils.c
  343. thread-utils.h
  344. trace.c
  345. trace.h
  346. trailer.c
  347. trailer.h
  348. transport-helper.c
  349. transport.c
  350. transport.h
  351. tree-diff.c
  352. tree-walk.c
  353. tree-walk.h
  354. tree.c
  355. tree.h
  356. unicode_width.h
  357. unimplemented.sh
  358. unix-socket.c
  359. unix-socket.h
  360. unpack-trees.c
  361. unpack-trees.h
  362. update_unicode.sh
  363. upload-pack.c
  364. url.c
  365. url.h
  366. urlmatch.c
  367. urlmatch.h
  368. usage.c
  369. userdiff.c
  370. userdiff.h
  371. utf8.c
  372. utf8.h
  373. varint.c
  374. varint.h
  375. version.c
  376. version.h
  377. versioncmp.c
  378. walker.c
  379. walker.h
  380. wildmatch.c
  381. wildmatch.h
  382. worktree.c
  383. worktree.h
  384. wrap-for-bin.sh
  385. wrapper.c
  386. write_or_die.c
  387. ws.c
  388. wt-status.c
  389. wt-status.h
  390. xdiff-interface.c
  391. xdiff-interface.h
  392. zlib.c