From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.devel Subject: Re: A project-files implementation for Git projects Date: Mon, 30 Sep 2019 03:09:19 +0300 Message-ID: <4be972f9-45a3-f2aa-f532-d7b8fbe054fd@yandex.ru> References: <8736h9rdc4.fsf@gnu.org> <87mufcfz1u.fsf@gnu.org> <87tv9kz2x6.fsf@gnu.org> <87a7bbjdwe.fsf@gnu.org> <87a7ba8uvx.fsf@gnu.org> <87pnk2zvvy.fsf@gnu.org> <87sgows6wy.fsf@gnu.org> <87ef0dy18z.fsf@gnu.org> <87impk675h.fsf@gnu.org> <874l13h30l.fsf@gnu.org> <7386ef98-c151-e1ce-23fa-11470a16f0d3@yandex.ru> <87h84x1zoa.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------05A1E9410EAE4A96347D7EDD" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="104328"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Sep 30 02:09:35 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iEjFu-000R0e-Rl for ged-emacs-devel@m.gmane.org; Mon, 30 Sep 2019 02:09:34 +0200 Original-Received: from localhost ([::1]:42820 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iEjFt-0000EE-Nw for ged-emacs-devel@m.gmane.org; Sun, 29 Sep 2019 20:09:33 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50288) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iEjFm-0000E2-1J for emacs-devel@gnu.org; Sun, 29 Sep 2019 20:09:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iEjFk-0007XZ-Bs for emacs-devel@gnu.org; Sun, 29 Sep 2019 20:09:25 -0400 Original-Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]:38674) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iEjFk-0007X9-3J for emacs-devel@gnu.org; Sun, 29 Sep 2019 20:09:24 -0400 Original-Received: by mail-wr1-x42d.google.com with SMTP id w12so9144678wro.5 for ; Sun, 29 Sep 2019 17:09:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:subject:to:references:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=Z7swk3clkpbWTgPg/yCu06mvYBUkzK/rhPYvECd/X/0=; b=LHlTGKU92MT6e2XzDUE6BILOMpoaW8Q+Q6wsH+9agW47JDZYaKtJxjD0oxMNIWUI87 /FslZngJu8V70XYk4CP7hOUY9ZuWdWH/BHjIS/x9wTccdp8TgsQV7o6rG5vNNHw4kmik zh1eTCxgi5aJKAJh/cdSGOhKskZTsCZsaVuxwzHbXPJIPmhdwyXMUM1Ia49hSTLNDDkn 0LsWWxSN25C2kr125Oyh+71wMsCkB+VQ7QWb9jXyXd7ry9CP4drdcif5RGxLTvCqiMhs LTC1CNthj9u2/upKYO34qSy47vA2OM/L7CUi2daY1rOgZcTJPW4WI+l9UxWY0sR92xNc UrnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:subject:to:references:message-id :date:user-agent:mime-version:in-reply-to:content-language; bh=Z7swk3clkpbWTgPg/yCu06mvYBUkzK/rhPYvECd/X/0=; b=a0qC3qtJJK7TbaXY7+j2RwLX/nmpmu8VoHNvYBPftmjOwnDwr9KR8yC9T3iSkjxw4A eIwIZu34f44D3lADKeEKdEBscLHPr+an3HNUU/tHtgtFNO9uHdhhCF4fUnEeS30IFiPq vvTKj+AcjiqTwGhTsMje6k9PSqmCdPs5fqiZtFesyiqvdj6T3LxVq++oQ3ng0aTA+oSb 0HmseNrex/ZWYIAbdcC94GSe9TYNjFZhEb4NzSuK8YcKf6GAWRRCz9xn6NleRfUVr9Nh Km77xLSrHLdt8EIxAIJePkGONkmvZ6cXyuAZu18xmWwZcbC0u87cTMKpKmxdk4X89K6L tCTw== X-Gm-Message-State: APjAAAX0noBCA3A0wDpDIS3kWETC8HgYj6lEx3bcpvKTIujgGg4DxgWo cu05GyNbHrCwMMlovAj3LBVBmY9J2x8= X-Google-Smtp-Source: APXvYqxpT1HwhF/gvVnLNE9TJowW2Uy7kyqB+UAvKsfoxwsQoTm+Ydmr1ojSSQ6sFztUJJE+OixJwA== X-Received: by 2002:a5d:4745:: with SMTP id o5mr11088320wrs.125.1569802162365; Sun, 29 Sep 2019 17:09:22 -0700 (PDT) Original-Received: from [192.168.88.225] (87-188-86.internetbus.cytanet.com.cy. [87.228.188.86]) by smtp.googlemail.com with ESMTPSA id a13sm30061179wrf.73.2019.09.29.17.09.20 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Sep 2019 17:09:21 -0700 (PDT) In-Reply-To: <87h84x1zoa.fsf@gnu.org> Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42d X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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:240400 Archived-At: This is a multi-part message in MIME format. --------------05A1E9410EAE4A96347D7EDD Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hi Tassilo, On 27.09.2019 19:17, Tassilo Horn wrote: > I have to admit that I've lost track over what we're actually trying to > do exactly. My main motivation was just to get a faster project-files > implementation for the Git repo I have at work. I've now fixed that on > my end using a simple caching approach which is good enough for me ATM. I'm attaching a working patch that will probably need tweaks later. I'm not sure how to handle attribution best. If you like it, you can simply commit it under your name (up to now, I've mostly done the rearranging and some minor tweaks). > So I think that your current idea is to: > > - No general VC list-files operation since we can come up with good > versions just for Git and Hg anyway. Fine with me. Great. I think we should start with that that either way. And when some other application arises that could use a VC 'ls-files' command we should see whether we can extract something that satisfies both. Maybe the minimum supported Git version will make it easier for us too then. > - I'm not sure if we're on the same board when it comes to ignores. > > If you want me to implement something I fear you have to explain the > ignore story again. I don't know what you imply by renaming the > parameter from EXTRA-IGNORES to ALL-IGNORES. Do you mean that the > patterns in .{git,hg}ignore (and $XDG_CONFIG_HOME/git/ignore, > $GIT_DIR/info/exclude) should be part of the ALL-IGNORES list (in > addition to project-vc-ignores) and parsed from those files? Good point, I forgot about those (and also about per-directory gitignore files). ALL-IGNORES would be a nice semantics for a VC 'ls-files' command, but if we're not doing that now, we don't have to try to fit that approach. Still, there could be a performance problem with outputting all ignored files and then parsing out only a part of them. Could you try the new feature with a test repository from https://debbugs.gnu.org/cgi/bugreport.cgi?bug=22481? > Processing > 3 files in the case of Git and handling 3 ignore syntaxes (regexp, glob, > rootglob) in the case of Hg doesn't sound too appealing to me. Speaking of syntaxes, I was curious which one is used by Mercurial's --exclude. But it seems to accept globs okay, including ones rooted with './'. --------------05A1E9410EAE4A96347D7EDD Content-Type: text/x-patch; name="vc-list-files.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="vc-list-files.diff" diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 4693d07fa8..bbb6310323 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -277,6 +277,66 @@ project-try-vc (funcall project-vc-external-roots-function))) (project-roots project))) +(cl-defmethod project-files ((project (head vc)) &optional dirs) + (cl-mapcan + (lambda (dir) + (let (backend) + (if (and (file-equal-p dir (cdr project)) + (setq backend (vc-responsible-backend dir)) + (cond + ((eq backend 'Hg)) + ((and (eq backend 'Git) + (or + (not project-vc-ignores) + (version<= "1.9" (vc-git--program-version))))))) + (project-vc-list-files dir backend project-vc-ignores) + (project--files-in-directory + dir + (project--dir-ignores project dir))))) + (or dirs (project-roots project)))) + +(defun project-vc-list-files (dir backend extra-ignores) + (pcase backend + (`Git + (let ((default-directory dir) + (args '("-z"))) + (when t ;include-unregistered + (setq args (append args '("-c" "-o" "--exclude-standard")))) + (when extra-ignores + (setq args (append args + (cons "--" + (mapcar + (lambda (i) + (if (string-match "\\./" i) + (format ":!/:%s" (substring i 2)) + (format ":!:%s" i))) + extra-ignores))))) + (mapcar + #'expand-file-name + (split-string + (apply #'vc-git--run-command-string nil "ls-files" args) + "\0" t)))) + (`Hg + (let ((default-directory dir) + args + files) + (when t ;include-unregistered + (setq args (nconc args '("--all")))) + (when extra-ignores + (setq args (nconc args + (mapcan + (lambda (i) + (list "--exclude" i)) + (copy-list extra-ignores))))) + (with-temp-buffer + (apply #'vc-hg-command t 0 "." + "status" args) + (goto-char (point-min)) + (while (re-search-forward "^[?C]\s+\\(.*\\)$" nil t) + (setq files (cons (expand-file-name (match-string 1)) + files)))) + (nreverse files))))) + (cl-defmethod project-ignores ((project (head vc)) dir) (let* ((root (cdr project)) backend) --------------05A1E9410EAE4A96347D7EDD--