Skip to content

Commit fdb3e30

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.
1 parent c2b7570 commit fdb3e30

File tree

5 files changed

+56
-4
lines changed

5 files changed

+56
-4
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: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ git_lfs_is_available (void)
194194

195195
static gboolean
196196
builder_git_run_lfs (GFile *dir,
197+
FlatpakGitMirrorFlags flags,
197198
GError **error,
198199
const char *subcommand,
199200
...)
@@ -203,6 +204,9 @@ builder_git_run_lfs (GFile *dir,
203204
const char *arg;
204205
gboolean ok;
205206

207+
if (flags & FLATPAK_GIT_MIRROR_FLAGS_DISABLE_LFS)
208+
return TRUE;
209+
206210
if (!git_lfs_is_available ())
207211
return TRUE;
208212

@@ -657,7 +661,7 @@ builder_git_mirror_repo (const char *repo_location,
657661
origin, full_ref_mapping, NULL))
658662
return FALSE;
659663

660-
if (!builder_git_run_lfs (mirror_dir, error,
664+
if (!builder_git_run_lfs (mirror_dir, flags, error,
661665
"fetch", "--all", NULL))
662666
return FALSE;
663667

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

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,11 +953,24 @@ builder_git_checkout (const char *repo_location,
949953
"config", "--bool", "core.bare", "false", NULL))
950954
return FALSE;
951955

956+
/* If the user explicitly asks to disables LFS, install the per-repo
957+
* lfs filter without any hooks and with skip-smudge so that the
958+
* plain git checkout below this does not try to fetch the LFS
959+
* objects again. The plain checkout will only retrieve the
960+
* pointer files to the LFS objects. */
961+
if ((mirror_flags & FLATPAK_GIT_MIRROR_FLAGS_DISABLE_LFS) && git_lfs_is_available ())
962+
{
963+
if (!git_lfs (dest, NULL, 0, error,
964+
(const char *[]){"install", "--local", "--skip-smudge", "--skip-repo", NULL}))
965+
return FALSE;
966+
}
967+
952968
if (!git (dest, NULL, 0, error,
953969
"checkout", branch, NULL))
954970
return FALSE;
955971

956-
if (!builder_git_run_lfs (dest, error, "checkout", NULL))
972+
if (!builder_git_run_lfs (dest, mirror_flags, error,
973+
"checkout", NULL))
957974
return FALSE;
958975

959976
if (mirror_flags & FLATPAK_GIT_MIRROR_FLAGS_MIRROR_SUBMODULES)

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)