Skip to content

Commit a4d5817

Browse files
committed
builder-git: Add a property to disable explicitly fetching LFS
The previous commit will attempt to fetch LFS by default for Git sources even if LFS is not configured (but available). This allows to disable that behaviour on a per source basis since repos may have huge LFS assets which may be undesirable to fetch. But if LFS is available and smudge filters are active, a `git checkout` will automatically fetch LFS objects by default even with `disable-lfs: true`. To skip that `GIT_LFS_SKIP_SMUDGE=1` can be set in the environment.
1 parent e2586a5 commit a4d5817

File tree

5 files changed

+46
-5
lines changed

5 files changed

+46
-5
lines changed

data/flatpak-manifest.schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,10 @@
840840
"disable-submodules": {
841841
"description": "Don't checkout the git submodules when cloning the repository.",
842842
"type": "boolean"
843+
},
844+
"disable-lfs": {
845+
"description": "Don't explicitly fetch or checkout LFS git objects.",
846+
"type": "boolean"
843847
}
844848
},
845849
"patternProperties": {

doc/flatpak-manifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,10 @@
772772
<term><option>disable-submodules</option> (boolean)</term>
773773
<listitem><para>Don't checkout the git submodules when cloning the repository.</para></listitem>
774774
</varlistentry>
775+
<varlistentry>
776+
<term><option>disable-lfs</option> (boolean)</term>
777+
<listitem><para>Don't explicitly fetch or checkout LFS git objects.</para></listitem>
778+
</varlistentry>
775779
</variablelist>
776780
</refsect3>
777781
<refsect3>

src/builder-git.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,17 @@ git_lfs_is_available (void)
202202

203203
static gboolean
204204
builder_git_run_lfs (GFile *dir,
205+
FlatpakGitMirrorFlags flags,
205206
GError **error,
206207
const char *subcommand,
207208
...)
208209
{
209210
va_list args;
210211
gboolean ok;
211212

213+
if (flags & FLATPAK_GIT_MIRROR_FLAGS_DISABLE_LFS)
214+
return TRUE;
215+
212216
if (!git_lfs_is_available ())
213217
return TRUE;
214218

@@ -656,7 +660,7 @@ builder_git_mirror_repo (const char *repo_location,
656660
return FALSE;
657661

658662
g_print ("Fetching LFS assets\n");
659-
if (!builder_git_run_lfs (mirror_dir, error,
663+
if (!builder_git_run_lfs (mirror_dir, flags, error,
660664
"fetch", "--all", NULL))
661665
return FALSE;
662666

@@ -690,7 +694,7 @@ builder_git_mirror_repo (const char *repo_location,
690694
return FALSE;
691695

692696
g_print ("Fetching LFS assets\n");
693-
if (!builder_git_run_lfs (mirror_dir, error,
697+
if (!builder_git_run_lfs (mirror_dir, flags, error,
694698
"fetch", "--all", NULL))
695699
return FALSE;
696700
}
@@ -795,7 +799,7 @@ builder_git_shallow_mirror_ref (const char *repo_location,
795799
"fetch", "--depth", "1", "origin", full_ref_colon_full_ref, NULL))
796800
return FALSE;
797801

798-
if (!builder_git_run_lfs (mirror_dir, error,
802+
if (!builder_git_run_lfs (mirror_dir, flags, error,
799803
"fetch", "origin", full_ref, NULL))
800804
return FALSE;
801805

@@ -949,14 +953,16 @@ builder_git_checkout (const char *repo_location,
949953
"config", "--bool", "core.bare", "false", NULL))
950954
return FALSE;
951955

952-
if (!builder_git_run_lfs (dest, error, "install", NULL))
956+
if (!builder_git_run_lfs (dest, mirror_flags, error,
957+
"install", NULL))
953958
return FALSE;
954959

955960
if (!git (dest, NULL, 0, error,
956961
"checkout", branch, NULL))
957962
return FALSE;
958963

959-
if (!builder_git_run_lfs (dest, error, "checkout", NULL))
964+
if (!builder_git_run_lfs (dest, mirror_flags, error,
965+
"checkout", NULL))
960966
return FALSE;
961967

962968

src/builder-git.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ typedef enum {
3131
FLATPAK_GIT_MIRROR_FLAGS_DISABLE_FSCK = 1 << 2,
3232
FLATPAK_GIT_MIRROR_FLAGS_DISABLE_SHALLOW = 1 << 3,
3333
FLATPAK_GIT_MIRROR_FLAGS_WILL_FETCH_FROM = 1 << 4,
34+
FLATPAK_GIT_MIRROR_FLAGS_DISABLE_LFS = 1 << 5,
3435
} FlatpakGitMirrorFlags;
3536

3637
gboolean builder_git_mirror_repo (const char *repo_location,

src/builder-source-git.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ struct BuilderSourceGit
4848
gboolean disable_fsckobjects;
4949
gboolean disable_shallow_clone;
5050
gboolean disable_submodules;
51+
gboolean disable_lfs;
5152
};
5253

5354
typedef struct
@@ -67,6 +68,7 @@ enum {
6768
PROP_DISABLE_FSCKOBJECTS,
6869
PROP_DISABLE_SHALLOW_CLONE,
6970
PROP_DISABLE_SUBMODULES,
71+
PROP_DISABLE_LFS,
7072
LAST_PROP
7173
};
7274

@@ -128,6 +130,10 @@ builder_source_git_get_property (GObject *object,
128130
g_value_set_boolean (value, self->disable_submodules);
129131
break;
130132

133+
case PROP_DISABLE_LFS:
134+
g_value_set_boolean (value, self->disable_lfs);
135+
break;
136+
131137
default:
132138
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
133139
}
@@ -180,6 +186,10 @@ builder_source_git_set_property (GObject *object,
180186
self->disable_submodules = g_value_get_boolean (value);
181187
break;
182188

189+
case PROP_DISABLE_LFS:
190+
self->disable_lfs = g_value_get_boolean (value);
191+
break;
192+
183193
default:
184194
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
185195
}
@@ -255,6 +265,8 @@ builder_source_git_download (BuilderSource *source,
255265

256266
if (!self->disable_submodules)
257267
flags |= FLATPAK_GIT_MIRROR_FLAGS_MIRROR_SUBMODULES;
268+
if (self->disable_lfs)
269+
flags |= FLATPAK_GIT_MIRROR_FLAGS_DISABLE_LFS;
258270
if (update_vcs)
259271
flags |= FLATPAK_GIT_MIRROR_FLAGS_UPDATE;
260272
if (self->disable_fsckobjects)
@@ -303,6 +315,9 @@ builder_source_git_extract (BuilderSource *source,
303315
if (!self->disable_submodules)
304316
mirror_flags |= FLATPAK_GIT_MIRROR_FLAGS_MIRROR_SUBMODULES;
305317

318+
if (self->disable_lfs)
319+
mirror_flags |= FLATPAK_GIT_MIRROR_FLAGS_DISABLE_LFS;
320+
306321
if (!builder_git_checkout (location, get_branch (self, location),
307322
dest, context, mirror_flags, error))
308323
return FALSE;
@@ -336,6 +351,9 @@ builder_source_git_bundle (BuilderSource *source,
336351
if (!self->disable_submodules)
337352
flags |= FLATPAK_GIT_MIRROR_FLAGS_MIRROR_SUBMODULES;
338353

354+
if (self->disable_lfs)
355+
flags |= FLATPAK_GIT_MIRROR_FLAGS_DISABLE_LFS;
356+
339357
if (!builder_git_shallow_mirror_ref (location,
340358
flatpak_file_get_path_cached (mirror_dir),
341359
flags,
@@ -481,6 +499,14 @@ builder_source_git_class_init (BuilderSourceGitClass *klass)
481499
"",
482500
FALSE,
483501
G_PARAM_READWRITE));
502+
503+
g_object_class_install_property (object_class,
504+
PROP_DISABLE_LFS,
505+
g_param_spec_boolean ("disable-lfs",
506+
"",
507+
"",
508+
FALSE,
509+
G_PARAM_READWRITE));
484510
}
485511

486512
static void

0 commit comments

Comments
 (0)