Skip to contentSkip to conversation

fetch: add a config option to always use the depth argument

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

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fetch: add a config option to always use the depth argument

When having a repository, which deals with large amounts of data, i.e. graphics, music, films, you may want to keep the git directory at the smallest size possible.

The depth option helped us in achieving this goal by removing the sizable history and just keep recent history around. In the case of having large amounts of data around, you probably want to use the depth option at any fetch you do, so it would be convenient to have an option for this.

Change-Id I45a569239639f20e24fbae32fb2046bc478c5f07
---
 Documentation/config.txt        | 6 ++++++
 Documentation/fetch-options.txt | 2 ++
 builtin/fetch.c                 | 5 +++++
 3 files changed, 13 insertions(+)
Documentation/config.txt +6 -0
index 9220725..418e21f 100644
@@ -1106,6 +1106,12 @@ fetch.prune::
 	If true, fetch will automatically behave as if the `--prune`
 	option was given on the command line.  See also `remote.<name>.prune`.
 
+fetch.depth::
+	If set, fetch will automatically behave as if the `--depth`
+	option was given on the command line.  This allows users to keep
+	the git directory at low space requirements, and thus comes in handy
+	for users with large binary files in the repository.
+
 format.attach::
 	Enable multipart/mixed attachments as the default for
 	'format-patch'.  The value can also be a double quoted string
Documentation/fetch-options.txt +2 -0
index b09a783..81131d0 100644
@@ -12,6 +12,8 @@
 	`git clone` with `--depth=<depth>` option (see linkgit:git-clone[1])
 	to the specified number of commits from the tip of each remote
 	branch history. Tags for the deepened commits are not fetched.
+	You can configure git to always use the depth option, see
+	`fetch.depth` in linkgit:git-config[1]
 
 --unshallow::
 	If the source repository is complete, convert a shallow
builtin/fetch.c +5 -0
index 7b84d35..30fa15b 100644
@@ -68,6 +68,11 @@ static int git_fetch_config(const char *k, const char *v, void *cb)
 		fetch_prune_config = git_config_bool(k, v);
 		return 0;
 	}
+	if (!strcmp(k, "fetch.depth")) {
+		if (git_config_string(&depth, k, v))
+			return -1;
+		return 0;
+	}
 	return git_default_config(k, v, cb);
 }
 
Signature · 1 line
2.1.2
#1 lore raw
Quoted 22 lines · Stefan Beller

When having a repository, which deals with large amounts of data, i.e. graphics, music, films, you may want to keep the git directory at the smallest size possible.

The depth option helped us in achieving this goal by removing the sizable history and just keep recent history around. In the case of having large amounts of data around, you probably want to use the depth option at any fetch you do, so it would be convenient to have an option for this.

Change-Id I45a569239639f20e24fbae32fb2046bc478c5f07
---
 Documentation/config.txt        | 6 ++++++
 Documentation/fetch-options.txt | 2 ++
 builtin/fetch.c                 | 5 +++++
 3 files changed, 13 insertions(+)
Documentation/config.txt +0 -0
index 9220725..418e21f 100644

Documentation/config.txt fetch.prune:: · line 1114

Quoted 9 lines
Documentation/config.txt +6 -0
@@ -1106,6 +1106,12 @@ fetch.prune::
 	If true, fetch will automatically behave as if the `--prune`
 	option was given on the command line.  See also `remote.<name>.prune`.
 
+fetch.depth::
+	If set, fetch will automatically behave as if the `--depth`
+	option was given on the command line.  This allows users to keep
+	the git directory at low space requirements, and thus comes in handy
+	for users with large binary files in the repository.
+

Hmm, is this something a user would typically want repository-wide? I am wondering if "remote.$nick.fetchDepth" or something scoped to remote is more appropriate.

Quoted 31 lines
Documentation/config.txt +0 -0
 format.attach::
 	Enable multipart/mixed attachments as the default for
 	'format-patch'.  The value can also be a double quoted string
Documentation/fetch-options.txt +2 -0
index b09a783..81131d0 100644
@@ -12,6 +12,8 @@
 	`git clone` with `--depth=<depth>` option (see linkgit:git-clone[1])
 	to the specified number of commits from the tip of each remote
 	branch history. Tags for the deepened commits are not fetched.
+	You can configure git to always use the depth option, see
+	`fetch.depth` in linkgit:git-config[1]
 
 --unshallow::
 	If the source repository is complete, convert a shallow
builtin/fetch.c +5 -0
index 7b84d35..30fa15b 100644
@@ -68,6 +68,11 @@ static int git_fetch_config(const char *k, const char *v, void *cb)
 		fetch_prune_config = git_config_bool(k, v);
 		return 0;
 	}
+	if (!strcmp(k, "fetch.depth")) {
+		if (git_config_string(&depth, k, v))
+			return -1;
+		return 0;
+	}
 	return git_default_config(k, v, cb);
 }
#2 lore raw
Quoted 12 lines · Junio C Hamano

Documentation/config.txt fetch.prune:: · line 1114

Quoted 6 lines · Stefan Beller
Documentation/config.txt +6 -0
+fetch.depth::
+	If set, fetch will automatically behave as if the `--depth`
+	option was given on the command line.  This allows users to keep
+	the git directory at low space requirements, and thus comes in handy
+	for users with large binary files in the repository.
+

Hmm, is this something a user would typically want repository-wide? I am wondering if "remote.$nick.fetchDepth" or something scoped to remote is more appropriate.

Regardless of what configuration variable is used, I think setting depth directly from the config will mean the user cannot defeat a configured value by passing --unshallow because of this code sequence in builtin/fetch.c; am I mistaken?

	...
	git_config(git_fetch_config, NULL);
	argc = parse_options(argc, argv, prefix,
			     builtin_fetch_options, builtin_fetch_usage, 0);
	if (unshallow) {
		if (depth)
			die(_("--depth and --unshallow cannot be used together"));
	...

I think depth variable should be left alone.

The right solution may be to leave the above "unshallow and depth are incompatible" check done only for the command line options as the original code, and much later in the code path after you figure out which remote we are talking to, only when neither --depth nor --unshallow is given, consult the configuration system to see if there is a default, perhaps in prepare_transport(). That approach will let you later support "remote.$nick.fetchDepth", even if you start with a repository-wide "fetch.depth" option, I would think.