From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.devel Subject: How to get a list of changed files with VC? Date: Thu, 13 Jul 2017 03:23:40 +0200 Message-ID: <87lgntdt9f.fsf@drachen> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1499909072 8275 195.159.176.226 (13 Jul 2017 01:24:32 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Thu, 13 Jul 2017 01:24:32 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) To: Emacs Development Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jul 13 03:24:28 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dVSrf-0001ic-Q2 for ged-emacs-devel@m.gmane.org; Thu, 13 Jul 2017 03:24:23 +0200 Original-Received: from localhost ([::1]:56747 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVSrl-0002bs-6F for ged-emacs-devel@m.gmane.org; Wed, 12 Jul 2017 21:24:29 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45772) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVSr7-0002bm-Ow for emacs-devel@gnu.org; Wed, 12 Jul 2017 21:23:50 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVSr3-0003gI-Px for emacs-devel@gnu.org; Wed, 12 Jul 2017 21:23:49 -0400 Original-Received: from mout.web.de ([212.227.15.3]:54093) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dVSr3-0003fW-FA for emacs-devel@gnu.org; Wed, 12 Jul 2017 21:23:45 -0400 Original-Received: from drachen.dragon ([88.73.234.235]) by smtp.web.de (mrweb003 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MLxrY-1daycl0IJw-007olC; Thu, 13 Jul 2017 03:23:43 +0200 X-Provags-ID: V03:K0:KNd6zeU0xbFSXb8TTLb3IVZcXrnTrhmaiG2P/AMStoSDyYRfTRR E5GKvMINGu+0ItELoJdHxKimO/EamZH3pkYws3Jr5qFPjFsLFwVA29l89aR5lqiH84VIEzA i56zSXqgNu9lWQYZGiI3xXRuRm+uoJg5V5VrKQ0AP2TRv97J7rjcoozBnWrN+V/JIg1qifI lt9Uoga7RMZ0Y+76b2CGg== X-UI-Out-Filterresults: notjunk:1;V01:K0:liUyCFXTIvk=:jO53etMCZ+QUvLM/j2JXyG 9uwdTrHpfUjx66Hcjvt5tvkyOceQdZYLTU6pPy9tLWnyIntfMa49Ttps3fju9dDYGh5uPXBGm esnztvzrZsxSUP7GD0FPedXQot1CUfuP8I9ShqncU92Risc35DkFcvW7fYOjVTxtqnsliZd1X z+4RMltpkvmvzRMReCKHexbjP26CWQ4RgBqBB6qnWX4ov8Qf03YV643gs16FrqVtLyO5c5Q4E uj2orGWYmphDFfAUBmxaPhPqnNFWwRwQZzjwIOfYXSh7vZEESwh3FDhPZvLfS7cw6lg+R2GMD cSwlxB4erW4P2tjetNX9WZ1r26Cse2LaqWY0ax0EX0ZcHx0LQN8RQ0DPyZf1a6sAPe02CRQrr leMPc5DSqN1CofRwqPaJ/dF4923CI1VbhSg0qfhBbv8pHm/b7uKS8mUlR8Q3VFX9ZWuXQeJgb 1/XDL9bS+0K803pi5HQ0rOUBhYLBWW6re66lBD+IO5HHVxJWyJHPU8l8eP6xvo5R+dx6BwIdR 8yVENgpPAyrKEyTVt+Zc86cMQL+DByR8bnSzsT5IDe6cRemGQdu4l/y7OskK1wfgoSW6W7xYz dukNPfFLKXIYvnmNwYWmjAsgMY5v8KhFavxmus2MypMWrdFaNXd+SipKv++EOIESr0ZzAZqNW NJBMeB4ry84fgAQfv2EXV9zKzk4wes1592TfroG4Dz0Yijoy0/stFU4mKJ2CCOlATc/CkTm2c mBIKrsqbSVykP7HdeloOFiY+B1Vl7cXEmVGO1YgsM14/E8jVi2Zp6Lheqj6JkZSrbhsDz9jz X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.15.3 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:216565 Archived-At: Hello, For el-search' `change' pattern, I need the following functions: #+begin_src emacs-lisp (defun el-search--changed-files-in-repo (repo-root-dir &optional commit) "Return a list of files that changed relative to COMMIT. COMMIT defaults to HEAD." (cl-callf or commit "HEAD") (let ((default-directory repo-root-dir)) (mapcar #'expand-file-name (split-string (shell-command-to-string (format "git diff -z --name-only %s --" (shell-quote-argument commit))) "\0" t)))) (defun el-search--file-changed-p (file revision) "Return non-nil when FILE has changed relative to REVISION." (cl-callf file-truename file) (when-let ((backend (vc-backend file))) (ignore-errors (let ((default-directory (file-name-directory file)) (vc-git-diff-switches nil)) (and (with-temp-buffer (= 1 (vc-call-backend backend 'diff (list file) nil revision (current-buffer)))) (with-temp-buffer (= 1 (vc-call-backend backend 'diff (list file) revision nil (current-buffer))))))))) #+end_src I didn't find something like this existing in VC (or did I miss it?). More specific questions about my implementation: 1. The implementation of the first function `el-search--changed-files-in-repo' is currently git-specific, but I didn't find a way to implement it with functions that VC defines to make it work for other version control systems. Any idea? 2. The second function `el-search--file-changed-p' doesn't have this problem. However, I gained it from trial and error. Does the implementation make sense? How can I avoid binding vc-git-diff-switches -> nil (I get an error for some files if I don't). And I also need to wrap the thing inside `ignore-errors' to avoid a more complicate `condition-case' where I don't fully understand which errors I need to catch. Any help for a better implementation is greatly appreciated. TIA, Michael.