Skip to contentSkip to conversation

builtin/mv: Get rid of the last caller of get_pathspec

PATCH In review Stefan Beller 2 participants 9 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 builtin/mv: Get rid of the last caller of get_pathspec

get_pathspec is deprecated and builtin/mv is its last caller, so getting rid of get_pathspec is rather easy. By getting rid of get_pathspec, the documentation such as 'technical/api-setup.txt' becomes easier to read as the reader doesn't need to bear with the additional fact that get_pathspec is deprecated.

The code in 'builtin/mv' still requires some work to make it less ugly.

CC Johannes Schindelin <[email protected]>
CC Junio C Hamano <[email protected]>
CC Nguyễn Thái Ngọc Duy <[email protected]>
---
 Documentation/technical/api-setup.txt |  2 --
 builtin/mv.c                          | 19 ++++++++++++++++---
 cache.h                               |  1 -
 pathspec.c                            | 30 ------------------------------
 4 files changed, 16 insertions(+), 36 deletions(-)
Documentation/technical/api-setup.txt +0 -2
index 540e455..eb1fa98 100644
@@ -27,8 +27,6 @@ parse_pathspec(). This function takes several arguments:
 
 - prefix and args come from cmd_* functions
 
-get_pathspec() is obsolete and should never be used in new code.
-
 parse_pathspec() helps catch unsupported features and reject them
 politely. At a lower level, different pathspec-related functions may
 not support the same set of features. Such pathspec-sensitive
builtin/mv.c +16 -3
index d1d4316..b89d90a 100644
@@ -10,6 +10,7 @@
 #include "string-list.h"
 #include "parse-options.h"
 #include "submodule.h"
+#include "pathspec.h"
 
 static const char * const builtin_mv_usage[] = {
 	N_("git mv [<options>] <source>... <destination>"),
@@ -20,13 +21,19 @@ static const char * const builtin_mv_usage[] = {
 #define KEEP_TRAILING_SLASH 2
 
 static const char **internal_copy_pathspec(const char *prefix,
-					   const char **pathspec,
+					   const char **argv,
 					   int count, unsigned flags)
 {
 	int i;
+	struct pathspec ps;
 	const char **result = xmalloc((count + 1) * sizeof(const char *));
-	memcpy(result, pathspec, count * sizeof(const char *));
+	memcpy(result, argv, count * sizeof(const char *));
 	result[count] = NULL;
+
+	/*
+	 * NEEDSWORK: instead of preprocessing, pass the right flags to
+	 * parse_pathspec below.
+	 */
 	for (i = 0; i < count; i++) {
 		int length = strlen(result[i]);
 		int to_copy = length;
@@ -42,7 +49,13 @@ static const char **internal_copy_pathspec(const char *prefix,
 				result[i] = it;
 		}
 	}
-	return get_pathspec(prefix, result);
+
+	parse_pathspec(&ps,
+		       PATHSPEC_ALL_MAGIC &
+		       ~(PATHSPEC_FROMTOP | PATHSPEC_LITERAL),
+		       PATHSPEC_PREFER_CWD,
+		       prefix, result);
+	return ps._raw;
 }
 
 static const char *add_slash(const char *path)
cache.h +0 -1
index 4f55466..d4e22e2 100644
@@ -452,7 +452,6 @@ extern void set_git_work_tree(const char *tree);
 
 #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
 
-extern const char **get_pathspec(const char *prefix, const char **pathspec);
 extern void setup_work_tree(void);
 extern const char *setup_git_directory_gently(int *);
 extern const char *setup_git_directory(void);
pathspec.c +0 -30
index 9304ee3..b0e14e5 100644
@@ -450,36 +450,6 @@ void parse_pathspec(struct pathspec *pathspec,
 	}
 }
 
-/*
- * N.B. get_pathspec() is deprecated in favor of the "struct pathspec"
- * based interface - see pathspec.c:parse_pathspec().
- *
- * Arguments:
- *  - prefix - a path relative to the root of the working tree
- *  - pathspec - a list of paths underneath the prefix path
- *
- * Iterates over pathspec, prepending each path with prefix,
- * and return the resulting list.
- *
- * If pathspec is empty, return a singleton list containing prefix.
- *
- * If pathspec and prefix are both empty, return an empty list.
- *
- * This is typically used by built-in commands such as add.c, in order
- * to normalize argv arguments provided to the built-in into a list of
- * paths to process, all relative to the root of the working tree.
- */
-const char **get_pathspec(const char *prefix, const char **pathspec)
-{
-	struct pathspec ps;
-	parse_pathspec(&ps,
-		       PATHSPEC_ALL_MAGIC &
-		       ~(PATHSPEC_FROMTOP | PATHSPEC_LITERAL),
-		       PATHSPEC_PREFER_CWD,
-		       prefix, pathspec);
-	return ps._raw;
-}
-
 void copy_pathspec(struct pathspec *dst, const struct pathspec *src)
 {
 	*dst = *src;
Signature · 1 line
2.5.0.2.g6ffee06.dirty
#1 lore raw
Quoted 7 lines · Stefan Beller

get_pathspec is deprecated and builtin/mv is its last caller, so getting rid of get_pathspec is rather easy. By getting rid of get_pathspec, the documentation such as 'technical/api-setup.txt' becomes easier to read as the reader doesn't need to bear with the additional fact that get_pathspec is deprecated.

The code in 'builtin/mv' still requires some work to make it less ugly.

Perhaps split this into two patches? One to free git-mv of get_pathspec() dependence, and the second to actually retire get_pathspec().

Quoted 1 line
#2 lore raw

cover Remove get_pathspec finally

Remove the last caller of the get_pathspec function and the get_pathspec function itself.

I stumbled into this as I was reading the documentation on pathspec, and the first sentence

get_pathspec() is obsolete and should never be used in new code.

made me wonder.

This replaces sb/remove-get-pathspec

Stefan Beller (2):
builtin/mv: remove get_pathspec()
pathspec: remove deprecated get_pathspec

 Documentation/technical/api-setup.txt |  2 --
 builtin/mv.c                          | 16 +++++++++++++---
 cache.h                               |  1 -
 pathspec.c                            | 36 -----------------------------------
 pathspec.h                            |  2 +-
 5 files changed, 14 insertions(+), 43 deletions(-)
Signature · 1 line
2.5.0.239.g9728e1d.dirty
#3 lore raw

PATCH 1/2 builtin/mv: remove get_pathspec()

get_pathspec is deprecated and builtin/mv.c is its last caller, so reimplement get_pathspec literally in builtin/mv.c

---
 builtin/mv.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
builtin/mv.c +13 -3
index d1d4316..99e9b3c 100644
@@ -10,6 +10,7 @@
 #include "string-list.h"
 #include "parse-options.h"
 #include "submodule.h"
+#include "pathspec.h"
 
 static const char * const builtin_mv_usage[] = {
 	N_("git mv [<options>] <source>... <destination>"),
@@ -20,13 +21,16 @@ static const char * const builtin_mv_usage[] = {
 #define KEEP_TRAILING_SLASH 2
 
 static const char **internal_copy_pathspec(const char *prefix,
-					   const char **pathspec,
+					   const char **argv,
 					   int count, unsigned flags)
 {
 	int i;
+	struct pathspec ps;
 	const char **result = xmalloc((count + 1) * sizeof(const char *));
-	memcpy(result, pathspec, count * sizeof(const char *));
+	memcpy(result, argv, count * sizeof(const char *));
 	result[count] = NULL;
+
+	/* NEEDSWORK: Move these preprocessing steps into parse_pathspec */
 	for (i = 0; i < count; i++) {
 		int length = strlen(result[i]);
 		int to_copy = length;
@@ -42,7 +46,13 @@ static const char **internal_copy_pathspec(const char *prefix,
 				result[i] = it;
 		}
 	}
-	return get_pathspec(prefix, result);
+
+	parse_pathspec(&ps,
+		       PATHSPEC_ALL_MAGIC &
+		       ~(PATHSPEC_FROMTOP | PATHSPEC_LITERAL),
+		       PATHSPEC_PREFER_CWD,
+		       prefix, result);
+	return ps._raw;
 }
 
 static const char *add_slash(const char *path)
Signature · 1 line
2.5.0.239.g9728e1d.dirty
#4 lore raw

Re: [PATCH 1/2] builtin/mv: remove get_pathspec()

Quoted 1 line · Stefan Beller

builtin/mv: remove get_pathspec()

Misleading. Perhaps rephrase as:

mv: drop dependency upon deprecated get_pathspec

Quoted 2 lines

get_pathspec is deprecated and builtin/mv.c is its last caller, so reimplement get_pathspec literally in builtin/mv.c

Curious. Since this is just moving code around, rather than doing the actual work to complete the final step as stated by the NEEDSWORK comment, isn't it just moving the "problem" from one location to another? Is it worth the code churn?

Quoted 15 lines

---

builtin/mv.c +1 -0
index d1d4316..99e9b3c 100644
@@ -10,6 +10,7 @@
 #include "string-list.h"
 #include "parse-options.h"
 #include "submodule.h"
+#include "pathspec.h"
 
 static const char * const builtin_mv_usage[] = {
        N_("git mv [<options>] <source>... <destination>"),

builtin/mv.c static const char * const builtin_mv_usage[] = { · line 24

Quoted 5 lines
builtin/mv.c +1 -1
@@ -20,13 +21,16 @@ static const char * const builtin_mv_usage[] = {
 #define KEEP_TRAILING_SLASH 2
 
 static const char **internal_copy_pathspec(const char *prefix,
-                                          const char **pathspec,
+                                          const char **argv,

What is this change about? It doesn't seem to be related to anything else in the patch or to its stated purpose, and makes the argument's purpose less clear, so it's not obvious why it is a good change.

Quoted 30 lines
builtin/mv.c +11 -3
                                           int count, unsigned flags)
 {
        int i;
+       struct pathspec ps;
        const char **result = xmalloc((count + 1) * sizeof(const char *));
-       memcpy(result, pathspec, count * sizeof(const char *));
+       memcpy(result, argv, count * sizeof(const char *));
        result[count] = NULL;
+
+       /* NEEDSWORK: Move these preprocessing steps into parse_pathspec */
        for (i = 0; i < count; i++) {
                int length = strlen(result[i]);
                int to_copy = length;
@@ -42,7 +46,13 @@ static const char **internal_copy_pathspec(const char *prefix,
                                result[i] = it;
                }
        }
-       return get_pathspec(prefix, result);
+
+       parse_pathspec(&ps,
+                      PATHSPEC_ALL_MAGIC &
+                      ~(PATHSPEC_FROMTOP | PATHSPEC_LITERAL),
+                      PATHSPEC_PREFER_CWD,
+                      prefix, result);
+       return ps._raw;
 }
 
 static const char *add_slash(const char *path)
--

2.5.0.239.g9728e1d.dirty

#5 lore raw

Re: [PATCH 1/2] builtin/mv: remove get_pathspec()

Quoted 7 lines · Eric Sunshine
Quoted 1 line · Stefan Beller

builtin/mv: remove get_pathspec()

Misleading. Perhaps rephrase as:

mv: drop dependency upon deprecated get_pathspec

Quoted 7 lines
Quoted 2 lines

get_pathspec is deprecated and builtin/mv.c is its last caller, so reimplement get_pathspec literally in builtin/mv.c

Curious. Since this is just moving code around, rather than doing the actual work to complete the final step as stated by the NEEDSWORK comment, isn't it just moving the "problem" from one location to another? Is it worth the code churn?

Yeah it is moving around the problem a bit. And the code churn is unfortunate. Though when I was reading the documentation on pathspecs, literally the first sentence was "Do not use get_pathspec, it is out dated". And that was a sad taste for reading documentation.

It's ok to have such warnings in the docs, but as the first sentence as if there was nothing more important than avoiding the out dated stuff? I mean I want to understand the actual code and how I can use it, right?

And there are different approaches to solving the problem. I could have just reworded or even just rearranged the documentation.

The approach I take here includes a bit of code churn, but it moves the problematic pieces all in one spot.

Quoted 56 lines
Quoted 16 lines

---

builtin/mv.c +1 -0
index d1d4316..99e9b3c 100644
@@ -10,6 +10,7 @@
 #include "string-list.h"
 #include "parse-options.h"
 #include "submodule.h"
+#include "pathspec.h"
 
 static const char * const builtin_mv_usage[] = {
        N_("git mv [<options>] <source>... <destination>"),

builtin/mv.c static const char * const builtin_mv_usage[] = { · line 24

Quoted 5 lines
builtin/mv.c +1 -1
@@ -20,13 +21,16 @@ static const char * const builtin_mv_usage[] = {
 #define KEEP_TRAILING_SLASH 2
 
 static const char **internal_copy_pathspec(const char *prefix,
-                                          const char **pathspec,
+                                          const char **argv,

What is this change about? It doesn't seem to be related to anything else in the patch or to its stated purpose, and makes the argument's purpose less clear, so it's not obvious why it is a good change.

Quoted 30 lines
builtin/mv.c +11 -3
                                           int count, unsigned flags)
 {
        int i;
+       struct pathspec ps;
        const char **result = xmalloc((count + 1) * sizeof(const char *));
-       memcpy(result, pathspec, count * sizeof(const char *));
+       memcpy(result, argv, count * sizeof(const char *));
        result[count] = NULL;
+
+       /* NEEDSWORK: Move these preprocessing steps into parse_pathspec */
        for (i = 0; i < count; i++) {
                int length = strlen(result[i]);
                int to_copy = length;
@@ -42,7 +46,13 @@ static const char **internal_copy_pathspec(const char *prefix,
                                result[i] = it;
                }
        }
-       return get_pathspec(prefix, result);
+
+       parse_pathspec(&ps,
+                      PATHSPEC_ALL_MAGIC &
+                      ~(PATHSPEC_FROMTOP | PATHSPEC_LITERAL),
+                      PATHSPEC_PREFER_CWD,
+                      prefix, result);
+       return ps._raw;
 }
 
 static const char *add_slash(const char *path)
--

2.5.0.239.g9728e1d.dirty

#6 lore raw

Re: [PATCH 1/2] builtin/mv: remove get_pathspec()

Quoted 10 lines · Stefan Beller
Quoted 8 lines · Eric Sunshine
Quoted 2 lines · Stefan Beller

get_pathspec is deprecated and builtin/mv.c is its last caller, so reimplement get_pathspec literally in builtin/mv.c

Curious. Since this is just moving code around, rather than doing the actual work to complete the final step as stated by the NEEDSWORK comment, isn't it just moving the "problem" from one location to another? Is it worth the code churn?

Quoted 4 lines

Yeah it is moving around the problem a bit. And the code churn is unfortunate. Though when I was reading the documentation on pathspecs, literally the first sentence was "Do not use get_pathspec, it is out dated". And that was a sad taste for reading documentation.

By loudly warning you about deprecation and, more importantly, pointing you at the accepted alternative, this documentation saves you from wasting time (both time spent reading and time spent going down a dead-end path). It would be a "sad taste" if it warned you quietly only at the end of the documentation or not at all.

Quoted 4 lines

It's ok to have such warnings in the docs, but as the first sentence as if there was nothing more important than avoiding the out dated stuff?

From a documentation standpoint, there is nothing more important than

warning you to avoid it since it is outdated and likely to go away in the future.

Quoted 1 line

I mean I want to understand the actual code and how I can use it, right?

No. It's deprecated and not meant for your use.

It's a different matter if you want to understand what the function does because you've encountered a call in existing code, but that case is covered by the existing documentation still being intact (that is, it wasn't removed when the deprecation notice was added).

Quoted 2 lines

And there are different approaches to solving the problem. I could have just reworded or even just rearranged the documentation.

The documentation seems fine as-is.

Quoted 2 lines

The approach I take here includes a bit of code churn, but it moves the problematic pieces all in one spot.

Indeed, I had the "localizing the problem to one spot" argument in mind, and even wrote it as an answer to my own question, but deleted it before hitting "Send". The counterargument (aside from code churn) is, that by leaving it alone, it serves as a good reminder of the "problem" and is more likely to get noticed and (perhaps) fixed by someone than if it is hidden away in builtin/mv.c.

#7 lore raw

Re: [PATCH 1/2] builtin/mv: remove get_pathspec()

Quoted 25 lines · Eric Sunshine
Quoted 10 lines · Stefan Beller
Quoted 8 lines · Eric Sunshine
Quoted 2 lines · Stefan Beller

get_pathspec is deprecated and builtin/mv.c is its last caller, so reimplement get_pathspec literally in builtin/mv.c

Curious. Since this is just moving code around, rather than doing the actual work to complete the final step as stated by the NEEDSWORK comment, isn't it just moving the "problem" from one location to another? Is it worth the code churn?

Quoted 4 lines

Yeah it is moving around the problem a bit. And the code churn is unfortunate. Though when I was reading the documentation on pathspecs, literally the first sentence was "Do not use get_pathspec, it is out dated". And that was a sad taste for reading documentation.

By loudly warning you about deprecation and, more importantly, pointing you at the accepted alternative, this documentation saves you from wasting time (both time spent reading and time spent going down a dead-end path). It would be a "sad taste" if it warned you quietly only at the end of the documentation or not at all.

Quoted 2 lines

It's ok to have such warnings in the docs, but as the first sentence as if there was nothing more important than avoiding the out dated stuff?

Quoted 7 lines

From a documentation standpoint, there is nothing more important than warning you to avoid it since it is outdated and likely to go away in the future.

Quoted 1 line

I mean I want to understand the actual code and how I can use it, right?

No. It's deprecated and not meant for your use.

I need to be more precise:
I mean I want to learn how to deal with <pathspec> things in code. Assume I know nothing of the history of that code and its deprecated earlier attempts. So I would expect a documentation like:

foo-bar(int arg): bars the foos with the specific thing equal arg

foobaz(int a, int b, int c): Note: this is outdated, bars the foos with ...

in that order, so if I were to start reading from top to bottom, I would find the current version first and could jump off starting writing code based on foo-bar.

If I was reading code and wonder: "What does foobaz exactly do? Oh I know! I'll consult the documentation", then I would find the note about it being out dated and preferably its suggested new replacement.

However I perceived the documentation I read more like this:

some words on foo-bar, a bit too shallow (a good overview, but I'd like to know more details, so keep reading)

note on foobaz being outdated

more words on foo-bar

Quoted 14 lines

It's a different matter if you want to understand what the function does because you've encountered a call in existing code, but that case is covered by the existing documentation still being intact (that is, it wasn't removed when the deprecation notice was added).

Quoted 2 lines

And there are different approaches to solving the problem. I could have just reworded or even just rearranged the documentation.

The documentation seems fine as-is.

Quoted 2 lines

The approach I take here includes a bit of code churn, but it moves the problematic pieces all in one spot.

Quoted 6 lines

Indeed, I had the "localizing the problem to one spot" argument in mind, and even wrote it as an answer to my own question, but deleted it before hitting "Send". The counterargument (aside from code churn) is, that by leaving it alone, it serves as a good reminder of the "problem" and is more likely to get noticed and (perhaps) fixed by someone than if it is hidden away in builtin/mv.c.

Having code just in one ugly spot however helps people in the other areas, where they can see the shiny new thing in action and don't have the mental burden of seeing a NEEDSWORK comment and thinking about that instead of the feature they want to add there.

#8 lore raw

PATCH 2/2 pathspec: remove deprecated get_pathspec

In reply to Stefan Beller

The function get_pathspec is no longer used, so remove it.

The NEEDSWORK comment in pathspec.c is outdated as that happened in (fadf96aba, 2013-09-09, Merge branch 'nd/magic-pathspec')

---
 Documentation/technical/api-setup.txt |  2 --
 cache.h                               |  1 -
 pathspec.c                            | 36 -----------------------------------
 pathspec.h                            |  2 +-
 4 files changed, 1 insertion(+), 40 deletions(-)
Documentation/technical/api-setup.txt +0 -2
index 540e455..eb1fa98 100644
@@ -27,8 +27,6 @@ parse_pathspec(). This function takes several arguments:
 
 - prefix and args come from cmd_* functions
 
-get_pathspec() is obsolete and should never be used in new code.
-
 parse_pathspec() helps catch unsupported features and reject them
 politely. At a lower level, different pathspec-related functions may
 not support the same set of features. Such pathspec-sensitive
cache.h +0 -1
index 4f55466..d4e22e2 100644
@@ -452,7 +452,6 @@ extern void set_git_work_tree(const char *tree);
 
 #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
 
-extern const char **get_pathspec(const char *prefix, const char **pathspec);
 extern void setup_work_tree(void);
 extern const char *setup_git_directory_gently(int *);
 extern const char *setup_git_directory(void);
pathspec.c +0 -36
index 9304ee3..abaec0a 100644
@@ -94,12 +94,6 @@ static void prefix_short_magic(struct strbuf *sb, int prefixlen,
  *
  * For now, we only parse the syntax and throw out anything other than
  * "top" magic.
- *
- * NEEDSWORK: This needs to be rewritten when we start migrating
- * get_pathspec() users to use the "struct pathspec" interface.  For
- * example, a pathspec element may be marked as case-insensitive, but
- * the prefix part must always match literally, and a single stupid
- * string cannot express such a case.
  */
 static unsigned prefix_pathspec(struct pathspec_item *item,
 				unsigned *p_short_magic,
@@ -450,36 +444,6 @@ void parse_pathspec(struct pathspec *pathspec,
 	}
 }
 
-/*
- * N.B. get_pathspec() is deprecated in favor of the "struct pathspec"
- * based interface - see pathspec.c:parse_pathspec().
- *
- * Arguments:
- *  - prefix - a path relative to the root of the working tree
- *  - pathspec - a list of paths underneath the prefix path
- *
- * Iterates over pathspec, prepending each path with prefix,
- * and return the resulting list.
- *
- * If pathspec is empty, return a singleton list containing prefix.
- *
- * If pathspec and prefix are both empty, return an empty list.
- *
- * This is typically used by built-in commands such as add.c, in order
- * to normalize argv arguments provided to the built-in into a list of
- * paths to process, all relative to the root of the working tree.
- */
-const char **get_pathspec(const char *prefix, const char **pathspec)
-{
-	struct pathspec ps;
-	parse_pathspec(&ps,
-		       PATHSPEC_ALL_MAGIC &
-		       ~(PATHSPEC_FROMTOP | PATHSPEC_LITERAL),
-		       PATHSPEC_PREFER_CWD,
-		       prefix, pathspec);
-	return ps._raw;
-}
-
 void copy_pathspec(struct pathspec *dst, const struct pathspec *src)
 {
 	*dst = *src;
pathspec.h +1 -1
index 0c11262..b345df6 100644
@@ -19,7 +19,7 @@
 #define PATHSPEC_ONESTAR 1	/* the pathspec pattern satisfies GFNM_ONESTAR */
 
 struct pathspec {
-	const char **_raw; /* get_pathspec() result, not freed by free_pathspec() */
+	const char **_raw; /* not freed by free_pathspec() */
 	int nr;
 	unsigned int has_wildcard:1;
 	unsigned int recursive:1;
Signature · 1 line
2.5.0.239.g9728e1d.dirty