I am trying to move(via the rename tool) a group of source files but still keep them tracked. Mercurial's rename tool has the --include option for handling multiple names. When I a try to move the files, I get the current directory added to the final name. When I remove the preceding "./" only the file name is referenced.
I am using the -I option to include a pattern of files. For reference:
https://www.selenic.com/mercurial/hg.1.html#rename
I am using Mercurial on windows through Cygwin64.
This is the directory that I am in:
$ pwd
/cygdrive/c/Users/me/thisProject/apple
This is what I want.
$ hg rename -f -v -I '*.c' ./ banana
moving one.c to .banana\one.c
moving two.c to .banana\two.c
moving three.c to .banana\three.c
This is what I don't want.
$ hg rename -f -v -I '*.c' ./ ./banana
moving one.c to banana\apple\one.c
moving two.c to banana\apple\two.c
moving three.c to banana\apple\three.c
Why does adding a "./" to the destination add the current directory name as an extra folder in the output?
Related
For example, let's say you have a directory dir/ with an arbitrary number of subdirectories including dir/subdir/, and you want to mount dir/ to a podman container with every subdirectory also mounted except dir/subdir/.
Is this possible in podman? If so, is it possible to do this purely with the arguments of a podman run command?
Is not possible, the entire folder will be available inside the container.
You can overcome this with permissions, acl or even symbolic links. In the last case, create a second folder with links pointing to only the folders you want to be available inside the container.
Use an extra bind-mount to hide the directory dir/subdir/
In other words, first bind-mount dir/ and then bind-mount an empty directory over dir/subdir to hide its contents.
$ mkdir dir
$ mkdir dir/subdir
$ mkdir dir/subdir2
$ mkdir emptydir
$ touch dir/subdir/file1.txt
$ touch dir/subdir2/file2.txt
$ podman pull -q docker.io/library/fedora
b2aa39c304c27b96c1fef0c06bee651ac9241d49c4fe34381cab8453f9a89c7d
$ podman run --rm \
-v ./dir:/dir:Z \
-v ./emptydir:/dir/subdir:Z \
docker.io/library/fedora find /dir
/dir
/dir/subdir
/dir/subdir2
/dir/subdir2/file2.txt
In the output from the command find /dir there is no file dir/subdir/file1.txt
I have a large project with unittest binaries running on the other machines. So, the gcda files were generated on the other machines. Then, I download them to the local machine but the different dirs. Each of the dirs has the sources code.
For example: dir gcda1/src/{*.gcda, *.gcno, *.h, *.cpp}..., dir gcda2/src/{*.gcda, *.gcno, *.h, *.cpp}....
Because the project is very large, so I have to run multiple lcov processes at the same time to generate info files to save time. And then merge these info files.
The problem is, when I merge these info files, it will take dir infos, for example:
gcda1/src/unittest1.cpp
gcda2/src/unittest1.cpp
I want this:
src/unittest1.cpp
#src/unittest1.cpp # this is expected to merge with above
The commands I use:
$ cd gcda1
$ lcov --rc lcov_branch_coverage=1 -c -d ./ -b ./ --no-external -o gcda1.info
$ cd ../gcda2
$ lcov --rc lcov_branch_coverage=1 -c -d ./ -b ./ --no-external -o gcda2.info
$ cd ..
$ lcov -a gcda1/gcda1.info -a gcda1/gcda2.info -o gcda.info
$ genhtml gcda.info -o output
The root dir contains the source code.
Description
Well, I have found a method to solve this problem finally.
The info files lcov generated are plain text file. So we can edit them directly.
Once you open these files, you will see every file line start with SF. Like below:
SF:/path/to/your/source/code.h
SF:/path/to/your/source/code.cpp
...
Problem
In my problem, these will be:
// file gcda1.info
SF:/path/to/root_dir/gcda1/src/unittest1.cpp
// file gcda2.info
SF:/path/to/root_dir/gcda2/src/unittest1.cpp
And, after lcov merge, it will be:
// file gcda.info
SF:/path/to/root_dir/gcda1/src/unittest1.cpp
SF:/path/to/root_dir/gcda2/src/unittest1.cpp
But, I expect this:
// file gcda.info
SF:/path/to/root_dir/src/unittest1.cpp
Method
My method to solve the problem is editing the info files directly.
First, edit gcda1.info and gcda2.info, change /path/to/root_dir/gcda1/src/unittest1.cpp to /path/to/root_dir/src/unittest1.cpp, and /path/to/root_dir/gcda2/src/unittest1.cpp to /path/to/root_dir/src/unittest1.cpp.
Then merge them like below and generate html report:
$ lcov -a gcda1.info -a gcda2.info -o gcda.info
$ genhtml gcda.info -o output
In a large project, we could not manually edit each info file, otherwise you will collapse.
We can use sed to help us. Like below:
$ sed "s/\(^SF.*\/\)gcda[0-9]+\/\(.*\)/\1\2/g" gcda_tmp.info > gcda.info
I would like to export files from a repository, ignoring changes in the working tree. Furthermore, rather than exporting everything, I would like to see a subset of it. The destination directory might already contain some files and those must be overwritten.
Given:
project/some/sub/dir/
I would like to export it to:
output/dir/
In git, I can use:
git archive --prefix=dir/ HEAD -- some/sub/dir/ | tar -xv -C output
What is the equivalent command in hg? If I use hg archive -t files -I some/sub/dir output/, then I get output/some/sub/dir. I could pipe the result through tar, but then I have to manually calculate the prefix that should be dropped:
hg archive -t tar -I some/sub/dir/ - |
tar -xv -C output --strip-components=3
(in reality, I have some other tar patterns that should be ignored such as --exclude='.*'). Any ideas? This export will be done for three other directories located in the repository.
Current situation:
srcdir=some/sub/dir
dstdir=output/dir
# hg archive auto-adds a 'proj-version' prefix. Given the srcdir,
# proj-version/some/sub/dir/X should become dstdir/X, so strip 4 components
prefixlength=$(grep -c / <<<"/${srcdir%%/}/")
hg archive -t tar -I "$srcdir" - |
tar -xv -C "$dstdir" --strip-components=$prefixlength
You can
hg archive ... && cd output/some/sub/dir && tar ... isn't it?
Build intermediate repo (Convert Extension), where some/sub/dir/ will be root of this repository (understand also sample from Converting from Mercurial topic) and get tar'red archive directly from hg archive for intermediate repository
I have to get list of changed, added or removed files since last commit.
command: hg status gives me for example
M file_path
C other_file_path
I need:
file_path
other_file_path
Solution have to work in Unix & Windows.
If you want to list all of the files, you can simply add -n to the hg status command:
$ hg status
M modded.txt
A added.txt
R removed.txt
? unknown.txt
$ hg status -n
modded.txt
added.txt
removed.txt
unknown.txt
However, this will also list unknown files (those that are new, but have not been specifically added to the repository with a hg add command). You can get around this by adding either -q (as Lazy Badger points out), or by using filesets (see hg help filesets) to specify all files that aren't unknown:
$ hg status -n -q
modded.txt
added.txt
removed.txt
$ hg status -n "set:!unknown()"
modded.txt
added.txt
removed.txt
You can specify which types of files are listed by combining the other options (-a -r for example will show added and removed files). Alternatively you can do clever things with filesets: for example, only listing the names of files that are removed by using "set:removed()"
I'm trying to setup a shortcut, a command which will let me check the history of one file.
I'm interested in when the file was originally commited, in what changesets it was changed and whether the current version in the working directory differs from the "last commited one".
So, in general
hg log --verbose filename.txt
hg status filename.txt
Is there a way to make this into a sort of a shortcut, so I can just type for example
hg file filename.txt
and get the "history" of the file?
Yes, you can add a shell alias:
[alias]
file = !$HG log --verbose "$1" && $HG status "$1"
The $HG environment variable refers to the path of the hg script used to invoke the shell alias, just in case hg is not in your path. The $1 refers to the first command line argument, the file name in your case.