Skip to content

Commit 26350af

Browse files
author
majin.nathan
committed
docs: clarify main branch API semantics
1 parent 85c01f0 commit 26350af

5 files changed

Lines changed: 58 additions & 23 deletions

File tree

docs/src/guide/tags_and_branches.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ The `reference` parameter (used in `create`, `update`, and `checkout_version`) a
1515
- An **integer**: version number in the **current branch** (e.g., `1`)
1616
- A **string**: tag name (e.g., `"stable"`)
1717
- A **tuple** `(branch_name, version)`: a specific version in a named branch
18-
- `(None, 2)` means version 2 on the main branch
19-
- `("main", 2)` means version 2 on the main branch (explicit)
18+
- `(None, 2)` means version 2 on the default branch
19+
- `("main", 2)` means version 2 on the default branch (explicit)
2020
- `("experiment", 3)` means version 3 on the experiment branch
2121
- `("branch-name", None)` means the latest version on that branch
2222

java/src/main/java/org/lance/Dataset.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,10 +1690,12 @@ public Branches branches() {
16901690

16911691
/**
16921692
* Create a branch at a specified version. The returned Dataset points to the created branch's
1693-
* initial version.
1693+
* initial version. The branch name {@code "main"} is reserved for the default branch and cannot
1694+
* be used as a new branch name.
16941695
*
16951696
* @param branch the branch name to create
1696-
* @param ref the reference to create branch from
1697+
* @param ref the reference to create branch from. In reference contexts, {@code "main"} is an
1698+
* alias for the default branch.
16971699
* @return a new Dataset of the branch
16981700
*/
16991701
public Dataset createBranch(String branch, Ref ref) {
@@ -1703,10 +1705,12 @@ public Dataset createBranch(String branch, Ref ref) {
17031705

17041706
/**
17051707
* Create a branch at a specified version. The returned Dataset points to the created branch's
1706-
* initial version.
1708+
* initial version. The branch name {@code "main"} is reserved for the default branch and cannot
1709+
* be used as a new branch name.
17071710
*
17081711
* @param branch the branch name to create
1709-
* @param ref the reference to create branch from
1712+
* @param ref the reference to create branch from. In reference contexts, {@code "main"} is an
1713+
* alias for the default branch.
17101714
* @param storageOptions the storage options to create branch with
17111715
* @return a new Dataset of the branch
17121716
*/
@@ -1727,8 +1731,9 @@ private Dataset innerCreateBranch(
17271731
}
17281732

17291733
/**
1730-
* Checkout using a unified {@link Ref} which can be a tag, the latest version on main/branch or a
1731-
* specified (branch_name, version_number).
1734+
* Checkout using a unified {@link Ref} which can be a tag, the latest version on the default
1735+
* branch or a named branch, or a specified (branch_name, version_number). In reference contexts,
1736+
* {@code "main"} is an alias for the default branch.
17321737
*
17331738
* @param ref the checkout reference
17341739
* @return a new Dataset instance checked out to the specified reference
@@ -1765,7 +1770,7 @@ public Map<String, String> getTableMetadata() {
17651770
public class Tags {
17661771

17671772
/**
1768-
* Create a new tag on main branch. This is left for compatibility. We should use {@link
1773+
* Create a new tag on the default branch. This is left for compatibility. We should use {@link
17691774
* #create(String, Ref)} instead.
17701775
*
17711776
* @param tag the tag name
@@ -1780,7 +1785,8 @@ public void create(String tag, long versionNumber) {
17801785
* Create a new tag on a specified branch.
17811786
*
17821787
* @param tag the tag name
1783-
* @param ref the referenced version to tag
1788+
* @param ref the referenced version to tag. In reference contexts, {@code "main"} is an alias
1789+
* for the default branch.
17841790
*/
17851791
public void create(String tag, Ref ref) {
17861792
Preconditions.checkArgument(tag != null, "Tag name cannot be null");
@@ -1797,6 +1803,8 @@ public void create(String tag, Ref ref) {
17971803
*
17981804
* @param tag the name of the tag to create
17991805
* @param versionNumber the version number (or commit reference) to associate with the tag
1806+
* @param targetBranch the branch to tag. In reference contexts, {@code "main"} is an alias for
1807+
* the default branch.
18001808
*/
18011809
@Deprecated
18021810
public void create(String tag, long versionNumber, String targetBranch) {
@@ -1816,11 +1824,11 @@ public void delete(String tag) {
18161824
}
18171825

18181826
/**
1819-
* Update a tag to a new version_number on main. This is left for compatibility. We should use
1820-
* {@link #update(String, Ref)} instead.
1827+
* Update a tag to a new version_number on the default branch. This is left for compatibility.
1828+
* We should use {@link #update(String, Ref)} instead.
18211829
*
18221830
* @param tag the tag name
1823-
* @param versionNumber the versionNumber on main.
1831+
* @param versionNumber the versionNumber on the default branch.
18241832
*/
18251833
public void update(String tag, long versionNumber) {
18261834
Preconditions.checkArgument(versionNumber > 0, "version_number must be greater than 0");
@@ -1831,7 +1839,8 @@ public void update(String tag, long versionNumber) {
18311839
* Update a tag to a new reference.
18321840
*
18331841
* @param tag the tag name
1834-
* @param ref the referenced version to tag
1842+
* @param ref the referenced version to tag. In reference contexts, {@code "main"} is an alias
1843+
* for the default branch.
18351844
*/
18361845
public void update(String tag, Ref ref) {
18371846
Preconditions.checkArgument(tag != null, "tag cannot be null");
@@ -1883,7 +1892,8 @@ public class Branches {
18831892
/**
18841893
* Delete a branch and its metadata.
18851894
*
1886-
* @param branchName the branch to delete
1895+
* @param branchName the branch to delete. {@code "main"} is reserved for the default branch and
1896+
* cannot be deleted as a named branch.
18871897
*/
18881898
public void delete(String branchName) {
18891899
try (LockManager.WriteLock writeLock = lockManager.acquireWriteLock()) {

java/src/main/java/org/lance/Ref.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,33 @@ public Optional<String> getTagName() {
4141
return tagName;
4242
}
4343

44+
/** Creates a reference to a specific version on the default branch. */
4445
public static Ref ofMain(long versionNumber) {
4546
Preconditions.checkArgument(versionNumber > 0, "versionNumber must be greater than 0");
4647
return new Ref(Optional.of(versionNumber), Optional.empty(), Optional.empty());
4748
}
4849

50+
/** Creates a reference to the latest version on the default branch. */
4951
public static Ref ofMain() {
5052
return new Ref(Optional.empty(), Optional.empty(), Optional.empty());
5153
}
5254

55+
/**
56+
* Creates a reference to the latest version on a branch.
57+
*
58+
* <p>In reference contexts, {@code "main"} is an alias for the default branch.
59+
*/
5360
public static Ref ofBranch(String branchName) {
5461
Preconditions.checkArgument(
5562
branchName != null && !branchName.isEmpty(), "branchName must not be empty");
5663
return new Ref(Optional.empty(), Optional.of(branchName), Optional.empty());
5764
}
5865

66+
/**
67+
* Creates a reference to a specific version on a branch.
68+
*
69+
* <p>In reference contexts, {@code "main"} is an alias for the default branch.
70+
*/
5971
public static Ref ofBranch(String branchName, long versionNumber) {
6072
Preconditions.checkArgument(
6173
branchName != null && !branchName.isEmpty(), "branchName must not be empty");

python/python/lance/dataset.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -926,12 +926,14 @@ def create_branch(
926926
Parameters
927927
----------
928928
branch: str
929-
Name of the branch to create.
929+
Name of the branch to create. ``"main"`` is reserved for the
930+
default branch and cannot be used as a new branch name.
930931
reference: Optional[int | str | Tuple[Optional[str], Optional[int]]
931932
An integer specifies a version number in the current branch; a string
932933
specifies a tag name; a Tuple[Optional[str], Optional[int]] specifies
933934
a version number in a specified branch. (None, None) means the latest
934-
version_number on the main branch.
935+
version_number on the default branch. ``("main", version)`` is an
936+
explicit alias for the default branch in this reference context.
935937
storage_options: Optional[Dict[str, str]]
936938
Storage options for the underlying object store. If not provided,
937939
the storage options from the current dataset will be used.
@@ -2863,7 +2865,8 @@ def checkout_version(
28632865
An integer specifies a version number in the current branch; a string
28642866
specifies a tag name; a Tuple[Optional[str], Optional[int]] specifies
28652867
a version number in a specified branch. (None, None) means the latest
2866-
version_number on the main branch.
2868+
version_number on the default branch. ``("main", version)`` is an
2869+
explicit alias for the default branch in this reference context.
28672870
28682871
Returns
28692872
-------
@@ -4616,7 +4619,8 @@ def shallow_clone(
46164619
An integer specifies a version number in the current branch; a string
46174620
specifies a tag name; a Tuple[Optional[str], Optional[int]] specifies
46184621
a version number in a specified branch. (None, None) means the latest
4619-
version_number on the main branch.
4622+
version_number on the default branch. ``("main", version)`` is an
4623+
explicit alias for the default branch in this reference context.
46204624
storage_options : dict, optional
46214625
Object store configuration for the new dataset (e.g., credentials,
46224626
endpoints). If not specified, the storage options of the source dataset
@@ -6930,7 +6934,8 @@ def create(
69306934
An integer specifies a version number in the current branch; a string
69316935
specifies a tag name; a Tuple[Optional[str], Optional[int]] specifies
69326936
a version number in a specified branch. (None, None) means the latest
6933-
version_number on the main branch.
6937+
version_number on the default branch. ``("main", version)`` is an
6938+
explicit alias for the default branch in this reference context.
69346939
"""
69356940
self._ds.create_tag(tag, reference)
69366941

@@ -6962,7 +6967,8 @@ def update(
69626967
An integer specifies a version number in the current branch; a string
69636968
specifies a tag name; a Tuple[Optional[str], Optional[int]] specifies
69646969
a version number in a specified branch. (None, None) means the latest
6965-
version_number on the main branch.
6970+
version_number on the default branch. ``("main", version)`` is an
6971+
explicit alias for the default branch in this reference context.
69666972
"""
69676973
self._ds.update_tag(tag, reference)
69686974

rust/lance/src/dataset.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,10 @@ impl Dataset {
430430
DatasetBuilder::from_uri(uri).load().await
431431
}
432432

433-
/// Check out a dataset version with a ref
433+
/// Check out a dataset version with a ref.
434+
///
435+
/// In reference contexts, `"main"` is an alias for the default branch and
436+
/// is equivalent to `None`.
434437
pub async fn checkout_version(&self, version: impl Into<refs::Ref>) -> Result<Self> {
435438
let reference: refs::Ref = version.into();
436439
match reference {
@@ -473,7 +476,9 @@ impl Dataset {
473476
Ok(())
474477
}
475478

476-
/// Check out the latest version of the branch
479+
/// Check out the latest version of the branch.
480+
///
481+
/// Use `"main"` to check out the latest version of the default branch.
477482
pub async fn checkout_branch(&self, branch: &str) -> Result<Self> {
478483
self.checkout_by_ref(None, Some(branch)).await
479484
}
@@ -493,6 +498,8 @@ impl Dataset {
493498
/// which can be cleaned up later. Such a zombie dataset may cause a branch creation
494499
/// failure if we use the same name to `create_branch`. In that case, you need to call
495500
/// `force_delete_branch` to interactively clean up the zombie dataset.
501+
///
502+
/// `"main"` is reserved for the default branch and cannot be used as a new branch name.
496503
pub async fn create_branch(
497504
&mut self,
498505
branch: &str,

0 commit comments

Comments
 (0)