Unix hard link对svn 的trunk,branch,tag模式的解释

2024-06-13 15:38

本文主要是介绍Unix hard link对svn 的trunk,branch,tag模式的解释,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

svn  创建分支

建立分支非常的简单—使用svn copy命令(原文link: http://www.subversion.org.cn/svnbook/nightly/svn.branchmerge.using.html

$ svn copy http://svn.example.com/repos/calc/trunk \http://svn.example.com/repos/calc/branches/my-calc-branch \-m "Creating a private branch of /calc/trunk."Committed revision 341.

This command causes a near-instantaneous commit in the repository, creating a new directory in revision 341. The new directory is a copy of  /calc/trunk . This is shown in  图 4.3 “版本库与复制” [19]  While it's also possible to create a branch by using  svn copy  to duplicate a directory within the working copy, this technique isn't recommended. It can be quite slow, in fact! Copying a directory on the client side is a linear-time operation, in that it actually has to duplicate every file and subdirectory on local disk. Copying a directory on the server, however, is a constant-time operation, and it's the way most people create branches.

图 4.3. 版本库与复制


2. svn 廉价复制


Subversion's repository has a special design. When you copy a directory, you don't need to worry about the repository growing huge—Subversion doesn't actually duplicate any data. Instead, it creates a new directory entry that points to an existing tree. If you're an experienced Unix user, you'll recognize this as the same concept behind a hard-link. As further changes are made to files and directories beneath the copied directory, Subversion continues to employ this hard-link concept where it can. It duplicates data only when it is necessary to disambiguate different versions of objects.This is why you'll often hear Subversion users talk about “cheap copies.” It doesn't matter how large the directory is—it takes a very tiny, constant amount of time and space to make a copy of it. In fact, this feature is the basis of how commits work in Subversion: each revision is a “cheap copy” of the previous revision, with a few items lazily changed within. (To read more about this, visit Subversion's web site and read about the “bubble up” method in Subversion's design documents.)当然,拷贝与分享的内部机制对用户来讲是不可见的,用户只是看到拷贝树,这里的要点是拷贝的时间与空间代价很小。如果你完全在版本库里创建分支(通过运行svn copy URL1 URL2),这是一个快速的,时间基本固定的操作,只要你希望,可以随意创建分支。

Part 2:  The difference between hard and soft links

原文链接:http://linuxgazette.net/105/pitcher.html


I participate in about 30 usenet newsgroups, and in a virtual LUG, and a number of questions keep coming up. I've answered a few of these questions often enough to have 'canned' an answer, which I modify, depending on the circumstances.

Here's one, now...

Q: Can someone give me a simple explanation of the difference between a soft link and a hard link? The documentation I've read mention these links but make no strong explanations of their meaning and how/when to use them. Thanks!

A: OK, I'll give it a try...

Unix files consist of two parts: the data part and the filename part.

The data part is associated with something called an 'inode'. The inode carries the map of where the data is, the file permissions, etc. for the data.


                             .---------------> ! data ! ! data ! etc/                  +------+ !------+! permbits, etc ! data addresses !+------------inode---------------+

The filename part carries a name and an associated inode number.
                         .--------------> ! permbits, etc ! addresses !/                 +---------inode-------------+! filename ! inode # !+--------------------+

More than one filename can reference the same inode number; these files are said to be 'hard linked' together.

        ! filename ! inode # !+--------------------+\>--------------> ! permbits, etc ! addresses !/                 +---------inode-------------+! othername ! inode # !+---------------------+

On the other hand, there's a special file type whose data part carries a path to another file. Since it is a special file, the OS recognizes the data as a path, and redirects opens, reads, and writes so that, instead of accessing the data within the special file, they access the data in the file named by the data in the special file. This special file is called a 'soft link' or a 'symbolic link' (aka a 'symlink').


      ! filename ! inode # !+--------------------+\.-------> ! permbits, etc ! addresses !+---------inode-------------+///.----------------------------------------------'( '-->  !"/path/to/some/other/file"! +---------data-------------+/                      }.~ ~ ~ ~ ~ ~ ~                       }-- (redirected at open() time)(                                     }'~~> ! filename ! inode # !+--------------------+\'------------> ! permbits, etc ! addresses !+---------inode-------------+//.----------------------------------------------------'('->  ! data !  ! data ! etc.+------+  +------+ 

Now, the filename part of the file is stored in a special file of its own along with the filename parts of other files; this special file is called a directory. The directory, as a file, is just an array of filename parts of other files.

When a directory is built, it is initially populated with the filename parts of two special files: the '.' and '..' files. The filename part for the '.' file is populated with the inode# of the directory file in which the entry has been made; '.' is a hardlink to the file that implements the current directory.

The filename part for the '..' file is populated with the inode# of the directory file that contains the filename part of the current directory file. '..' is a hardlink to the file that implements the immediate parent of the current directory.

The 'ln' command knows how to build hardlinks and softlinks; the 'mkdir' command knows how to build directories (the OS takes care of the above hardlinks).

There are restrictions on what can be hardlinked (both links must reside on the same filesystem, the source file must exist, etc.) that are not applicable to softlinks (source and target can be on seperate file systems, source does not have to exist, etc.). OTOH, softlinks have other restrictions not shared by hardlinks (additional I/O necessary to complete file access, additional storage taken up by softlink file's data, etc.)

In other words, there's tradeoffs with each.

Now, let's demonstrate some of this...

ln in action

Let's start off with an empty directory, and create a file in it

~/directory $ ls -lia 
total 373477 drwxr-xr-x   2 lpitcher users        1024 Mar 11 20:16 .91804 drwxr-xr-x  29 lpitcher users        2048 Mar 11 20:16 ..~/directory $ echo "This is a file" >basic.file~/directory $ ls -lia 
total 473477 drwxr-xr-x   2 lpitcher users        1024 Mar 11 20:17 .91804 drwxr-xr-x  29 lpitcher users        2048 Mar 11 20:16 ..73478 -rw-r--r--   1 lpitcher users          15 Mar 11 20:17 basic.file~/directory $ cat basic.file
This is a file
Now, let's make a hardlink to the file
   
~/directory $ ln basic.file hardlink.file~/directory $ ls -lia 
total 573477 drwxr-xr-x   2 lpitcher users        1024 Mar 11 20:20 .91804 drwxr-xr-x  29 lpitcher users        2048 Mar 11 20:18 ..73478 -rw-r--r--   2 lpitcher users          15 Mar 11 20:17 basic.file73478 -rw-r--r--   2 lpitcher users          15 Mar 11 20:17 hardlink.file~/directory $ cat hardlink.file
This is a file

We see that:

  1. hardlink.file shares the same inode (73478) as basic.file
  2. hardlink.file shares the same data as basic.file

If we change the permissions on basic.file:

~/directory $ chmod a+w basic.file~/directory $ ls -lia 
total 573477 drwxr-xr-x   2 lpitcher users        1024 Mar 11 20:20 .91804 drwxr-xr-x  29 lpitcher users        2048 Mar 11 20:18 ..73478 -rw-rw-rw-   2 lpitcher users          15 Mar 11 20:17 basic.file73478 -rw-rw-rw-   2 lpitcher users          15 Mar 11 20:17 hardlink.file

then the same permissions change on hardlink.file.

The two files (basic.file and hardlink.file) share the same inode and data, but have different file names.

Let's now make a softlink to the original file:

~/directory $ ln -s basic.file softlink.file~/directory $ ls -lia 
total 573477 drwxr-xr-x   2 lpitcher users        1024 Mar 11 20:24 .91804 drwxr-xr-x  29 lpitcher users        2048 Mar 11 20:18 ..73478 -rw-rw-rw-   2 lpitcher users          15 Mar 11 20:17 basic.file73478 -rw-rw-rw-   2 lpitcher users          15 Mar 11 20:17 hardlink.file73479 lrwxrwxrwx   1 lpitcher users          10 Mar 11 20:24 softlink.file -> basic.file~/directory $ cat softlink.file
This is a file

Here, we see that although softlink.file accesses the same data as basic.file and hardlink.file, it does not share the same inode (73479 vs 73478), nor does it exhibit the same file permissions. It does show a new permission bit: the 'l' (softlink) bit.

If we delete basic.file:

~/directory $ rm basic.file~/directory $ ls -lia 
total 473477 drwxr-xr-x   2 lpitcher users        1024 Mar 11 20:27 .91804 drwxr-xr-x  29 lpitcher users        2048 Mar 11 20:18 ..73478 -rw-rw-rw-   1 lpitcher users          15 Mar 11 20:17 hardlink.file73479 lrwxrwxrwx   1 lpitcher users          10 Mar 11 20:24 softlink.file -> basic.file

then we lose the ability to access the linked data through the softlink:

~/directory $ cat softlink.file
cat: softlink.file: No such file or directory

However, we still have access to the original data through the hardlink:

~/directory $ cat hardlink.file
This is a file

You will notice that when we deleted the original file, the hardlink didn't vanish. Similarly, if we had deleted the softlink, the original file wouldn't have vanished.

A further note with respect to hardlink files

When deleting files, the data part isn't disposed of until all the filename parts have been deleted. There's a count in the inode that indicates how many filenames point to this file, and that count is decremented by 1 each time one of those filenames is deleted. When the count makes it to zero, the inode and its associated data are deleted.

By the way, the count also reflects how many times the file has been opened without being closed (in other words, how many references to the file are still active). This has some ramifications which aren't obvious at first: you can delete a file so that no "filename" part points to the inode, without releasing the space for the data part of the file, because the file is still open.

Have you ever found yourself in this position: you notice that /var/log/messages (or some other syslog-owned file) has grown too big, and you

     rm /var/log/messagestouch /var/log/messages

to reclaim the space, but the used space doesn't reappear? This is because, although you've deleted the filename part, there's a process that's got the data part open still (syslogd), and the OS won't release the space for the data until the process closes it. In order to complete your space reclamation, you have to

     kill -SIGHUP `cat /var/run/syslogd.pid`

to get syslogd to close and reopen the file.

You can use this to your advantage in programs: have you ever wondered how you could hide a temporary file? Well, you could do the following:

     {FILE *fp;fp = fopen("some.hidden.file","w");unlink("some.hidden.file"); /* deletes the filename part *//* some.hidden.file no longer has a filename and is truely hidden */fprintf(fp,"This data won't be found\n"); /* access the data part *//*etc*/fclose(fp); /* finally release the data part */}

 


这篇关于Unix hard link对svn 的trunk,branch,tag模式的解释的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1057716

相关文章

TP-Link PDDNS服将于务6月30日正式停运:用户需转向第三方DDNS服务

《TP-LinkPDDNS服将于务6月30日正式停运:用户需转向第三方DDNS服务》近期,路由器制造巨头普联(TP-Link)在用户群体中引发了一系列重要变动,上个月,公司发出了一则通知,明确要求所... 路由器厂商普联(TP-Link)上个月发布公告要求所有用户必须完成实名认证后才能继续使用普联提供的 D

Java实现状态模式的示例代码

《Java实现状态模式的示例代码》状态模式是一种行为型设计模式,允许对象根据其内部状态改变行为,本文主要介绍了Java实现状态模式的示例代码,文中通过示例代码介绍的非常详细,需要的朋友们下面随着小编来... 目录一、简介1、定义2、状态模式的结构二、Java实现案例1、电灯开关状态案例2、番茄工作法状态案例

Mybatis提示Tag name expected的问题及解决

《Mybatis提示Tagnameexpected的问题及解决》MyBatis是一个开源的Java持久层框架,用于将Java对象与数据库表进行映射,它提供了一种简单、灵活的方式来访问数据库,同时也... 目录概念说明MyBATis特点发现问题解决问题第一种方式第二种方式问题总结概念说明MyBatis(原名

TP-LINK/水星和hasivo交换机怎么选? 三款网管交换机系统功能对比

《TP-LINK/水星和hasivo交换机怎么选?三款网管交换机系统功能对比》今天选了三款都是”8+1″的2.5G网管交换机,分别是TP-LINK水星和hasivo交换机,该怎么选呢?这些交换机功... TP-LINK、水星和hasivo这三台交换机都是”8+1″的2.5G网管交换机,我手里的China编程has

wolfSSL参数设置或配置项解释

1. wolfCrypt Only 解释:wolfCrypt是一个开源的、轻量级的、可移植的加密库,支持多种加密算法和协议。选择“wolfCrypt Only”意味着系统或应用将仅使用wolfCrypt库进行加密操作,而不依赖其他加密库。 2. DTLS Support 解释:DTLS(Datagram Transport Layer Security)是一种基于UDP的安全协议,提供类似于

在JS中的设计模式的单例模式、策略模式、代理模式、原型模式浅讲

1. 单例模式(Singleton Pattern) 确保一个类只有一个实例,并提供一个全局访问点。 示例代码: class Singleton {constructor() {if (Singleton.instance) {return Singleton.instance;}Singleton.instance = this;this.data = [];}addData(value)

macOS升级后SVN升级

问题 svn: error: The subversion command line tools are no longer provided by Xcode. 解决 sudo chown -R $(whoami) /usr/local/Cellar brew install svn

idea下svn的使用

创建项目 设置ignore文件 创建分支 切换到分支 查看当前分支 创建项目 设置ignore文件 .idea.mvntarget.gitignore*.imlmvnw.cmdmvnw 创建分支 切换到分支 查看当前分支

模版方法模式template method

学习笔记,原文链接 https://refactoringguru.cn/design-patterns/template-method 超类中定义了一个算法的框架, 允许子类在不修改结构的情况下重写算法的特定步骤。 上层接口有默认实现的方法和子类需要自己实现的方法

【iOS】MVC模式

MVC模式 MVC模式MVC模式demo MVC模式 MVC模式全称为model(模型)view(视图)controller(控制器),他分为三个不同的层分别负责不同的职责。 View:该层用于存放视图,该层中我们可以对页面及控件进行布局。Model:模型一般都拥有很好的可复用性,在该层中,我们可以统一管理一些数据。Controlller:该层充当一个CPU的功能,即该应用程序