unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Using different default-directory and relative paths in VC, Was: Re: bug#21383
       [not found]                                     ` <jwvzj0zmbkw.fsf-monnier+emacsbugs@gnu.org>
@ 2015-09-07 20:55                                       ` Dmitry Gutov
  2015-09-07 22:33                                         ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: Dmitry Gutov @ 2015-09-07 20:55 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

On 09/07/2015 01:29 AM, Stefan Monnier wrote:

>> Does vc-status get a relative file name as input?
>
> Currently, I don't think so.  But that could be changed if needed.

Hopefully not.

>> b) how are you going to enforce it?.
>
> By checking all callers?

That's an odd thing to do for an API. What if diff-hl calls vc-state 
with an absolute path? Will it get a slap on the wrist?

>> (*) If we try to eliminate this duplication of info, we introduce
>> duplication of effort inside VC. Seems to be pointless complexity.
>
> Clearly it's easy to get back the absolute file name with just
> (expand-file-name <FILE>), and I don't see where we'd obviously get
> duplication of efforts.  So I'm not sure why you think it'd add complexity.

I was thinking that due to assuming that default-directory will have to 
be bound to the root. But indeed, simply using the parent directory of 
the file in question should work well enough. Although when a command is 
passed a list of files, determining their common parent will require 
more effort.

> What I do see as a problem is that it would require a careful
> study&adjustment of the whole VC code.  I'm not sure if the result would
> be more complex or simpler, admittedly.  I think it'd be about the same,
> just with cleaner semantics.

Something like the below might work, but it'll need to be done in every 
command, and some of them take a list of files; other ones take a 
directory and a set of files too.

And we'll have to be on the lookout for commands that output relative 
paths when passed relative paths as input (like 'find' does).

Note that if FILE is a relative name, (file-name-directory file) returns 
an unsuitable value.

diff --git a/lisp/vc/vc-hooks.el b/lisp/vc/vc-hooks.el
index 3e6d2a9..e273c6d 100644
--- a/lisp/vc/vc-hooks.el
+++ b/lisp/vc/vc-hooks.el
@@ -475,10 +475,12 @@ status of this file.  Otherwise, the value 
returned is one of:
    ;; FIXME: New (sub)states needed (?):
    ;; - `copied' and `moved' (might be handled by `removed' and `added')
    (or (vc-file-getprop file 'vc-state)
-      (when (> (length file) 0)         ;Why??  --Stef
-	(setq backend (or backend (vc-responsible-backend file)))
-	(when backend
-          (vc-state-refresh file backend)))))
+      (let ((default-directory (file-name-directory file))
+            (file (file-relative-name file)))
+        (when (> (length file) 0)         ;Why??  --Stef
+          (setq backend (or backend (vc-responsible-backend file)))
+          (when backend
+            (vc-state-refresh file backend))))))

  (defun vc-state-refresh (file backend)
    "Quickly recompute the `state' of FILE."




^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: Using different default-directory and relative paths in VC, Was: Re: bug#21383
  2015-09-07 20:55                                       ` Using different default-directory and relative paths in VC, Was: Re: bug#21383 Dmitry Gutov
@ 2015-09-07 22:33                                         ` Stefan Monnier
  2015-09-07 23:29                                           ` Dmitry Gutov
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2015-09-07 22:33 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: emacs-devel

>>> Does vc-status get a relative file name as input?
>> Currently, I don't think so.  But that could be changed if needed.
> Hopefully not.
>>> b) how are you going to enforce it?.
>> By checking all callers?
> That's an odd thing to do for an API. What if diff-hl calls vc-state with an
> absolute path? Will it get a slap on the wrist?

Sorry, I didn't realize you were talking about vc-state.  No I guess
vc-state would have to keep working with absolute file names (tho it
could be extended to also accept relative file names).

> in question should work well enough. Although when a command is
> passed a list of files, determining their common parent will require
> more effort.

I'd expect that the caller should be able to easily arrange for each
file in the list to *already* be relative to default-directory, so
there's no need to look for the common parent.


        Stefan



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Using different default-directory and relative paths in VC, Was: Re: bug#21383
  2015-09-07 22:33                                         ` Stefan Monnier
@ 2015-09-07 23:29                                           ` Dmitry Gutov
  2015-09-07 23:34                                             ` Dmitry Gutov
  2015-09-08  1:31                                             ` Stefan Monnier
  0 siblings, 2 replies; 5+ messages in thread
From: Dmitry Gutov @ 2015-09-07 23:29 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

On 09/08/2015 01:33 AM, Stefan Monnier wrote:

> Sorry, I didn't realize you were talking about vc-state.  No I guess
> vc-state would have to keep working with absolute file names (tho it
> could be extended to also accept relative file names).

It was just an example. Would vc-state keep working with absolute file 
names, but vc-working-revision start only accepting relative ones?

> I'd expect that the caller should be able to easily arrange for each
> file in the list to *already* be relative to default-directory, so
> there's no need to look for the common parent.

If the relative file names start with "../", the result is pointless: we 
still risk calling Git from outside of the repository checkout.

If only some of them start with "../", the result may be subtly 
different, depending on the presence of submodules, I guess, 
sub-repositories combined with ignore files.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Using different default-directory and relative paths in VC, Was: Re: bug#21383
  2015-09-07 23:29                                           ` Dmitry Gutov
@ 2015-09-07 23:34                                             ` Dmitry Gutov
  2015-09-08  1:31                                             ` Stefan Monnier
  1 sibling, 0 replies; 5+ messages in thread
From: Dmitry Gutov @ 2015-09-07 23:34 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

On 09/08/2015 02:29 AM, Dmitry Gutov wrote:

> If only some of them start with "../", the result may be subtly
> different, depending on the presence of submodules, I guess,
                                                     ^
                                                     and
> sub-repositories combined with ignore files.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Using different default-directory and relative paths in VC, Was: Re: bug#21383
  2015-09-07 23:29                                           ` Dmitry Gutov
  2015-09-07 23:34                                             ` Dmitry Gutov
@ 2015-09-08  1:31                                             ` Stefan Monnier
  1 sibling, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2015-09-08  1:31 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: emacs-devel

>> Sorry, I didn't realize you were talking about vc-state.  No I guess
>> vc-state would have to keep working with absolute file names (tho it
>> could be extended to also accept relative file names).
> It was just an example.  Would vc-state keep working with absolute file
> names, but vc-working-revision start only accepting relative ones?

I guess all those functions which are part of the API exposed by VC to
external packages would need to preserve support for absolute file
names, yes.

>> I'd expect that the caller should be able to easily arrange for each
>> file in the list to *already* be relative to default-directory, so
>> there's no need to look for the common parent.
> If the relative file names start with "../", the result is pointless:

I explicitly ruled them out in my earlier definition of "relative file names".


        Stefan



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-09-08  1:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CAAW2-ZfFt-D9VX_xU1Sp2tCL_59LreL3wCen0-Snia7H8mmrpA@mail.gmail.com>
     [not found] ` <jwvpp24t6cq.fsf-monnier+emacsbugs@gnu.org>
     [not found]   ` <55E41499.5030501@yandex.ru>
     [not found]     ` <jwvio7ve4o4.fsf-monnier+emacsbugs@gnu.org>
     [not found]       ` <55E5094A.3010108@yandex.ru>
     [not found]         ` <jwvmvx6sso7.fsf-monnier+emacsbugs@gnu.org>
     [not found]           ` <55E59487.1050804@yandex.ru>
     [not found]             ` <jwvtwreqh6n.fsf-monnier+emacsbugs@gnu.org>
     [not found]               ` <55E5CA42.1080005@yandex.ru>
     [not found]                 ` <jwv1teiqdz2.fsf-monnier+emacsbugs@gnu.org>
     [not found]                   ` <55E5DF1A.9010902@yandex.ru>
     [not found]                     ` <jwv4mjdqyad.fsf-monnier+emacsbugs@gnu.org>
     [not found]                       ` <55E6D426.10105@yandex.ru>
     [not found]                         ` <jwvegifmr7x.fsf-monnier+emacsbugs@gnu.org>
     [not found]                           ` <55E89E83.6000501@yandex.ru>
     [not found]                             ` <jwvmvx3j5ir.fsf-monnier+emacsbugs@gnu.org>
     [not found]                               ` <55EA5CB0.9070007@yandex.ru>
     [not found]                                 ` <jwvlhckhpnc.fsf-monnier+emacsbugs@gnu.org>
     [not found]                                   ` <55EB50D7.2030103@yandex.ru>
     [not found]                                     ` <jwvzj0zmbkw.fsf-monnier+emacsbugs@gnu.org>
2015-09-07 20:55                                       ` Using different default-directory and relative paths in VC, Was: Re: bug#21383 Dmitry Gutov
2015-09-07 22:33                                         ` Stefan Monnier
2015-09-07 23:29                                           ` Dmitry Gutov
2015-09-07 23:34                                             ` Dmitry Gutov
2015-09-08  1:31                                             ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).