all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Andre Spiegel <spiegel@gnu.org>
Subject: Rewrite of vc-user-login-name
Date: Sun, 22 Jan 2006 17:19:48 +0100	[thread overview]
Message-ID: <1137946789.5032.149.camel@localhost> (raw)

Here's a patch that closes a long standing issue, removing the need for
Tramp to advise vc-user-login-name.  I'm not quite sure how to install
it, though: should I just remove the advice in tramp-vc.el?  Is that
guaranteed not to break anything if people simply update from CVS?
(Since the argument list changed, the tramp advice no longer works with
this patch.)

Apart from that, if anybody sees any issues with the new code, feel free
to suggest improvements.  If I don't hear anything, I'll install it and
simply remove the Tramp advice tomorrow.  (I have already installed a
related patch that makes `vc-user-login-name UID' unnecessary, hence the
change in the argument list.)

--- vc-hooks.el	20 Aug 2005 09:13:19 +0200	1.176
+++ vc-hooks.el	22 Jan 2006 13:51:14 +0100	
@@ -410,14 +410,22 @@
           (vc-file-setprop file 'vc-checkout-model
                            (vc-call checkout-model file)))))
 
-(defun vc-user-login-name (&optional uid)
-  "Return the name under which the user is logged in, as a string.
-\(With optional argument UID, return the name of that user.)
-This function does the same as function `user-login-name', but unlike
-that, it never returns nil.  If a UID cannot be resolved, that
-UID is returned as a string."
-  (or (user-login-name uid)
-      (number-to-string (or uid (user-uid)))))
+(defun vc-user-login-name (file)
+  "Return the name under which the user accesses the given FILE."
+  (or (and (eq (string-match tramp-file-name-regexp file) 0)
+           ;; tramp case: execute "whoami" via tramp
+           (let ((default-directory (file-name-directory file)))
+             (with-temp-buffer
+               (if (not (zerop (process-file "whoami" nil t)))
+                   ;; fall through if "whoami" didn't work
+                   nil
+                 ;; remove trailing newline
+                 (delete-region (1- (point-max)) (point-max))
+                 (buffer-string)))))
+      ;; normal case
+      (user-login-name)
+      ;; if user-login-name is nil, return the UID as a string
+      (number-to-string (user-uid))))
 
 (defun vc-state (file)
   "Return the version control state of FILE.

             reply	other threads:[~2006-01-22 16:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-01-22 16:19 Andre Spiegel [this message]
2006-01-22 22:22 ` Rewrite of vc-user-login-name Michael Albinus
2006-01-24 16:47 ` Richard M. Stallman
2006-01-25 18:42   ` Andre Spiegel
2006-01-27 19:52     ` Michael Albinus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1137946789.5032.149.camel@localhost \
    --to=spiegel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.