Skip to content

Commit 6005cdc

Browse files
RajivTSfacebook-github-bot
authored andcommitted
Add upload tag functionality to gitimport binary
Summary: Every now and then we come across a weird tag object that gitimport as part of its normal execution doesn't upload for some reason. This new command is created specifically for that purpose. Note that this won't add a mapping in `bonsai_tag_mapping` table but will simply upload the tag object to the storage layer. We might want to extend this to add the mappings as well in the future, if we see a need. Reviewed By: markbt Differential Revision: D75960452 fbshipit-source-id: 81596968cd5d5c4861c533c0a7608411a8426485
1 parent a51d4f9 commit 6005cdc

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

eden/mononoke/git/gitimport/src/main.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ mod repo;
1010
use std::collections::HashMap;
1111
use std::path::Path;
1212
use std::path::PathBuf;
13+
use std::str::FromStr;
1314
use std::sync::Arc;
1415

1516
use anyhow::Context;
@@ -227,6 +228,10 @@ enum GitimportSubcommand {
227228
ImportTreeAsSingleBonsaiChangeset {
228229
git_commit: String,
229230
},
231+
/// Import a single tag object into Mononoke data store
232+
UploadTag {
233+
tag_sha1: String,
234+
},
230235
}
231236

232237
#[fbinit::main]
@@ -328,7 +333,7 @@ async fn async_main(app: MononokeApp) -> Result<(), Error> {
328333
}
329334

330335
let uploader = Arc::new(import_direct::DirectUploader::new(repo.clone(), reupload));
331-
336+
let reader = Arc::new(GitRepoReader::new(&prefs.git_command_path, path).await?);
332337
let target = match args.subcommand {
333338
GitimportSubcommand::FullRepo {} => GitimportTarget::full(),
334339
GitimportSubcommand::GitRange { git_from, git_to } => {
@@ -357,6 +362,15 @@ async fn async_main(app: MononokeApp) -> Result<(), Error> {
357362
}
358363
return Ok(());
359364
}
365+
GitimportSubcommand::UploadTag { tag_sha1 } => {
366+
let tag_sha1 = ObjectId::from_str(&tag_sha1)
367+
.with_context(|| format!("Invalid SHA1 hash provided for Git Tag {}", tag_sha1))?;
368+
upload_git_tag(&ctx, uploader.clone(), reader.clone(), &tag_sha1)
369+
.await
370+
.with_context(|| format!("Error in uploading tag with ID {}", tag_sha1))?;
371+
info!(ctx.logger(), "Uploaded tag with ID {}", tag_sha1);
372+
return Ok(());
373+
}
360374
};
361375

362376
let gitimport_result: LinkedHashMap<_, _> =
@@ -425,7 +439,6 @@ async fn async_main(app: MononokeApp) -> Result<(), Error> {
425439
.into_iter()
426440
.map(|entry| (entry.tag_name, entry.tag_hash))
427441
.collect::<HashMap<_, _>>();
428-
let reader = Arc::new(GitRepoReader::new(&prefs.git_command_path, path).await?);
429442
let pushvars = if args.bypass_readonly {
430443
Some(HashMap::from_iter([(
431444
"BYPASS_READONLY".to_string(),
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This software may be used and distributed according to the terms of the
4+
# GNU General Public License found in the LICENSE file in the root
5+
# directory of this source tree.
6+
7+
$ . "${TEST_FIXTURES}/library.sh"
8+
$ GIT_REPO="${TESTTMP}/repo-git"
9+
$ setup_common_config blob_files
10+
11+
# Setup git repository
12+
$ mkdir -p "$GIT_REPO"
13+
$ cd "$GIT_REPO"
14+
$ git init -q
15+
$ echo "this is file1" > file1
16+
$ git add file1
17+
$ git commit -qa -m "Commit"
18+
$ git tag -a -m "Tag" tag1
19+
$ tag_hash=$(git rev-parse tags/tag1)
20+
21+
# Import just the tag into Mononoke
22+
$ with_stripped_logs gitimport "$GIT_REPO" upload-tag $tag_hash
23+
using repo "repo" repoid RepositoryId(0)
24+
Uploaded tag with ID 929a3a6ccd846af11aa4384cc99d63691b480d9d
25+
26+
# Ensure that the uploaded tag is visible in Mononoke
27+
$ mononoke_admin git-objects -R repo fetch --id $tag_hash
28+
The object is a Git Tag
29+
30+
Tag {
31+
target: Sha1(15cc4e9575665b507ee372f97b716ff552842136),
32+
target_kind: Commit,
33+
name: "tag1",
34+
tagger: Some(
35+
Signature {
36+
name: "mononoke",
37+
email: "mononoke@mononoke",
38+
time: Time {
39+
seconds: 946684800,
40+
offset: 0,
41+
},
42+
},
43+
),
44+
message: "Tag\n",
45+
pgp_signature: None,
46+
}

0 commit comments

Comments
 (0)