Subject: Re: bug#4206: 23.1; vc-dir bug with git

From: Dan Nicolaescu <[email-masked]>
Date: Sun, 23 Aug 2009 04:57:14 -0700 (PDT)

Tom Tromey <[email-masked]> writes:

  > >>>>> "Dan" == Dan Nicolaescu <[email-masked]> writes:
  > 
  > Dan> What's the right thing to do here?  
  > Dan> vc-git-register does not support (yet?) passing directories as an
  > Dan> argument. 
  > 
  > I think the best situation would be for vc-dir to understand
  > unregistered directories (and not display them twice), and for
  > vc-git-register to be able to run "git add" on a directory.  

The patch below helps.
But the *vc-dir* buffer does not get updated correctly.
Maybe vc-git-dir-status-files does not work quite right, but it's hard
to tell without being a low level git expert.

  > "git add DIR" usually does the right thing and in any case if it "overshoots" it
  > can be corrected.

It seems that vc-git-revert does not revert files in the 'added state to
'unregistered state.  It does not seem that all VC backends behave
consistently in this situation :-(

--- vc-dir.el.~1.40.~	2009-08-20 23:40:25.000000000 -0700
+++ vc-dir.el	2009-08-23 04:02:01.000000000 -0700
@@ -326,8 +326,9 @@ If BODY uses EVENT, it should be a varia
     (or (vc-dir-fileinfo->directory data)
 	;; Otherwise compute it from the file name.
 	(file-name-directory
-	 (expand-file-name
-	  (vc-dir-fileinfo->name data))))))
+	 (directory-file-name
+	  (expand-file-name
+	   (vc-dir-fileinfo->name data)))))))
 
 (defun vc-dir-update (entries buffer &optional noinsert)
   "Update BUFFER's ewoc from the list of ENTRIES.
@@ -343,8 +344,10 @@ If NOINSERT, ignore elements on ENTRIES 
 	  ;; names too many times
 	  (sort entries
 		(lambda (entry1 entry2)
-		  (let ((dir1 (file-name-directory (expand-file-name (car entry1))))
-			(dir2 (file-name-directory (expand-file-name (car entry2)))))
+		  (let ((dir1 (file-name-directory
+			        (directory-file-name (expand-file-name (car entry1)))))
+			(dir2 (file-name-directory
+			       (directory-file-name (expand-file-name (car entry2))))))
 		    (cond
 		     ((string< dir1 dir2) t)
 		     ((not (string= dir1 dir2)) nil)
@@ -362,7 +365,8 @@ If NOINSERT, ignore elements on ENTRIES 
 
       (while (and entry node)
 	(let* ((entryfile (car entry))
-	       (entrydir (file-name-directory (expand-file-name entryfile)))
+	       (entrydir (file-name-directory (directory-file-name
+					       (expand-file-name entryfile))))
 	       (nodedir (vc-dir-node-directory node)))
 	  (cond
 	   ;; First try to find the directory.
@@ -406,7 +410,8 @@ If NOINSERT, ignore elements on ENTRIES 
       (unless (or node noinsert)
 	(let ((lastdir (vc-dir-node-directory (ewoc-nth vc-ewoc -1))))
 	  (dolist (entry entries)
-	    (let ((entrydir (file-name-directory (expand-file-name (car entry)))))
+	    (let ((entrydir (file-name-directory
+			     (directory-file-name (expand-file-name (car entry))))))
 	      ;; Insert a directory node if needed.
 	      (unless (string-equal lastdir entrydir)
 		(setq lastdir entrydir)
Index: vc-git.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/vc-git.el,v
retrieving revision 1.86
diff -u -3 -p -u -p -r1.86 vc-git.el
--- vc-git.el	21 Aug 2009 03:37:37 -0000	1.86
+++ vc-git.el	23 Aug 2009 11:06:39 -0000
@@ -425,7 +425,15 @@ If nil, use the value of `vc-diff-switch
 
 (defun vc-git-register (files &optional rev comment)
   "Register FILE into the git version-control system."
-  (vc-git-command nil 0 files "update-index" "--add" "--"))
+  (let (flist dlist)
+    (dolist (crt files)
+      (if (file-directory-p crt)
+	  (push crt dlist)
+	(push crt flist)))
+    (when flist
+      (vc-git-command nil 0 flist "update-index" "--add" "--"))
+    (when dlist
+      (vc-git-command nil 0 dlist "add"))))
 
 (defalias 'vc-git-responsible-p 'vc-git-root)