add generic terminal prompt function

When we need to prompt the user for input interactively, we
want to access their terminal directly. We can't rely on
stdio because it may be connected to pipes or files, rather
than the terminal. Instead, we use "getpass()", because it
abstracts the idea of prompting and reading from the
terminal.  However, it has some problems:

  1. It never echoes the typed characters, which makes it OK
     for passwords but annoying for other input (like usernames).

  2. Some implementations of getpass() have an extremely
     small input buffer (e.g., Solaris 8 is reported to
     support only 8 characters).

  3. Some implementations of getpass() will fall back to
     reading from stdin (e.g., glibc). We explicitly don't
     want this, because our stdin may be connected to a pipe
     speaking a particular protocol, and reading will
     disrupt the protocol flow (e.g., the remote-curl
     helper).

  4. Some implementations of getpass() turn off signals, so
     that hitting "^C" on the terminal does not break out of
     the password prompt. This can be a mild annoyance.

Instead, let's provide an abstract "git_terminal_prompt"
function that addresses these concerns. This patch includes
an implementation based on /dev/tty, enabled by setting
HAVE_DEV_TTY. The fallback is to use getpass() as before.

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